I am developing a custom tool for TChart.NET. I would like to know how I can make the tool resize the chart rectangle.
Suppose I want to auto-position the tool on my chart, and have it next to the chart for example on the right. Then I would like the normal chart to shrink down its ChartRect by the width of my tool. You can compare it to the legend, which auto-positions itself, and does not overlap with the chart region itself. I want my tool to behave the same way.
Currently I see no way, by examining the TChart code to achieve this. In a tool you can override the ChartEvent, and capture there some of the events.
I want to resize the chart rectangle before the legend, walls, axes and series are drawn. To make sure that all the rest is properly adapting to my reduced chart rectangle.
The only one I currently see that would work is the BeforeDrawEventArgs chart event, and there adapt the ChartRect with this code in my tool:
Code: Select all
protected override void ChartEvent(EventArgs e)
{
base.ChartEvent(e);
if (e is BeforeDrawEventArgs)
{
Rectangle chartRect = this.Chart.ChartRect;
chartRect.Inflate(-this.Width, 0);
this.Chart.ChartRect = chartRect;
}
}
Code: Select all
internal void InternalDraw(Graphics g, bool noTools)
{
Rectangle chartRect = this.ChartRect;
if (!noTools)
{
this.BroadcastToolEvent(new BeforeDrawEventArgs());
}
this.redrawing = true;
this.CalcInvertedRotation();
foreach (Series series in this.series)
{
if (series.bActive)
{
series.DoBeforeDrawChart();
}
}
if (!this.Graphics3D.SupportsFullRotation)
{
this.DrawTitlesAndLegend(g, ref chartRect, true);
}
this.ChartRect = chartRect;
this.SetSeriesZOrder();
....
}
Code: Select all
internal void InternalDraw(Graphics g, bool noTools)
{
if (!noTools)
{
this.BroadcastToolEvent(new BeforeDrawEventArgs());
}
Rectangle chartRect = this.ChartRect;
...
}
Is there a good reason why TeeChart decides not to allow to resize the chart rect in the BeforeDraw chart event?
Do you see another option to achieve what I want to do?
kind regards,
Dimitri