Simple steps to create Delphi chart
This Delphi graphic tutorial demonstrates how to create a simple charts using TChart component.
Bookmark:
Simple steps to create Delphi chart
Use following simple steps to start your first chart using Delphi TChart component:
- Put chart component on the form
- Double click on chart, then you will see chart editing dialog box.
- Click add button in series tab sheet.
- Select the chart style from the list (Line, Bar, Pie ..)
Put following code to add data into the chart
procedure TForm1.Button1Click(Sender: TObject); begin { function AddXY(Const AXValue, AYValue: Double; Const AXLabel: String; AColor: TColor) : Longint; This function inserts a new point in the Series. The new point has X and Y values. The AXLabel parameter is optional (can be empty ''). The AColor parameter is optional (can be clTeeColor). The function returns the new point position in the Values list. } Chart1.Series[0].AddXY(10, 20, '', clTeeColor); Chart1.Series[0].AddXY(15, 50, '', clTeeColor); Chart1.Series[0].AddXY(20, 30, '', clTeeColor); Chart1.Series[0].AddXY(25, 70, '', clTeeColor); Chart1.Series[0].AddXY(30, 10, '', clTeeColor); Chart1.Series[0].AddXY(35, 50, '', clTeeColor); Chart1.Series[0].AddXY(40, 45, '', clTeeColor); Chart1.Series[0].AddXY(45, 10, '', clTeeColor); { Or you can write following code using "With" statement. Its much easier than repeating everything again and again. With Chart1.Series[0] Do Begin AddXY(10, 20, '', clTeeColor); AddXY(15, 50, '', clTeeColor); AddXY(20, 30, '', clTeeColor); AddXY(25, 70, '', clTeeColor); AddXY(30, 10, '', clTeeColor); AddXY(35, 50, '', clTeeColor); AddXY(40, 45, '', clTeeColor); AddXY(45, 10, '', clTeeColor); End; } end;
Download This Delphi Tutorials.
Download materials for this article (Delphi - Tutorials)
delphi-chart.zip
File size: 5 KB, File type: zip
Total downloads: 7831, Upload date: February 11 - 2009
Luis :: February 20-2009 :: 01:31 AM
Hello, Would you please give me some hints on how to allow a user to choose a chart style, I mean I need a code for example i can select combobox and type 3 options to plot a chart.
Thanks
Sibusiso :: March 10-2009 :: 01:34 PM
How to make the chart to be visible in intraweb
Widakdov :: November 09-2009 :: 08:49 AM
Dear digital coding ,
How to create a simulated chart using delphi
meng :: April 12-2010 :: 04:29 AM
very good very good very good very good!!!
Narcís Calvet :: April 12-2010 :: 03:06 PM
This code can be simpler:
Chart1[0].AddXY(15, 50);
Chart1[0].AddXY(20, 30);
Chart1[0].AddXY(25, 70);
Chart1[0].AddXY(30, 10);
Chart1[0].AddXY(35, 50);
Chart1[0].AddXY(40, 45);
Chart1[0].AddXY(45, 10);
You can even replace Chart1[0] (first series in the SeriesList collection in the chart) for Series1, for example:
Series1.AddXY(15, 50);
Series1.AddXY(20, 30);
Series1.AddXY(25, 70);
Series1.AddXY(30, 10);
Series1.AddXY(35, 50);
Series1.AddXY(40, 45);
Series1.AddXY(45, 10);
carol paola galvis :: April 26-2010 :: 03:33 PM
si gracias por el tutorial
Piet :: December 02-2010 :: 10:59 PM
Is it also possible to create a chart, adding a label as a marker to specific data points but not showing the label on the horizontal axes?
For instance:X: 0 to 100
Y: random
Show X-values on BottomAxis, Y-Values on VertAxis and three labels (markers) on X=23, X=57, X=71
stephen :: January 08-2011 :: 11:51 PM
Hi,
I have a problem where AddXY doesn't plot the points during an iteration but as soon the iterations arte finished it blurts out everything. Stepping into the program all the recording of the data at each iteration is fine i.e. X and Y.
so it seems like a refresh.,. repaint, update issue? i've tried using for loops to slow things down and use the chart1.refresh etc commands but no joy. I need real time monitering of X and Y. Have you any ideas how i could do this?
it would be appreciated,
Thanks
c.g :: February 18-2011 :: 09:30 PM
I am using delphi 3 and cannot get your code to work at all, any suggestions. Thanks
Okan :: May 18-2011 :: 11:16 PM
Thank You!