Forum > TAChart

primary Questions about TChart

<< < (3/4) > >>

wp:

--- Quote from: majid.ebru on February 11, 2018, 07:29:39 am ---
--- Quote from: wp on February 11, 2018, 12:18:42 am ---In the attachment there is a solution to the "color-split" chart. It is based on the user-drawn series as described above. Drag the horizontal dividing line up and down to move the color boundary. There's a little glitch, when data point symbols are shown and the dividing line goes right through the symbol because the symbol is always drawn as a full circle - to get over this a clipping approach should be used.

--- End quote ---

Thankyou

your project is very Goooooooood

but i can't compile your project?

waht do i do?

i should update my TChart element?

--- End quote ---
It seems that you don't use Laz 1.8. You should upgrade, there are many new features.

If you don't want to, just remove the line causing the trouble.

wp:

--- Quote from: majid.ebru on February 11, 2018, 07:31:07 am ---
--- Quote from: wp on February 10, 2018, 09:52:01 pm ---
--- Quote from: majid.ebru on February 09, 2018, 07:31:31 pm ---how can i have mult color line?

--- End quote ---
The TLineSeries of TAChart in Lazarus trunk, r57277, now has a new property "ColorEach" with which you can colorize the line segments individually. The color is added to the data points (4th parameter of the series method AddXY) and can be applied to data points symbol and/or the line segments before or after each data point (TColorEachMode = (ceNone, cePoint, ceLineBefore, ceLineAfter, cePointAndLineBefore, cePointAndLineAfter).

See the demo in the TAChart demo folder (lazarus/components/tachart/demo/line)

--- End quote ---

it's perfect

how can i do that?

--- End quote ---
You must install the trunk version of Lazarus (this is the developer version). The easiest way is using the fpcupdeluxe program (https://github.com/newpascal/fpcupdeluxe/releases/tag/v1.6.0n).

corpsman:

--- Quote from: wp on February 11, 2018, 12:18:42 am ---In the attachment there is a solution to the "color-split" chart. It is based on the user-drawn series as described above. Drag the horizontal dividing line up and down to move the color boundary. There's a little glitch, when data point symbols are shown and the dividing line goes right through the symbol because the symbol is always drawn as a full circle - to get over this a clipping approach should be used.

--- End quote ---

The sample is cool but your intersect routine has some errors
here is my version that works better ;)

--- 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";}};} ---Function Intersect(p1, p2: TPoint; y: Integer): Integer;Begin  If p1.y = p2.y Then // fixed catch of div by zero    Result := (p1.x + p2.x) Div 2  Else    Result := round(((p2.x - p1.x) * (y - p1.y)) / (p2.y - p1.y) + p1.x); // reorder to divide "larger" numbers is more stable.End;   
And the Routine that does the rending changed to this:


--- 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.Chart1UserDrawnSeries1Draw(ACanvas: TCanvas;  Const ARect: TRect);   Procedure DrawCircle(p: TPoint; AColor: TColor; R: Integer);  Begin    Chart1.Drawer.SetBrushParams(bsSolid, AColor);    Chart1.Drawer.Ellipse(P.x - R, P.y - R, P.x + R, P.y + R);  End;   Function GetColor(y, yref: Integer): TColor;  Begin    If y > yref Then      Result := COLOR_BELOW    Else      Result := COLOR_ABOVE;  End; Var  i: Integer;  gp: TDoublePoint;  p1, p2, p3: TPoint;  yref: Integer;  x: Integer;  showDataPoints: Boolean;Begin  showDataPoints := Checkbox1.Checked;  pen.Width := 4;  Chart1.Drawer.Pen := Pen;  yref := Chart1.YGraphToImage(Chart1ConstantLine1.Position);   i := 0;  gp := DoublePoint(Data[i].X, Data[i].Y);  p1 := Chart1.GraphToImage(gp);  If showDataPoints Then Begin    Chart1.Drawer.SetPenParams(psSolid, GetColor(p1.y, yref));    DrawCircle(p1, GetColor(p1.y, yref), RADIUS); // Fix copy paste index error 2->1  End;  For i := 1 To High(Data) Do Begin // draw from second to last point (index of by one correction)    gp := DoublePoint(Data[i].X, Data[i].Y);    p2 := Chart1.GraphToImage(gp);    If (p2.y - yref) * (p1.y - yref) < 0 Then Begin      p3 := Point(Intersect(p1, p2, yref), yref);      Chart1.Drawer.SetPenParams(psSolid, GetColor(p1.y, yref), 2);      Chart1.Drawer.Line(p1, p3);      Chart1.Drawer.SetPenParams(psSolid, GetColor(p2.y, yref), 2);      Chart1.Drawer.Line(p3, p2);    End    Else Begin      Chart1.Drawer.SetPenParams(psSolid, GetColor(p2.y, yref), 2);      Chart1.Drawer.Line(p1, p2);    End;    If showDataPoints Then      DrawCircle(p2, GetColor(p2.y, yref), RADIUS);    p1 := p2;  End;End;   
Thanks a lot for publishing your code.

wp:
Thanks for pointing out these bugs. I committed the fix to git-main (except for the reordering of multiplication and division - this really makes no difference with floats).

Tulurdes:
Hi all, I know this topic is a little old but I think it is still very relevant.

I haven't updated from 2.2.4 yet, so I'm not sure if they improved the chart possibilities.
But I've made some changes on this code and made it more compact in the draw event so I could reuse it in a easier way.

I've also added a "fill" option so it could work as both line and area.

But I'm struggling with something, I'd like to make this chart independent, but there are some items that seems impossible to replace since the event only passes as parameters ACanvas and ARect

This are the calls I can't get rid of
Chart1.YGraphToImage (direct access to a chart)
Chart1.GraphToImage (direct access to a chart)
Data.X, Data.Y (direct access to chart data source)

What I want is to be able to create charts at runtime and have this drawing style working on all of them.

Any help would be very welcome.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version