I need to update the chart based on dropdown change. i dont know how to do in javascript or jquery.
i have created fiddle to explain my situation
this is the html
<select id="chartType">
<option>bar chart</option>
<option>area chart</option>
<option>line chart</option>
<option>spline chart</option>
</select>
<div id="chart"></div>
JS
var chart = c3.generate({
data: {
rows: [
['data4', 'data2', 'data3'],
[90, 120, 300],
[40, 160, 240],
[50, 200, 290],
[120, 160, 230],
[80, 130, 300],
[90, 220, 320]
],
type: 'bar'
}
});
this is my customisation , trying
var currentChart = 0;
var charts = [{
type: 'line',
data: 'data4'
}, {
type: 'area',
data: 'data2'
}, {
type: 'spline',
data: 'data3'
}];
$(function () {
$("#chartType").change(function (evt) {
var chartSelection = $("#chartType").val();
$('#chart').hide().filter(charts + chartSelection).show();
});
});
in detail explanation
i am working on c3.js charts
in c3, it has 4 kinds of charts
- bar chart
- area chart
- spline chart
- line chart
whenever user changes the dropdown or select the other charts i need to update the chart.
C3 library link
http://c3js.org/samples/chart_combination.html
Any help is appreciated