using wt, c library web development, trying upload .wav file , print values in chart. there way dynamically, in other words add points chart created?
yes, there way that, once wrote code monitor memory usage , print info in chart, performance tab of windows task manager. used boost thread continuously update it. here code might put in right direction chart problem.
you need wcartesianchart
wt::chart::wcartesianchart* _chart_memory_display;
now, initialization charts pretty tricky. wrote function it. note: uses #define performance_history 100 amount of data chart stores, far know there no limit, wanted last 100 points.
wt::chart::wcartesianchart* createcartesianchart(wcontainerwidget* parent) { wstandarditemmodel *model = new wstandarditemmodel(performance_history, 2, parent); //create scatter plot. wt::chart::wcartesianchart* chart = new wt::chart::wcartesianchart(parent); //give chart empty model fill data chart->setmodel(model); //set column holds x data chart->setxseriescolumn(0); //get axes wt::chart::waxis& x_axis = chart->axis(wt::chart::axis::xaxis); wt::chart::waxis& y1_axis = chart->axis(wt::chart::axis::y1axis); wt::chart::waxis& y2_axis = chart->axis(wt::chart::axis::y2axis); //modify axes attributes x_axis.setrange(0, performance_history); x_axis.setgridlinesenabled(true); x_axis.setlabelinterval(performance_history / 10); y1_axis.setrange(0, 100); y1_axis.setgridlinesenabled(true); y1_axis.setlabelinterval(10); y2_axis.setrange(0, 100); y2_axis.setvisible(true); y2_axis.setlabelinterval(10); //set chart type chart->settype(wt::chart::charttype::scatterplot); // typically, mathematical functions, want axes cross @ 0 mark: chart->axis(wt::chart::axis::xaxis).setlocation(wt::chart::axisvalue::zerovalue); chart->axis(wt::chart::axis::y1axis).setlocation(wt::chart::axisvalue::zerovalue); chart->axis(wt::chart::axis::y2axis).setlocation(wt::chart::axisvalue::zerovalue); // add lines wt::chart::wdataseries s(1, wt::chart::seriestype::lineseries); chart->addseries(s); //size display size of chart, has no effect on scale chart->resize(300, 300); return chart; }
basically, wt charts need model, , data series ready receive data. highly recommend reading documentation on in function not recognize, took me sometime put pieces together. also, check out wt widget gallery, has chart , code samples.
now, actual updating, wrote function.
void updatechartdisplay(wt::wabstractitemmodel* data_model, double data) { //update old data for(unsigned int = 0; < performance_history; i++) { //move data 1 index data_model->setdata(i, 0, i); data_model->setdata(i, 1, data_model->data(i+1, 1)); } //get last index of data int insertion_point = performance_history - 1; //insert new data @ last index data_model->setdata(insertion_point, 0, insertion_point); data_model->setdata(insertion_point, 1, data); }
now, data_model model of chart being updated,
_chart_memory_display->model()
the double coming in, data being added chart. have boost thread calling function every second passing in new data, looks task manager when running. not sure if trying update dynamically or fill data, hope helps , puts on right track!
Comments
Post a Comment