I'm sorry that you find entering data like that annoying, but
unfortunately, the DataTable structure is predicated upon the idea of one
cell, one value - it is, in essence, a mini database.
If you have a data array in the format:
var inputData = [
[x, [/* list of y1 */], [/* list of y2 */]],
//....
];
then you can parse that into a DataTable like this:
var data = new google.visualization.DataTable();
data.addColumn('number', 'x');
data.addColumn('number', 'y1');
data.addColumn('number', 'y1');
for (var i = 0; i < inputData.length; i++) {
var length1 = inputData[i][1].length;
var length2 = inputData[i][2].length;
var maxLength = Math.max(length1, length2);
for (var j = 0; j < maxLength; j++) {
var row = [inputData[i][0]];
row.push((j < length1) ? inputData[i][1][j] : null);
row.push((j < length2) ? inputData[i][2][j] : null);
data.addRow(row);
}
}
See an example here: http://jsfiddle.net/asgallant/Jumry/
On Friday, August 16, 2013 11:15:47 AM UTC-4, mg wrote:
>
> Hi everyone!
>
> I was working with Google's Scatter chart and came upon what I think is
> kind of a limitation when building the chart.
>
> Suppose I've got two *Y series* defined as* Y1 : 'Male' *and* Y2: 'Female'
> *, and my* (x,y) pairs* are *(weight, height).*
>
> A typical scatter chart row would be:
>
> [72, 1.84, 1.75] where I've got male and female heights for a certain
> weight.
>
> But what if I have more heights for that same weight? If I were adding
> those rows to the chart I'd have to:
>
> data.addRow([72, 1.84, 1.75]);
> data.addRow([72, 1.70, 1.69]);
> data.addRow([72, null, 1.64]);
>
> Because of the way I process my input data, I find it quite annoying
> having to create new rows with the *same x value* to fill multiple Y
> values for the same series.
>
> Wouldn't it be much easier to be able to do something like:
>
> data.addRow([72, [1.84, 1.70], [1.75, 1.69, 1.64] ]) ?
>
> That syntax won't work right now, but is there some other way to do what
> I've tried? If not, could it be implemented?
>
> Cheers,
> M
>
>
>
>
>
--
You received this message because you are subscribed to the Google Groups
"Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/groups/opt_out.