Reputation: 21
Do not know what I'm doing wrong, I am trying to get json data from and run the code. If I enter the data directly, everything works fine.
Parsing json (Not working):
function showprice(pricedata){
var obj = jQuery.parseJSON(pricedata);
console.log(obj.created);
console.log(obj.price);
label = obj.created;
values = obj.price;
var data = {
labels : [obj.created], //obj.created = "2013-12-30 14:20:29","2013-12-30 15:14:48","2013-12-30 14:32:29","2013-12-30 14:26:29"
values : [obj.price], //obj.price = 28.41,28.41,72.42,60.42
datasets : [
{
fillColor : "rgba(151,187,205,0.5)",
strokeColor : "rgba(151,187,205,1)",
pointColor : "rgba(151,187,205,1)",
pointStrokeColor : "#fff",
data : [obj.price],...
Data entered directly into the code (Works):
function showprice(pricedata){
var obj = jQuery.parseJSON(pricedata);
console.log(obj.created);
console.log(obj.price);
label = obj.created;
values = obj.price;
var data = {
labels : ["2013-12-30 14:20:29","2013-12-30 15:14:48","2013-12-30 14:32:29","2013-12-30 14:26:29"], //obj.created = "2013-12-30 14:20:29","2013-12-30 15:14:48","2013-12-30 14:32:29","2013-12-30 14:26:29"
values : [28.41,28.41,72.42,60.42], //obj.price = 28.41,28.41,72.42,60.42
datasets : [
{
fillColor : "rgba(151,187,205,0.5)",
strokeColor : "rgba(151,187,205,1)",
pointColor : "rgba(151,187,205,1)",
pointStrokeColor : "#fff",
data : [28.41,28.41,72.42,60.42],
mouseover: function(data) {...
Upvotes: 0
Views: 171
Reputation: 227280
Your obj.created
and obj.price
values are actually strings that just so happen to contain commas.
You can convert them to arrays using .split()
.
var label = obj.created.split(',');
var values = obj.price.split(',');
Upvotes: 2