jQuery Sparklines: $.getJSON data can't be read
Posted
by
Bob Jansen
on Stack Overflow
See other posts from Stack Overflow
or by Bob Jansen
Published on 2013-10-27T21:39:44Z
Indexed on
2013/10/27
21:53 UTC
Read the original article
Hit count: 288
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?
© Stack Overflow or respective owner