Below is an example snippet that utilizes static data:
Highcharts.chart("container", {
title: {
text: "Highcharts pie chart"
},
xAxis: {
categories: [
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"
]
},
series: [
{
type: "pie",
allowPointSelect: true,
keys: ["name", "y", "selected", "sliced"],
data: [
["January", 105],
["February", 400],
["March",230]
],
showInLegend: true
}
]
});
@import "https://code.highcharts.com/5/css/highcharts.css";
.highcharts-series .highcharts-point-select {
fill: #fff;
stroke: #f00;
stroke-dasharray: 10;
}
<script src="https://code.highcharts.com/5/js/highcharts.js"></script>
<div id="container"></div>
Now, I am attempting to parse data from a JSON query with the following format:
{"headers":["Month","Clicks"],"rows":[["January",105],["February",400],["March",230]]}
The current JSON format in the working snippet looks like this:
["January", 105],
["February", 400],
["March",230]
I have encountered difficulties when trying to parse the data correctly. In the updated snippet below, I have added a JavaScript function at the start to parse the JSON data.
var unformatted = {"headers":["Month","impressions"],"rows":[["January",124010],["February",545010]]};
var data2 = [];
for (var i = 0; i < unformatted.rows.length; i++) {
var row = unformatted.rows[i];
data2.push({
Month: row[0],
Clicks: row[1]
});
}
Highcharts.chart("container", {
title: {
text: "Clicks per Month"
},
xAxis: {
categories: [
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"
]
},
series: [
{
type: "pie",
allowPointSelect: true,
keys: ["name", "y", "selected", "sliced"],
data: data2,
showInLegend: true
}
]
});
@import "https://code.highcharts.com/5/css/highcharts.css";
.highcharts-series .highcharts-point-select {
fill: #fff;
stroke: #f00;
stroke-dasharray: 10;
}
<script src="https://code.highcharts.com/5/js/highcharts.js"></script>
<div id="container"></div>