I'm trying to generate a pie graph with Sparklines but I'm running into some trouble. I can't seem to figure out what I'm doing wrong, but I feel it is a silly mistake.
I'm using the following code to generate a sparkline chart in the div #traffic_bos_ss:
//Display Visitor Screen Size Stats
$.getJSON('models/ucp/traffic/traffic_display_bos.php',
{
type: 'ss',
server: server,
api: api,
ip: ip,
},
function(data)
{
var values = data.views;
//alert(values);
$('#traffic_bos_ss').sparkline(values,
{
type: "pie",
height: "100%",
tooltipFormat: 'data.screen - {{value}}',
});
});
The JSON string fetched:
{"screen":"1220x1080, 1620x1080, 1920x1080","views":"[2, 2, 61]"}
For some reason Sparklines does not process the variable values. When I alert the variable it outputs "[2, 2, 61]". Now the jQuery code does work when I replace the snippet:
var values = data.views;
with
var values = [2, 2, 61];
What am I doing wrong?