Unsolved How do I create charts by data receieved by a server? Im very new to qt
-
This post is deleted! -
@DemonLord Did you take a look at https://doc.qt.io/qt-5/qtcharts-index.html ?
There are also examples: https://doc.qt.io/qt-5/qtcharts-examples.html -
@jsulm heyy I've seen the examples none of them show how data from tcp server can be plotted into a graph. Do you have any idea?
-
@DemonLord
There is simply no relevance to where the data comes from, "tcp server" is quite irrelevant. Get your data from wherever, plot it, two quite separate processes.Start by gathering all your data, from tcp or wherever, and make sure that bit is working. Then use the data you have to generate points for a plot. A data point like
(100, 100)
doesn't care whether it came from TCP or not. -
@JonB I'm making a monitoring system so basically the data is on going.....the tcp client sends the data and the tcp server receives the data and then I have to convert the data into a ongoing graph that never stops.....I mean my supervisor asked me to do that so I don't think is irrelevant? There must be a way? Other then customplot ofcourse.....I already managed to get the client to send the data to the tcp server non stop but I'm struggling with plotting the graph....I must plot the graph under a tab widget too its complicated
-
@DemonLord For plotting it does not matter from where the data comes from. So, what exactly is the issue?
Can you already get the data from the server? -
@jsulm ohh the issue is I want to see a graph on the TCP/IP console and not the string of numbers/data and I don't know how? Like I've tried using the examples but no graph show up....
-
@DemonLord said in How do I create charts by data receieved by a server? Im very new to qt:
Like I've tried using the examples but no graph show up....
Then please show what you did (code)...
-
@jsulm sorry here's the code as you can see the data is displayed n plain text but I don't want it in plain text but in a chart how can I do this?
#include "tcpconsole.h"
#include <QScrollBar>
TCPConsole::TCPConsole(QWidget *parent) :
QPlainTextEdit(parent)
{
document()->setMaximumBlockCount(100);
QPalette p = palette();
p.setColor(QPalette::Base, Qt::black);
p.setColor(QPalette::Text, Qt::green);
setPalette(p);}
void TCPConsole::putData(const QByteArray &data)
{
insertPlainText(data);// data is shown in plain textQScrollBar *bar = verticalScrollBar(); bar->setValue(bar->maximum());
}
void TCPConsole::setLocalEchoEnabled(bool set)
{
m_localEchoEnabled = set;
}void TCPConsole::keyPressEvent(QKeyEvent *e)
{
switch (e->key()) {
case Qt::Key_Backspace:
case Qt::Key_Left:
case Qt::Key_Right:
case Qt::Key_Up:
case Qt::Key_Down:
break;
default:
if (m_localEchoEnabled)
QPlainTextEdit::keyPressEvent(e);
emit getData(e->text().toLocal8Bit());
}
}void TCPConsole::mousePressEvent(QMouseEvent *e)
{
Q_UNUSED(e)
setFocus();
}void TCPConsole::mouseDoubleClickEvent(QMouseEvent *e)
{
Q_UNUSED(e)
}void TCPConsole::contextMenuEvent(QContextMenuEvent *e)
{
Q_UNUSED(e)
} -
@DemonLord Where in this code do you show any charts?
You wrote that you're trying to use examples, but then you post code without anything related to charts... -
This post is deleted! -
@jsulm im not sure its correct thou
void MainWindow::tcpreadData(const QByteArray &data)
{
const tcpsettingdialog::TcpSettings tcp = m_tcpsettingdialog->tcpSettings();m_tcpconsole->putData(data);
//create charts
QChartView *chartView;
//All charts initialize here.
hs_ch1_raw_chart = new QChart();
init_LineChart(hs_ch1_raw_chart, "High Speed Channel 1 - RAW");
chartView = new QChartView(hs_ch1_raw_chart);
m_charts << chartView;if(tcp.dataLoggerEnabled)
{
QString dataString = QString::fromStdString(data.toStdString());datalogger(dataString);
}
}void MainWindow::init_LineChart(QChart *chart, QString ChartName) const
{
chart->setTitle(ChartName);QString name("Series ");
int nameIndex = 0;
for (const DataList &list : m_dataTable) {
QLineSeries *series = new QLineSeries(chart);
for (const Data &data : list)
series->append(data.first);
series->setName(name + QString::number(nameIndex));
nameIndex++;
chart->addSeries(series);
}chart->createDefaultAxes();
chart->axes(Qt::Horizontal).first()->setRange(0, m_valueMax);
chart->axes(Qt::Vertical).first()->setRange(0, m_valueCount);// Add space to label to add space between labels and axis
QValueAxis axisY = qobject_cast<QValueAxis>(chart->axes(Qt::Vertical).first());
Q_ASSERT(axisY);
axisY->setLabelFormat("%.1f ");
} -
@DemonLord said in How do I create charts by data receieved by a server? Im very new to qt:
tcpreadData(const QByteArray &data)
Why do you create here a new QChart everytime it is called instead of using an existing one to append new data to it?!
-
Because I want to display multiple charts with multiple diff data
-
@DemonLord OK. And what is the problem?
-
I'm not seeing a chart
-
@DemonLord
it won't solve al your issue, far from it, but to "see" the chartschartView = new QChartView(hs_ch1_raw_chart); chartView->show();//<-Add this m_charts << chartView;
-
@J-Hilk ohh thanks but do you know what's the issue I can't seem to figure it out