Add and remove chart dynamically

Hi

I would like to add a bar chart on click of a button and line chart in the same container on click of a different button.
how do i do it?
e.g suppose I have two buttons AM, PM
onlick of AM i want the title of chart to be displayed as AM
and respectively on click of PM, title of chart to be displayed as “PM”.

Hi,

it is possible to show both bar and line charts together. However, adding series dynamically require rebuilding a chart.

if(chart){
    chart.destructor();
}
chart = new dhtmlXChart({..});
chart.addSeries({...});
chart.load(...);

xAxis can be reset with the help of define method

chart.define("xAxis",{
   template:"'#time#",
   title: "PM"
});
chart.refresh();

No at a time only either a bar chart or line chart will be displayed.
I am not sure of the chart.define(),can you point any documentation or sample using this method.

Thanks for the information regarding adding chart dynamically, tried that
function onload() {

barchart_am = new dhtmlXChart({…});
}
function switchTime() {
if(pm) {
barchart_am .destructor();
barchart_pm = new dhtmlxChart({…});
}
else if (am) {
barchart_pm .destructor();
barchart_am = new dhtmlXChart({…});
}

I just wanted to know if instead of creating the chart every time is there a way to just pass values dynamically and do it.

I am not sure of the chart.define(),can you point any documentation or sample using this method.

Please take a look:

docs.dhtmlx.com/api__dhtmlxchart_define.html

There are hideSeries/showSeries methods, but they work in charts with legend:
dhtmlx.com/docs/products/dhtmlxC … harts.html
We will change their behavior in the next version. It will be possible to create a chart with to series and hide / show one of the series. However, in this case the scale calculated for both series and if charts have different series, it is better to use different charts: