I would like to thank you for creating this great open source library.
I want to create dynamic charts using external JSON file in which the chart parsing json data each at a time.
My Current Code:
var chart = c3.generate({
bindto: '#chart',
size: {
height: 240,
width: 480
},
data: {
url: 'static/data/trainp.json',
mimeType: 'json',
keys: {
x: 'Series',
value: ['Setting1']
},
type: 'line'
},
subchart: {
show: true
}
});
Example of the required chart : https://jsfiddle.net/cy2owjva/
Please let me know what change i have to make in https://jsfiddle.net/cy2owjva/ .
Thank You
@AskSaikatSinha Try this
`
$(function () {
$.getJSON('./linejson.json', function (externaldata) {
var chart = c3.generate({
title: {
text:'External JSON loading via C3.js'
},
bindto: '#chart',
data: {
json: externaldata,
type: 'area-spline',
}
})
setInterval(function(){
chart.flow({
columns:
[
['data1',Math.round(Math.random()*200)]
],
type:'area-spline'
})
}, 1500)
});
})
`
and have your external JSON file like so
linejson.json file
{
"data1": [30, 20, 50, 40, 60, 50]
}
I'm at the same issue. Trying to animate a chart with a stream of real time data.
tried this:
var xhr = new XMLHttpRequest();
function reload(){
//each call on this url changes the json
xhr.open('GET', "http://127.0.0.1:5000/json/", true).send();
chart.flow('http://127.0.0.1:5000/json/');
chart.flush()
}
setInterval(reload, 500);
Tried flow, generate, load and none of those reload the chart without needing to reload the browser.
Any tips?
@HawiCaesar Thank you, your code works.
Most helpful comment
@AskSaikatSinha Try this
`
$(function () {
});
})
`
and have your external JSON file like so
linejson.json file
{ "data1": [30, 20, 50, 40, 60, 50] }