Forum > Beginners



Hi! I'm playing around with "TChart" by tutorial

To draw a chart I use a button. When I click it 1 time it draws a chart as expected. But when I click it another one it draws another line from start point to the end.

I don't understand why this is happening and how to fix it.

In the button's OnClick handler you probably execute the code which is in FormCreate of the tutorial. In OnCreate it is guaranteed that the series is empty initially. But in the ButtonClick the same data values are added to the series again and again. Since the series is a true x/y plot it connects the last point of the previous run (at the right side of the chart) with the first point of the next run (at the left side of the chart).

You can fix this easily when you clear the series at the beginning:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---//procedure TForm1.FormCreate(Sender: TObject);procedure TForm1.Button1Click(Sender: TObject);const  N = 100;  MIN = -10;  MAX = 10;var  i: Integer;  x: Double;begin  SinSeries.Clear,  CosSeries.Clear;  for i:=0 to N-1 do begin    x := MIN + (MAX - MIN) * i /(N - 1);    SinSeries.AddXY(x, sin(x));    CosSeries.AddXY(x, cos(x));    SinCosSeries.AddXY(x, sin(x)*cos(x));  end;end;


[0] Message Index

Go to full version