Setting multiple Scatter chart data sets in one go?


« Back to message list

Enter your email address to get email updates on this topic. You can stop receiving updates by clicking the link in the update email messages.

Posted by Paul on 14th April 2014
Hi Richard,

first of all thanks again for creating and supporting such a fantastic and useful product. I have a question about the scatter graph that I still can't figure out and hope you can help.

Basically I have an array (called testData here) which itself contains multiple arrays (data sets) which I want to send to a scatter graph to plot. However, my first attempt didn't work and I wondered if I am misunderstanding something, doing something subtly wrong or if the RGraph scatter graph behaviour is just by design. I did get my code to work perfectly in the following way:

// create a new scatter graph
testGraph = new RGraph.Scatter('graphMissileCanvas', [])

// Copy over multiple data sets to the graph.
// Need to do these individually as setting
// testGraph.data = testData
// doesn't work for some reason.
for (i = 0; i < testData.length; i++) {
     testGraph.data[i] = testData[i];
};

However, I don't understand why the following simpler code doesn't seem to work instead and wondered if you were able to clarify for me whether or not it should?

// create a new scatter graph
testGraph = new RGraph.Scatter('graphMissileCanvas', [])

// Copy over multiple data sets to the graph.
// testGraph.data = testData;

Thanks again and best wishes,
Paul

Posted by Richard on 14th April 2014
Hi there,

Scatter chart datasets involve lots of arrays - so the format probably needs tweaking.

point1 = [15,23];
point2 = [13,23];

dataset = [point1, point2];

scatter.data[0] = dataset; // First dataset

So it's a 3D array, that you could also show like this:

scatter.data[0] = [[15,23], [13,23]]; // First dataset

HTH






Richard
www.rgraph.net
If RGraph has helped you - please share the website - thanks!

Add a reply

 




« Back to message list
RGraph on social media