How to clear chart and redraw new chart in same container

I am planning to have a tab that display chart and grid, the data in the grid change depending on the setting.

var nCount = oFormProps.Grid.getUserData("", "Count");
document.getElementById('chart_container').style.height = nCount * 20 + "px";

if (oFormProps.Chart != undefined || oFormProps.Chart != null) {
                oFormProps.Chart.clearAll();
                oFormProps.Chart.refresh();
}
oFormProps.Chart = new dhtmlXChart({
                view: "barH",
                color: "#66ccff",
                container: "chart_container",
                value: "#data2#",
                label: "#data1#",
                width: 20,
                xAxis: {
                    start: oGrid.getUserData("", "MinValue"),
                    step: oGrid.getUserData("", "Step"),
                    end: oGrid.getUserData("", "MaxValue")
                }

});

sort of work, however I still see left-over from previous charts, like x and yAxis markings, also the resizing of the container does not work, likely due to the fact that the old chart is not completely gone.

Hello
Could you provide us the whole html file with code?
Or send us direct link or completed demo on support@dhtmlx.com with link to this topic
docs.dhtmlx.com/doku.php?id=othe … leted_demo

Hello, i have a workarround,try this:

$$(“chart_id”).hide();
$$(“chart_id”).show();
$$(“chart_id”).refresh();
$$(“chart_id”).parse(this);

I am not sure what you mean by that, is that php? I’m using javascript, razor and .NET MVC. What would the equivalent be in javascript? The chart object does not seem to have a hide() nor a show() method.

above sample is related to dhtmlx touch library, which shares the same chart functionality but has a bit different API

Anyway, call to chart.clearAll() must remove all data from the previous chart. But it will not remove scales ( as they are defined globally, and will be reused, when you will load new data ). If you need to remove chart fully - you can use chart.destructor(); call

As for resizing, if chart’s container was resized after chart’s rendering , you can call chart.refresh() to repaint the chart.