Recent

Author Topic: Tchart LineSeries with changes in line color?  (Read 969 times)

stephanweber

  • Jr. Member
  • **
  • Posts: 54
Tchart LineSeries with changes in line color?
« on: July 11, 2024, 10:24:32 am »
Hi,

I need to do a family plot, like sinewaves of different frequencies vs time, e.g. starting at t=0 going to 10s.
I can put all the different frequencies in one LineSeries by using addXY(0,nan) if I reach the last point. This way the now frequency starts correct at t=0 without having a line from 10s back to 0s.
However, still the whole plot is hard to understand, and having different colors e.g. red for freq=1kHz, then orange for 2kHz, green for next, etc.

So I programmed a change in SeriesColor after each frequency, but the chart shows only the last used color.
He this problem can be solved?

My current code:

loop on n:

For k:=0 to kmax
           Do Chart2LineSeries.Addxy(xTranData[k],yTranData[k]);
         Chart2LineSeries.Addxy(0,nan);
         If n mod 2 = 0 then Chart2LineSeries.SeriesColor:=clBlack
         else Chart2LineSeries.SeriesColor:=clRed

Bye Stephan


stephanweber

  • Jr. Member
  • **
  • Posts: 54
Re: Tchart LineSeries with changes in line color?
« Reply #1 on: July 11, 2024, 11:48:57 am »
I found ColorEach property but it does not help.
I also tried using SerieColor vs LinePen.Color, no change.
I use v2.2.2 under Windows.

Bye Stephan

wp

  • Hero Member
  • *****
  • Posts: 12287
Re: Tchart LineSeries with changes in line color?
« Reply #2 on: July 11, 2024, 12:14:24 pm »
Sorry, I don't understand what you are doing.

Why don't you add several series? One for 1kHz, one for 2kHz etc? Or, if all datapoints have the same x value you can even use a single series to which you can assign several y values (you must add chartstyles in this case in order to define curve colors and legend texts).

See attached project which demonstrates both approaches.

stephanweber

  • Jr. Member
  • **
  • Posts: 54
Re: Tchart LineSeries with changes in line color?
« Reply #3 on: July 12, 2024, 08:45:09 am »
Thanks for reply, I have a large random number of frequencies!
Now I found this solution:

 For k:=0 to nmax
           Do Case n mod 6 of
              0: Chart2LineSeries.Addxy(xTranData[k],yTranData[k],'' ,clBlack);
              1: Chart2LineSeries.Addxy(xTranData[k],yTranData[k],'' ,clMaroon);
              2: Chart2LineSeries.Addxy(xTranData[k],yTranData[k],'' ,clRed);
              3: Chart2LineSeries.Addxy(xTranData[k],yTranData[k],'' ,clLime);
              4: Chart2LineSeries.Addxy(xTranData[k],yTranData[k],'' ,clGreen);
              5: Chart2LineSeries.Addxy(xTranData[k],yTranData[k],'' ,clBlue);
              else Chart2LineSeries.Addxy(xTranData[k],yTranData[k],'',clPurple);
          end;                                                           

The only strange thing here is that the string output is not working (but here I don't need it).

Bye Stephan

wp

  • Hero Member
  • *****
  • Posts: 12287
Re: Tchart LineSeries with changes in line color?
« Reply #4 on: July 12, 2024, 12:01:46 pm »
For k:=0 to nmax
           Do Case n mod 6 of
              0: Chart2LineSeries.Addxy(xTranData[k],yTranData[k],'' ,clBlack);
              1: Chart2LineSeries.Addxy(xTranData[k],yTranData[k],'' ,clMaroon);
              2: Chart2LineSeries.Addxy(xTranData[k],yTranData[k],'' ,clRed);
              3: Chart2LineSeries.Addxy(xTranData[k],yTranData[k],'' ,clLime);
              4: Chart2LineSeries.Addxy(xTranData[k],yTranData[k],'' ,clGreen);
              5: Chart2LineSeries.Addxy(xTranData[k],yTranData[k],'' ,clBlue);
              else Chart2LineSeries.Addxy(xTranData[k],yTranData[k],'',clPurple);
          end;                                                           

The only strange thing here is that the string output is not working (but here I don't need it).
You do not specify a label text when you add the data values to the series:
Code: Pascal  [Select][+][-]
  1.   Chart2LineSeries.AddXY(x, y, labeltext, color);

 

TinyPortal © 2005-2018