Continuous Plotting of Live data on WCartesianChart
I am currently trying to display incoming live data on a WCartesianChart widget. I get two values to plot, date/time on X-axis and the sensor data on Y-axis.
I have created a WStandardItemModel with 32 rows and 2 columns and added it to chart as below,
std::shared_ptr<WStandardItemModel> model = std::make_shared<WStandardItemModel>(32, 2); std::unique_ptr<NumericItem> prototype = std::make_unique<NumericItem>(); model->setItemPrototype(std::move(prototype)); model->setHeaderData(0, WString("X")); model->setHeaderData(1, WString("Y")); auto chart = this->addWidget(std::make_unique<WCartesianChart>()); chart->setModel(model);
Finally, I have created a WDataSeries and added it to chart as below,
std::unique_ptr<WDataSeries> s = std::make_unique<WDataSeries>(1, SeriesType::Line); chart->addSeries(std::move(s));
With above code, I am able to plot only 32 sensor values, but beyond that, the chart stops loading any value. Because this is live data, what code changes should I do to keep loading new values so that the chart keeps plotting the incoming live data?
Any inputs or code examples to solve the plotting of live data are highly appreciated!
Updated by Korneel Dumon 3 months ago
I image your live data is being generated on the server. To show it live in the browser you need to use the server-push mechanism. You can find some documentation here:
Other options are to use a periodic
WTimer to refresh your table, or a refresh-button in the UI.