I've seen some examples on multiple lines in one graph and done some easy pie and bar charts from JSON files in Chart.js.
Currently easy bars and pie charts go like this:
$.getJSON("http://127.0.0.1/charts/test/amounts.json", function (result)
{
var labels = [], data = [];
for (var i = 0; i < result.length ; i++)
{
labels.push(result[i].source);
data.push(result[i].amount);
}
var ctx = document.getElementById("myChart").getContext("2d");
ctx.canvas.width = 800;
ctx.canvas.height = 500;
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: labels,
datasets: [
{
label: "Total products per Source",
fillColor: "rgba(220,220,220,0.2)",
strokeColor: "rgba(220,220,220,1)",
pointColor: "rgba(220,220,220,1)",
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(220,220,220,1)",
data: data
}
]}
});
});
But I cannot imagine how to start or format my JSON files for multiple lines. Do I need to have multiple JSON files, one for each line? If so, how would I load it into my canvas?
Or can I format my JSON file in a way, that I can use only one file for multiple lines? I've seen this example: https://codepen.io/k3no/pen/pbYGVa but I'm still not sure on how to get JSON and multiple lines together ..
My data (still in Python/Pandas for now) looks like this:
source time rating
Source1 2017-05-14 13919
2017-06-04 14154
Source2 2017-05-28 272
2017-06-11 307
2017-06-18 329
Source3 2017-06-04 3473
2017-06-11 3437
And I'd like to have time as an x axis, rating as the y axis and the sources are the different lines / data series.