Jump to content
JChartFX Community
  • 0

Creating a cumulative option


PhilHannent

Question

Hi,

Thanks for all the help in the past.  I don't write thanks posts as they add no real value.

I am looking to create a toggle for changing the chart to be cumulative.  In your documentation you talk about setting the values:

http://www.jchartfx.com/api/DataValues/X

However there is no demonstration or documentation on how I can loop over each series and each point by knowing the length of each.  Could you provide information on how I can iterate over the data?

Many thanks

Phil

Link to comment
Share on other sites

9 answers to this question

Recommended Posts

  • 0

I am not sure what you mean "by changing the chart to be cumulative", can you explain this in detail?

If you want to stack bars on top of each other, you might want to try using the getAllSeries().setStackedStyle(cfx.Stacked.Normal)

If you actually want to loop through the data, you can use Chart.getData(), this will return a data object that exposes a getItem(series,point) method where you can retrieve the values being plotted by the chart.

Regards,

JuanC

Link to comment
Share on other sites

  • 0

 Further to my earlier post, this is the function I am trying to create:

function chartCumulativeToggle() {
    if (!aDataCumulativeSet) {
        aDataCumulativeSet = true;
        //TODO: Figure out how to get the count of series
        for(var i=0; i < chart1.getData().getSeries();i++){
            var AddPoints = 0;
            //TODO: Figure out how to get the count of points in this series
            for(var j = 0; j < chart1.getSeries(i).getPoints();j++) {
                //TODO: Figure out how to get the current value
                AddPoints =+ chart1.getItem(i, j);
                chart1.getData().getX().setItem(i, j, AddPoints);
            }
        }
    } else {
        aDataCumulativeSet = false;
        chart1.setDataSource(aData);
    }
    chart1.recalculateScale();
}

RealTimeCharts.zip

Link to comment
Share on other sites

  • 0

chart1.getData().getSeries() returns the number of series

chart1.getData().getPoints() returns the number of points

chart1.getData().getItem(series,point) returns the value for the specified series/point combination

chart1.getData().setItem(series, point, value) sets the value for the specified series/point combination.

You would only use getData().getX() if you were interested in getting/setting the X axis values in an XY chart.

Note that alternatively you could create a new jscript array with the accumulated values and invoke setDataSource again.

JuanC

Link to comment
Share on other sites

  • 0

Good afternoon,

Thanks for the reply, looks like I was very close with my code.  Your second sentence about getting the points is a little too general for me.  I need the number of points within a specific series for my loops to work.  Getting the total number of points wouldn't work.  How can I get the number of points for the given series?

Many thanks

Phil

Link to comment
Share on other sites

  • 0

In jChartFX all series have the same number of points, visually you can achieve series that look shorter than others by using Hidden values but internally we keep track of the number of points globally (and not per-series)

getData().getPoints returns the number of points on each of the series, i.e. in a chart with 2 series (PreviousYear vs LastYear) and 12 points (monthly), getData().getPoints() will return 12 (not 24)

JuanC

Link to comment
Share on other sites

  • 0

Thank you JuanC.

In case it helps others this is my correct function:

function chartCumulativeToggle() {
    if (!aDataCumulativeSet) {
        aDataCumulativeSet = true;
        for(var i=0; i < chart1.getData().getSeries();i++){
            var AddPoints = 0;
            for(var j = 0; j < chart1.getData().getPoints();j++) {
                AddPoints += chart1.getData().getItem(i, j);
                chart1.getData().setItem(i, j, AddPoints);
            }
        }
    } else {
        aDataCumulativeSet = false;
        chart1.setDataSource(aData);
    }
}

WindowsApplication1.zip

Link to comment
Share on other sites

  • 0

getData().getX() will only return the numerical data for XY charts (i.e. charts like scatter where each point has a numerical X value).

To get the strings used for the X axis labels in a bar chart you will want to use

getAxisX().getLabels().getItem(i) where i is the 0 based index of the point you want the label for.

JuanC 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...