I am new to javascripting and jquery. I am drawing charts using flot in which i have 2 Bar graphs…
My first bar graph
<div id="bar1" style="width:600px;height:300px;"></div>
$(function () {
var css_id = "#bar1";
var data = [
{label: 'foo',color:'red', data: [[1,300], [2,300], [3,300], [4,300], [5,300]]},
{label: 'bar',color:'blue', data: [[1,800], [2,600], [3,400], [4,200], [5,0]]},
{label: 'baz',color:'green', data: [[1,100], [2,200], [3,300], [4,400], [5,500]]},
];
var options = {
series: {stack: 0,
lines: {show: false, steps: false },
bars: {show: true, barWidth: 0.4, align: 'center',},},
xaxis: {ticks: [[1,'One'], [2,'Two'], [3,'Three'], [4,'Four'], [5,'Five']]},
};
$.plot($(css_id), data, options);
});
My second graph
<div id="bar2" style="width:600px;height:300px;"></div>
var data = [
{label: 'foo', color:'red', data: [[1,300], [2,300], [3,300], [4,300], [5,300]]},
{label: 'bar', color:'blue', data: [[1,800], [2,600], [3,400], [4,200], [5,0]]},
{label: 'baz', color:'yellow', data: [[1,100], [2,200], [3,300], [4,400], [5,500]]},
];
$.plot($("#bar2"), data, {
series: {
stack: 1,
bars: {
show: true,
barWidth: 0.6,
fill:1
}
}
});
Now i have a click event of a button
$(document).ready(function() {
......
});
Now what should i write on the occurance of the button event such that i dynamically change my bar graphs from <div id="bar1"> to <div id="bar2">
If i understand the question correctly you want to hide/show each div on the press of a button …. first hide one of the
<div>usingstyle="display:none"and then use the following code to toggle both onclickof a buttonUsing
toggle()on both with hide the currently showndivand show the currently hiddendiv(hope that makes sense !)Docs for toggle()