0

I would like to use json in chartJS. In first example I used

["0","76","32","88"]

and everything looks great.

Problem is in second example when I want to use JSON data as:

var json =[{"wartosc":"0"},{"wartosc":"76"},{"wartosc":"32"},{"wartosc":"88"}];

In variable chartjsData i want to have data as ["0","76","32","88"] but it doesn't work.

var json =[{"wartosc":"0"},{"wartosc":"76"},{"wartosc":"32"},{"wartosc":"88"}];
var chartjsData = [];
for (var i = 0; i < json.lenght; i++) {
    chartjsData.push (json[i].wartosc);
}
var areaChartData = {
  labels: ["j","j","j","j"],
  datasets: [
    {
      label: "Electronics",
      fillColor: "rgba(210, 214, 222, 1)",
      strokeColor: "rgba(210, 214, 222, 1)",
      pointColor: "rgba(210, 214, 222, 1)",
      pointStrokeColor: "#c1c7d1",
      pointHighlightFill: "#fff",
      pointHighlightStroke: "rgba(220,220,220,1)",
      data: ["0","76","32","88"]
    },
    {
      label: "Digital Goods",
      fillColor: "rgba(60,141,188,0.9)",
      strokeColor: "rgba(60,141,188,0.8)",
      pointColor: "#3b8bba",
      pointStrokeColor: "rgba(60,141,188,1)",
      pointHighlightFill: "#fff",
      pointHighlightStroke: "rgba(60,141,188,1)",
      data: chartjsData
    }
  ]
};

1 Answer 1

1

You misspelled .length

for (var i = 0; i < json.length; i++) {
    chartjsData.push (json[i].wartosc);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.