Page 1 of 1

Series marks with semi-transparent background

Posted: Mon Nov 04, 2019 9:00 pm
by 16585021
I would like to add a semi-transparent background to some marks on a chart, but keep the font non-transparent. The only setting I find for this is Series.Marks.Transparency, but it does both the background and the font.

Can this be achieved?

Thank you,

Ed Dressel

Re: Series marks with semi-transparent background

Posted: Fri Nov 08, 2019 1:56 pm
by yeray
Hello,

You could use events to draw the brush with transparency and draw the marks without brush later:

Code: Select all

uses Series;

type TChartSeriesAccess=class(TChartSeries);

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.View3D:=False;
  Chart1.Legend.Hide;

  with TBarSeries(Chart1.AddSeries(TBarSeries)) do
  begin
    Marks.Shadow.Hide;
    Marks.Transparency:=50;

    FillSampleValues;
  end;

  Chart1.OnBeforeDrawSeries:=SeriesBeforeDraw;
  Chart1.OnAfterDraw:=ChartAfterDraw;
end;

procedure TForm1.SeriesBeforeDraw(Sender: TObject);
begin
  if (Chart1.SeriesCount>0) and (Chart1[0] is TBarSeries) then
  begin
    with TBarSeries(Chart1[0]) do
    begin
      Marks.Brush.Style:=bsSolid;
      Marks.Transparency:=50;
      Marks.Pen.Hide;
      Marks.Font.Color:=clNone;
    end;
  end;
end;

procedure TForm1.ChartAfterDraw(Sender: TObject);
begin
  if (Chart1.SeriesCount>0) and (Chart1[0] is TBarSeries) then
    with TBarSeries(Chart1[0]) do
    begin
      Marks.Transparency:=0;
      Marks.Brush.Clear;
      Marks.Pen.Show;
      Marks.Font.Color:=clBlack;
      TChartSeriesAccess(Chart1[0]).DrawMarks;
    end;
end;