I am trying to update a C3 graph with different onclick funtion by using the load function of C3.
The code snippet is here:
var json1 = [{
date: '2014-01-01',
upload: 200,
download: 200,
total: 400
}, {
date: '2014-01-02',
upload: 100,
download: 300,
total: 400
}, {
date: '2014-02-01',
upload: 300,
download: 200,
total: 500
}, {
date: '2014-02-02',
upload: 400,
download: 100,
total: 500
}];
var json2 = [{
date: '2014-01-01',
upload: 200,
download: 500,
total: 700
}, {
date: '2014-01-02',
upload: 500,
download: 450,
total: 950
}, {
date: '2014-02-01',
upload: 200,
download: 800,
total: 1000
}, {
date: '2014-02-02',
upload: 300,
download: 500,
total: 800
}];
var chart = c3.generate({
bindto: '#div1',
data: {
json: json1,
onclick: function (event) {
console.log("11111111111") ;
},
keys: {
x: 'date',
value: ['upload', 'download']
}
},
axis: {
x: {
type: 'timeseries',
tick: {
format: function (x) {
if (x.getDate() === 1) {
return x.toLocaleDateString();
}
}
}
}
}
});
setTimeout(function () {
chart.unload();
}, 1000);
setTimeout(function () {
chart.load({
json: json2,
keys: {
x: 'date',
value: ['upload', 'download']
},
onclick: function (event) {
console.log("22222222") ;
},
});
}, 1000);
<link href="https://rawgit.com/masayuki0812/c3/master/c3.css" rel="stylesheet"/>
<script src="https://rawgit.com/masayuki0812/c3/master/c3.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.10/d3.min.js"></script>
<div id="div1"></div>
Please tell me a way so to update the onClick funtion on the load function itself.