wxFreeChart - dynamic data and dateTime

Talk here about issues with one of the components hosted at wxCode, or suggest features for it.
spacevoyager
In need of some credit
In need of some credit
Posts: 1
Joined: Mon Feb 11, 2013 5:06 pm

wxFreeChart - dynamic data and dateTime

Postby spacevoyager » Mon Feb 11, 2013 5:22 pm

Hello at all!

Im new in wxwidgets and wxFreeChart and trying to make a chart which displays me the voltage and current from a externel charge controller.

I have dynamic data so i was using XYDynamicDataset and XYDynamicSerie. Plots are working with XY Dataset :-) But now i want to change bottom scale to display date and time... but i don't know how :(.
In the sample dir, is an example with dateTime but not with dynamic data.... how can i combine this things ??

Any help would be very nice!


Falko

PS:
My current code:

In init function:

Code: Select all


// --- Plot Init ---
    // colors for first and second datasets
    wxColour color_current = wxColour(255, 0, 0);
    wxColour color_voltage = wxColour(0, 0, 255);

    // first step: create plot
    plot = new XYPlot();

    // create dynamic dataset
    voltage_battery_dataset = new XYDynamicDataset();
    voltage_battery_serie = new XYDynamicSerie();
    voltage_battery_dataset->AddSerie(voltage_battery_serie);

    current_battery_dataset = new XYDynamicDataset();
    current_battery_serie = new XYDynamicSerie();
    current_battery_dataset->AddSerie(current_battery_serie);


    // set line renderer to it
    XYLineRenderer *renderer_voltage = new XYLineRenderer();
    renderer_voltage->SetSerieColour(0,&color_voltage);
    voltage_battery_dataset->SetRenderer(renderer_voltage);
    plot->AddDataset(voltage_battery_dataset);

    // cu
    XYLineRenderer *renderer_current = new XYLineRenderer();
    renderer_current->SetSerieColour(0,&color_current);
    current_battery_dataset->SetRenderer(renderer_current);
    plot->AddDataset(current_battery_dataset);



    // create left and bottom number axes
    NumberAxis *leftAxisVoltage = new NumberAxis(AXIS_LEFT);
    leftAxisVoltage->SetLabelTextColour(color_voltage);
    leftAxisVoltage->SetLabelPen(*wxThePenList->FindOrCreatePen(color_voltage, 1, wxSOLID));
    plot->AddAxis(leftAxisVoltage);

    NumberAxis *leftAxisCurrent = new NumberAxis(AXIS_LEFT);
    leftAxisCurrent->SetLabelTextColour(color_current);
    leftAxisCurrent->SetLabelPen(*wxThePenList->FindOrCreatePen(color_current, 1, wxSOLID));
    plot->AddAxis(leftAxisCurrent);

    NumberAxis *bottomAxis = new NumberAxis(AXIS_BOTTOM);
    plot->AddAxis(bottomAxis);


    // link axes and dataset
    plot->LinkDataVerticalAxis(0, 0);
    plot->LinkDataVerticalAxis(1, 1);
   plot->LinkDataHorizontalAxis(0, 0);
    plot->LinkDataHorizontalAxis(1, 0);

    // and finally create chart
    Chart *chart = new Chart(plot, GetName());

    // set axis as scrolled, so chart panel can scroll its window.
    //chart->SetScrolledAxis(bottomAxis);


    wxChartPanel * m_chartPanel = new wxChartPanel(Notebook1);
    m_chartPanel->SetChart(chart) ;
    Notebook1->AddPage(m_chartPanel,"Plot");





and the new data function:

Code: Select all


        GC_Device::lokal_time_t record_time;
        record_time  =  selected_gc->getDBValue(db_record).s.record_time;
        double plot_time;
        plot_time = record_time.hour + (record_time.minute*60.0 + record_time.second)/3600.0; // to display time in float format, not very nice:(
        double voltage_battery =     selected_gc->getDBValue(db_record).s.u_bat;
        double current_battery =     selected_gc->getDBValue(db_record).s.i_bat;
        voltage_battery_serie->AddXY(plot_time, voltage_battery);
        current_battery_serie->AddXY(plot_time, current_battery);



MAB
Earned a small fee
Earned a small fee
Posts: 23
Joined: Mon Aug 25, 2008 3:27 pm

Re: wxFreeChart - dynamic data and dateTime

Postby MAB » Thu Mar 07, 2013 12:25 pm

Please, download wxFreeChart source from svn. Look at TimeSeries demo.

TimeSeriesDataset is XY dataset, where one axis contains data/time values. It's intended for static data.

You can use make your own dataset from TimeSeriesDataseet and XYDynamicDataset.

Best regards.


Return to “wxCode”

Who is online

Users browsing this forum: No registered users and 3 guests