Forum > TAChart

TAChart how to make different width and/or color only for a specific grid line

<< < (2/2)

tk:

--- Quote from: wp on July 17, 2025, 03:58:21 pm ---Ah - there's a better solution:

--- End quote ---

Thanks I'll try this solution later when someone has problem with my own solution, which I made in the meantime.

My solution is now:
a) After each chart data update calculate Minimum and Maximum values from all 'working' line series.
b) Then show dummy zero line series (in my case the first series) only when zero fits between minimum and maximum:

--- 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";}};} ---  Chart.Series[0].Active := (Minimum <= 0) and (Maximum >= 0);
This is not clean solution, the dummy zero line is not visible in certain situations when it actually should be (this depends on vertical range rounding algorithms used in the automatic range calculation in each chart component), but for now it is a good tradeoff for me.
And this works both for TAChart and TeeChart.

tk:
Finally I've used this wp's solution:


--- Quote from: wp on July 17, 2025, 03:20:44 pm ---Another possibility would be to skip the idea with the ConstantLine series and to hook into one of the chart's drawing events. OnAfterDrawBackwall or OnAfterCustomDrawBackwall seem to be good candidates. Get the logical extent in a local variable and replace the y value by 0. Calculate the corresponding screen points and draw the connecting line.

--- End quote ---

Because it is simple (does not need any extra series or axes) and virtually the same way can be made in TeeChart.

I use a slightly modified solution.
For more details see my answer here:
https://stackoverflow.com/questions/79704456/steema-teechart-how-to-make-different-width-and-color-only-for-a-specific-horizo

EDIT:
Just to be safe, I'm posting my answer here because in the Stack Overflow ecosystem you never know who will edit your answer and how.


--- 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);begin//...  Chart1:=TChart.Create(Self);//...  Chart1.OnAfterCustomDrawBackWall := ChartAfterCustomDrawBackWall;end; procedure TForm1.ChartAfterCustomDrawBackWall(Sender: TChart; ADrawer: IChartDrawer; const ARect: TRect);var  x0Pos, x1Pos, y0Pos, y1Pos, yPos: Integer;begin  yPos := Sender.YGraphToImage(0);  y0Pos := Sender.YGraphToImage(Sender.CurrentExtent.b.Y);  y1Pos := Sender.YGraphToImage(Sender.CurrentExtent.a.Y);  x0Pos := Sender.XGraphToImage(Sender.CurrentExtent.a.X);  x1Pos := Sender.XGraphToImage(Sender.CurrentExtent.b.X);  if (yPos >= y0Pos) and (yPos <= y1Pos) then  begin    ADrawer.SetPenColor(clBlack);    ADrawer.SetPenWidth(1);    ADrawer.Line(x0Pos, YPos, x1Pos, YPos);  end;end;  

Navigation

[0] Message Index

[*] Previous page

Go to full version