Friday, 14 April 2017

javascript - Creating HighChart pie charts as sparkline-type elements

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 argument is eluding me.






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 '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
}],



http://jsfiddle.net/8v63kxwp/2/

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...