Forum > TAChart
Tchart LineSeries with changes in line color?
(1/1)
stephanweber:
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:
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:
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:
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:
--- Quote from: stephanweber on July 12, 2024, 08:45:09 am --- 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).
--- End quote ---
You do not specify a label text when you add the data values to the series:
--- 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";}};} --- Chart2LineSeries.AddXY(x, y, labeltext, color);
Navigation
[0] Message Index