I need to populate a table of data with dynamic, minimal pie charts, sort of like a sparkline chart using HighCharts.
I'm very close to solving this but passing the array of data via the data-sparkline <td>
argument is eluding me.
<td data-sparkline="[{name: 'KARE', y: 17.33, sliced: true, selected: true}, {name: 'KSTP', y: 14.03}, {name: 'WCCO', y: 10.38}, {name: 'KMSP', y: 3.2}] ; pie"/>
Here's what I have so far.
If I hard code the chart data in the function on line 74 of the fiddle, the charts initialize and works, but I need the function to read the array in the table.
for (i = 0; i < len; i += 1) {
$td = $($tds[i]);
stringdata = $td.data('sparkline');
arr = stringdata.split('; ');
data = arr[0];
chart = {};
console.log(data);
if (arr[1]) {
chart.type = arr[1];
}
$td.highcharts('SparkLine', {
series: [{
data: [{name: 'KARE', y: 17.33, sliced: true, selected: true}, {name: 'KSTP', y: 14.03}, {name: 'WCCO', y: 10.38}, {name: 'KMSP', y: 3.2}],
pointStart: 1
}],
http://jsfiddle.net/8v63kxwp/3/
But if I cycle through the <td>
's and read the string in the data-sparkline argument, it logs the proper string in the console, but doesn't draw the pie chart.
for (i = 0; i < len; i += 1) {
$td = $($tds[i]);
stringdata = $td.data('sparkline');
arr = stringdata.split('; ');
data = arr[0];
chart = {};
console.log(data);
if (arr[1]) {
chart.type = arr[1];
}
$td.highcharts('SparkLine', {
series: [{
data: data,
pointStart: 1
}],