wxFreeChart - dynamic data and dateTime

Talk here about issues with one of the components hosted at wxCode, or suggest features for it.
Post Reply
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

Post by 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!


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();

    current_battery_dataset = new XYDynamicDataset();
    current_battery_serie = new XYDynamicSerie();

    // set line renderer to it
    XYLineRenderer *renderer_voltage = new XYLineRenderer();

    // cu
    XYLineRenderer *renderer_current = new XYLineRenderer();

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

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

    NumberAxis *bottomAxis = new NumberAxis(AXIS_BOTTOM);

    // 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.

    wxChartPanel * m_chartPanel = new wxChartPanel(Notebook1);
    m_chartPanel->SetChart(chart) ;

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);

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

Re: wxFreeChart - dynamic data and dateTime

Post by 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.

Post Reply