Question

I've got a need to draw gantts that consist of two subsections -- one painted with a brush that has a custom bitmap, and another simply coloured in some specified colour. These subsections have variable length, which makes it impossible to have a preset bitmap for painting.

The current solution I'm using is to have two instances of TGanttSeries, where the firs one is used to display the first kind of subsections, second -- another kind of subsections. This is quite a cumbersome approach, which provides additional challenges where some actions need to be performed on a gantt that visually appears to be a single entity, but in fact consists of two different gantts from two different TGanttSeries instances.

Is it possible to provide custom painting of gantts in TGanttSeries where a single gantt represented as a rectangle could have several subsections painted differently?

Was it helpful?

Solution 2

It appears that overriding method DrawValue that is inherited from TGanttSeries provides the most flexible approach to control drawing of individual points (gantts) by drawing directly on the ParentChart.Canvas object.

However, in my experience if there a need to model a situation where a single gantt consists of several parts that should react to mouse events, have individual marks then potentially a better approach is to provide a TGanttSeries descendent that aggregates separate TGanttSeries instances for each such part. Such TGanttSeries descendent then would be added to an instance of TChart to control the behaviour of all aggregated series components.

Here is an example of using this approach -- the adjacent gantts behave like a single one while providing an easy way to differentiate between the two parts programmaticaly (e.g. for event handling):

enter image description here

OTHER TIPS

You could try using the OnGetPointerStyle event as Yeray suggested here.

Here it is the example from the link:

  private
    { Private declarations }
    Function SeriesGetPointerStyle(Sender:TChartSeries; ValueIndex:Integer):TSeriesPointerStyle;
//...
procedure TForm1.FormCreate(Sender: TObject);
begin
  with Chart1.AddSeries(TGanttSeries) as TGanttSeries do
  begin
    Pointer.VertSize:=10;
    FillSampleValues(10);
    OnGetPointerStyle:=SeriesGetPointerStyle;
  end;
end;

Function TForm1.SeriesGetPointerStyle(Sender:TChartSeries; ValueIndex:Integer):TSeriesPointerStyle;
begin
  Chart1.Canvas.Brush.Style:=TBrushStyle(2+(ValueIndex mod 6));
  result:=psRectangle;
end;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top