Author Topic: New charts  (Read 560 times)

Tomxe

  • Full Member
  • ***
  • Posts: 146
New charts
« on: August 04, 2026, 04:10:35 pm »
XelCharts available in OPM:
- Line chart
- Bar chart
- Pie chart
- Spark line

Usage:
Code: Pascal  [Select][+][-]
  1. uses XelChartTypes, XelLineChart, XelBarChart, XelPieChart, XelSparkline;
  2.  
  3.  
  4. const Months : array[0..11] of String =
  5.   ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
  6.    'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
  7.  
  8.   Revenue : array[0..11] of Double =
  9.     (412, 388, 455, 501, 478, 533, 590, 612, 587, 640, 705, 748);
  10.   Cost    : array[0..11] of Double =
  11.     (301, 295, 322, 340, 351, 366, 388, 401, 396, 410, 447, 470);
  12.   Support : array[0..11] of Double =
  13.     ( 61,  58,  70,  66,  74,  81,  77,  90,  84,  95, 101,  98);
  14. var i: Integer;
  15.     C: TXelLineChart;
  16.     C2: TXelBarChart;
  17.     C3: TXelPieChart;
  18.     S: TXelChartSeries;
  19.     Sp: TXelSparkline;
  20. begin
  21.   //Line chart
  22.   C := XelLineChart1;
  23.   C.Theme  := ctLight;
  24.   C.Title  := 'Monthly revenue and cost';
  25.   C.Footer := 'thousands of EUR';
  26.  
  27.   for i := 0 to 11 do C.Categories.Add(Months[i]);
  28.   C.AddSeries('Revenue', Revenue).Style := ssLinePoints;
  29.   C.AddSeries('Cost', Cost).Style := ssLinePoints;
  30.   C.AddSeries('Support', Support).Style := ssLinePoints;
  31.   C.AxisY.LabelFormat := '%.0f';
  32.   C.AxisX.TickCount   := 12;
  33.   C.MarkLast := True;
  34.  
  35.   //Bar chart
  36.   C2 := XelBarChart1;
  37.   C2.Layout := blStacked;
  38.   C2.Title := 'Cost breakdown, stacked';
  39.   for i := 0 to 11 do C2.Categories.Add(Months[i]);
  40.  
  41.   C2.AddSeries('Revenue', Revenue);
  42.   C2.AddSeries('Cost', Cost);
  43.   C2.AddSeries('Support', Support);
  44.   C2.AxisY.LabelFormat := '%.0f';
  45.  
  46.   //Pie chart
  47.   C3 := XelPieChart1;
  48.   C3.Donut := 55;
  49.   C3.Title := 'Traffic by source, donut';
  50.  
  51.   S := C3.Series.Add;
  52.   S.Add(4210, 'Organic');
  53.   S.Add(2870, 'Direct');
  54.   S.Add(1640, 'Referral');
  55.   S.Add( 980, 'Social');
  56.   S.Add( 410, 'Email');
  57.   S.Add(  95, 'Affiliate');
  58.   S.Add(  40, 'Print');
  59.   C3.Labels       := plNamePercent;
  60.   C3.ExplodeIndex := 0;
  61.   C3.Explode      := 10;
  62.  
  63.   //Spark line
  64.   Sp := XelSparkline1;
  65.   Sp.SetData(Revenue);

hedgehog

  • Full Member
  • ***
  • Posts: 135
Re: New charts
« Reply #1 on: August 08, 2026, 06:46:20 am »
Very beautiful.
But I noticed that the outermost mark is drawn over the series name.

I suggest fixing it like this:
Code: Pascal  [Select][+][-]
  1. procedure TXelCustomChart.DrawValueLabel(ACanvas: TCanvas; X, Y: Integer;
  2.   const AText: String; ABelow: Boolean; AAlignment: TAlignment = taCenter);
  3. var
  4.   S: TSize;
  5. begin
  6.   if AText = '' then Exit;
  7.   S:= ACanvas.TextExtent(AText);
  8.   ACanvas.Brush.Style := bsClear;
  9.   ACanvas.Font.Color  := InkColor;
  10.   case AAlignment of
  11.     taRightJustify: X-= S.cx;
  12.     taCenter:       X-= (S.cx-1) div 2;
  13.   end;
  14.   if ABelow then Y+= 3 else Y-= S.cy + 3;
  15.   ACanvas.TextOut(X, Y, AText);
  16.   ACanvas.Brush.Style := bsSolid;
  17. end;

and
Code: Pascal  [Select][+][-]
  1. procedure TXelLineChart.DrawOverlay(ACanvas: TCanvas; const ARect: TRect);
  2. ...
  3.     else if FMarkLast then
  4.     begin
  5.       J := S.Count - 1;
  6.       if S.Text[J] <> '' then Txt := S.Text[J]
  7.                          else Txt := AxisY.FormatValue(S.Y[J]);
  8.       DrawValueLabel(ACanvas, ValueToX(S.X[J], ARect),
  9.         ValueToY(S.Y[J], ARect), Txt, False, taRightJustify); // <<--- this
  10.     end;
  11.   end;
  12. end;
« Last Edit: August 08, 2026, 06:51:29 am by hedgehog »

Boleeman

  • Hero Member
  • *****
  • Posts: 1169
Re: New charts
« Reply #2 on: August 08, 2026, 11:17:33 am »
Thanks Tomxe for your great Charts and the other components on the OPM.

I tried aligning in the other direction (to the right) and extended the white background a little.
« Last Edit: August 10, 2026, 04:29:23 am by Boleeman »

Tomxe

  • Full Member
  • ***
  • Posts: 146
Re: New charts
« Reply #3 on: August 09, 2026, 08:20:17 pm »
Very nice, guys!

Boleeman

  • Hero Member
  • *****
  • Posts: 1169
Re: New charts
« Reply #4 on: August 10, 2026, 04:26:40 am »
Not sure if you are interested Tomxe but I was working on a 3D transparent version?
(but written in CSharp)


JD

  • Hero Member
  • *****
  • Posts: 1916
Re: New charts
« Reply #5 on: August 10, 2026, 12:13:34 pm »
XelCharts available in OPM:
- Line chart
- Bar chart
- Pie chart
- Spark line

Very good. Thanks or sharing.

JD
Linux Mint - Lazarus 4.8/FPC 3.2.2,
Windows - Lazarus 4.8/FPC 3.2.2

mORMot 2, PostgreSQL & MariaDB.

 

TinyPortal © 2005-2018