Recent

Author Topic: Multi Lineseries  (Read 10685 times)

mpknap

  • Full Member
  • ***
  • Posts: 155
Multi Lineseries
« on: March 06, 2019, 06:27:24 am »
How to create and display 100 LineSeries on Chart1 with Tchart component? (Later even 3000 line series I would need.)
  
Code: Pascal  [Select][+][-]
  1.  
  2. var
  3. Series_ar: array of TLineSeries;
  4. .....
  5.  for j :=1 to 100 do   begin
  6.      
  7.    Series_ar[i].AddXy( random(1000),i);
  8. ......
  9.  
  10.  
did not work.

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: Multi Lineseries
« Reply #1 on: March 06, 2019, 06:52:39 am »
Did you create the series and add it to the chart?
Code: Pascal  [Select][+][-]
  1. uses
  2.   LCLIntf;
  3.  
  4. procedure TForm1.FormCreate(Sender: TObject);
  5. const
  6.   NUM_SERIES = 10;
  7.   NUM_POINTS = 10;
  8. var
  9.   i,j: Integer;
  10.   ser: TLineSeries;
  11. begin
  12.   for j := 1 to NUM_SERIES do begin
  13.     ser := TLineSeries.Create(Chart1);
  14.     ser.SeriesColor:= rgb(Random(256), Random(256), Random(256));
  15.     for i := 1 to NUM_POINTS do
  16.       ser.AddXY(Random, Random);
  17.     Chart1.AddSeries(ser);
  18.   end;
  19. end;  

mpknap

  • Full Member
  • ***
  • Posts: 155
Re: Multi Lineseries
« Reply #2 on: March 06, 2019, 07:11:05 am »
Thanks. I would like, however, Array 1..X]. To call for a specific series .. Is it possible?

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: Multi Lineseries
« Reply #3 on: March 06, 2019, 07:25:06 am »
I would like, however, Array 1..X]. To call for a specific series ..
The chart has a built-in list of series. Begins with 0, though. (But I'd strongly advice against using an array starting at 1 anyway - it is guaranteed to make you trouble because all other arrays and lists used by the LCL begin with 0). To access the 7th series added (index 6) you simply call:
Code: Pascal  [Select][+][-]
  1. var
  2.   ser: TLineSeries;
  3. begin
  4.   ser := TLineSeries(Chart1.Series[6]);
  5.   ...
Of course you can use your own array in addition. Saves you the type-cast to TLineSeries:
Code: Pascal  [Select][+][-]
  1. var
  2.   Series_ar: array[1..NUM_SERIES] of TLineSeries;
  3. ...
  4.   for j := Low(Series_ar) to High(Series_ar) do begin
  5.     Series_ar[i] := TLineSeries.Create(Chart1);
  6.     Series_ar[i].SeriesColor:= rgb(Random(256), Random(256), Random(256));
  7.     for i := 1 to NUM_POINTS do
  8.       Series_ar[i].AddXY(Random, Random);
  9.     Chart1.AddSeries(Series_ar[i]);
  10.   end;
« Last Edit: March 06, 2019, 07:45:44 am by wp »

mpknap

  • Full Member
  • ***
  • Posts: 155
Re: Multi Lineseries
« Reply #4 on: March 06, 2019, 04:44:30 pm »
WP, Something is not quite right. An error pops up (attachment).
The code looks like this:
Code: Pascal  [Select][+][-]
  1. procedure TForm4.Button5Click(Sender: TObject);
  2. const
  3.   NUM_SERIES = 2000;
  4.   NUM_POINTS = 10;
  5. var
  6.   i, j: integer;
  7.   ser: TLineSeries;
  8.   Series_ar: array[1..2000] of TLineSeries;
  9.  
  10. begin
  11.  { for j := 1 to NUM_SERIES do begin
  12.     ser := TLineSeries.Create(Chart1);
  13.     ser.SeriesColor:= rgb(Random(256), Random(256), Random(256));
  14.     for i := 1 to NUM_POINTS do
  15.       ser.AddXY(Random, Random);
  16.     Chart1.AddSeries(ser);
  17.   end;
  18.  }
  19.   for j := Low(Series_ar) to 20 do
  20.   begin
  21.     Series_ar[j] := TLineSeries.Create(Chart2);
  22.     Series_ar[j].SeriesColor := rgb(Random(256), Random(256), Random(256));
  23.     for i := 1 to NUM_POINTS do
  24.       Series_ar[i].AddXY(Random, Random);
  25.     Chart2.AddSeries(Series_ar[i]);
  26.  
  27.   end;
  28. end;        

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: Multi Lineseries
« Reply #5 on: March 06, 2019, 04:52:52 pm »
Carefully look at your code. Understand what each index, i and j, is good for. Why does the series have an index j in the outer loop and an index i in the inner loop? Is this correct?

mpknap

  • Full Member
  • ***
  • Posts: 155
Re: Multi Lineseries
« Reply #6 on: March 06, 2019, 05:51:11 pm »
Of course!!! It should be everywhere "j". Thanks again, now I will test a few days :)
Code: Pascal  [Select][+][-]
  1. for j := Low(Series_ar) to 20 do
  2.   begin
  3.     Series_ar[j] := TLineSeries.Create(Chart2);
  4.     Series_ar[j].SeriesColor := rgb(Random(256), Random(256), Random(256));
  5.     for i := 1 to NUM_POINTS do
  6.       Series_ar[j].AddXY(Random, Random);
  7.     Chart2.AddSeries(Series_ar[j]);
  8.  
  9.   end;

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: Multi Lineseries
« Reply #7 on: March 06, 2019, 05:55:00 pm »
It should be everywhere "j".
Looked at my own code in reply #3, and found the "i" there as well. Excuse me for the typo.

mpknap

  • Full Member
  • ***
  • Posts: 155
Re: Multi Lineseries
« Reply #8 on: March 07, 2019, 08:13:10 pm »
One more problem and question (to WP).
Why I do not see String after adding in the

Code: Pascal  [Select][+][-]
  1. ...
  2. Series_ar[j].AddXY(Random, Random,' TIME ');
  3. ...


?


I changed to smsLabel, smsCustom ...

Maybe I misunderstood but I wanted the text "Time" to be in Bottom Chart Axis, under Grid ...

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: Multi Lineseries
« Reply #9 on: March 07, 2019, 11:33:09 pm »
When you add a text to the "AddXY" call this text will be used as a series data point label. To show the labels you set the series' Marks.Style to smsLabel. If you want to use the labels as axis labels you must assign the internal ListSource of the series (to which the AddXY data go) to the Marks.Source of the BottomAxis (and set Marks.Style to smsLabel again).

Your note "I wanted the text "Time" to be in Bottom Chart Axis, under Grid" can also be understood as if you want to use the 'TIME" as axis title. In this case, AddXY is not the correct place. Go to the chart's BottomAxis.Title and assign the string to the subproperty "Caption". Don't forget to show the title by setting its "Visible" to true.

mpknap

  • Full Member
  • ***
  • Posts: 155
Re: Multi Lineseries
« Reply #10 on: March 08, 2019, 05:54:32 am »
I change, I think, I'm looking on the net. Somewhere, I made a mistake and I do not know where.
It's hard to explain but maybe it will be easier on the pictures. The graph is 24H time. As in the attachment in the picture. I want the time to be properly scaled after taking the zoom.

Maybe I'll add that this one variable (bottom) is unixtime. So maybe we'll change it to date and time ??
« Last Edit: March 08, 2019, 07:35:42 am by mpknap »

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: Multi Lineseries
« Reply #11 on: March 08, 2019, 11:13:57 am »
Change the x values to be TDateTime and use a TDateTimeIntervalChartSource as Marks.Source of the BottomAxis (set Marks.Style to smsLabel). Increase the Params.MaxLength of the DateTimeIntervalChartSource to avoid overlapping labels. TDateTimeIntervalchartSource is able to create correct date/time labels at all zoom levels, although they are not always "nice", i.e. each new day is not always marked with a 0:00:00 label.

mpknap

  • Full Member
  • ***
  • Posts: 155
Re: Multi Lineseries
« Reply #12 on: March 11, 2019, 05:23:07 pm »
As always, many thanks.
One more question. I inserted TChartListbox. After starting (multiselect) all items are marked. How do you deselect all them, for example with a button?

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: Multi Lineseries
« Reply #13 on: March 11, 2019, 05:42:53 pm »
You mean: All items are checked and you want to un-check an item? Just click on the checkbox - this will remove the checkmark and hide the associated series. Or by code: set the (public) property Checked[Index] to false; Index is the index of the item in the listbox. Don't forget to set the Chart property of the Listbox to the chart to be processed.

mpknap

  • Full Member
  • ***
  • Posts: 155
Re: Multi Lineseries
« Reply #14 on: March 11, 2019, 05:51:33 pm »
I mean uncheck everyone at once, by buttonClick.


But already done
Code: Pascal  [Select][+][-]
  1. procedure TForm4.Button6Click(Sender: TObject);
  2. var x : integer;
  3. begin
  4.   for x:=0  to   chartlistbox1.SeriesCount-1 do
  5.       chartlistbox1.Checked[x]:=false;
  6. end;
« Last Edit: March 11, 2019, 06:05:03 pm by mpknap »

 

TinyPortal © 2005-2018