clearAll() function with dynamic data

hi,
i m using dhtmlx bar chart with dynamic json data. My problem is i can not clear data before drawing the chart. if i draw 2 charts consecutively they overlap and view is ruined. I used clearAll() function as below but didnt work:

barChart.clearAll();
barChart.parse(resultArray,“json”);

this doesnt work. any help pls?
(barChart is chart object and resultArray is dynamic json array)

Hi,

could you attach the sample that reproduces the problem

what you mean by sample? it is dhtmlxchart.js or my javascript code.

Here is an example, how to made sample (completed demo):
docs.dhtmlx.com/doku.php?id=othe … leted_demo

hi Darya,
can you give me a simple example of repainting chart after clicking a button. I can not clean old chart before painting new one. I have button and i draw chart by clicking this button but it draws new chart on old one and they overlap. There are method like clearAll() and refresh(), can i use them to solve this problem? if so can you tell me where shall i call these methods in my code. (before parsing, after parsing etc.) I m using json data and my code is below:

			function onJsonDataRetrieved(response) {
				var jsonObject=JSON.parse(response);
				var resultArray=jsonObject.resultArray;
				var length=jsonObject.length;
				 var barChart=new dhtmlXChart({
			    		view:"stackedBar",
			    		container:"chart_container",
			    	    value:"#sales#",
			    		label:"#sales#",
			    		width:100,
			    		xAxis:{
			    			title:"Sales",
			    			template:"#year#"
			    		},
			    		yAxis:{
			    			title:"sales per year"
			    		},
			    		gradient:"3d",
			    		color: "#00FF22"
			     
			    	});
				for(var k=0;k<length;k++){
					barChart.addSeries({
			    	    value:"#sales"+k+"#",
			    		color:get_random_color(),
			    		label:"#sales"+k+"#",
			    	});
					}

		    	barChart.parse(resultArray,"json");
			}

Here is a working sample for you:
chart.rar (78.2 KB)

Here is online sample with the same chert type as you have:
dhtmlx.com/docs/products/dht … chart.html
Just call barChart1.clearAll() - and it will clear your chart data.