Unsolved How do I create charts by data receieved by a server? Im very new to qt
-
@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