Recent

Author Topic: Bar chart pen property  (Read 270 times)

badmintonfan

  • New Member
  • *
  • Posts: 36
Bar chart pen property
« on: January 23, 2023, 10:24:28 am »
I make a bar chart,is there a way to set one of the bars's barpen property like style,color different than others?

wp

  • Hero Member
  • *****
  • Posts: 10862
Re: Bar chart pen property
« Reply #1 on: January 23, 2023, 11:46:33 am »
When adding data points to the series you can specify a color for each data point. In case of the bar series this is used as brush color of that individual data point. Applying it to the pen in some kind of automatic way, however, is not possible.

Of course, you can custom-draw the bars. A BarSeries has the event onCustomDrawBar:
Code: Pascal  [Select][+][-]
  1. type
  2.   TCustomDrawBarEvent = procedure (
  3.     ASeries: TBarSeries; ADrawer: IChartDrawer; const ARect: TRect;
  4.     APointIndex, AStackIndex: Integer) of object;

In the following example the bar with index 5 is painted in green with thick darker border:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Chart1BarSeries1CustomDrawBar(ASeries: TBarSeries;
  2.   ADrawer: IChartDrawer; const ARect: TRect; APointIndex, AStackIndex: Integer);
  3. begin
  4.   if APointIndex = 5 then
  5.   begin
  6.     ADrawer.SetBrushColor(clLime);
  7.     ADrawer.SetPenParams(psSolid, clGreen, 5);
  8.   end else
  9.   begin
  10.     ADrawer.SetBrushColor(ASeries.BarBrush.Color);
  11.     ADrawer.SetPen(ASeries.BarPen);
  12.   end;
  13.   ADrawer.Rectangle(ARect);
  14. end;
Note, however, that you are completely left alone here. If you want a 3D-like presentation as in your screenshot you must draw the sides yourself, and you also must take care of the shading of the side-walls.

 

TinyPortal © 2005-2018