I am facing a challenge in displaying two charts using a dropdown menu. I have attempted to achieve this using both JQuery and AngularJS, but I am encountering difficulties in making it work properly.
There are two charts that need to be displayed:
<div ng-controller="ExampleCtrl">
<nvd3-discrete-bar-chart
data="exampleData"
id="exampleId"
width="800"
height="400"
tooltips="true"
showXAxis="true"
showYAxis="true">
<svg></svg>
</nvd3-discrete-bar-chart>
<nvd3-discrete-bar-chart
data="exampleData2"
id="exampleId2"
width="800"
height="400"
tooltips="true"
showXAxis="true"
showYAxis="true">
<svg></svg>
</nvd3-discrete-bar-chart>
</div>
I intend to use a dropdown menu to toggle between the charts.
<select id="leave" onchange="leaveChange()">
<option value="1">Second</option>
<option value="2">First</option>
</select>
The function for selecting the chart is as follows:
function leaveChange() {
if (document.getElementById("leave").value != "1"){
document.getElementById("test").data="exampleData2";
}
else{
document.getElementById("test").data="exampleData";
}
}
If you prefer using Jquery instead, you can refer to this link for an example: http://jsfiddle.net/K3Lwj/3/