IChartSeries.AutoplaceLabels

Fore Syntax

AutoplaceLabels;

Fore.Net syntax

AutoplaceLabels();

Description

The AutoplaceLabels method locates data labels to avoid their overlapping.

Comments

The correct execution of the method requires all labels of the chart to be rendered. On rendering, size of labels which are required for its correct layout is calculated. If the dynamic creation of a chart with labels is executed, execute the preliminary rendering by the appropriate method depending on the chart location:

  1. A chart is dynamically located on the Fore form. First use  IFormControl.BeginUpdate  and  IFormControl.EndUpdate, this results in rendering of a data label with fitting position. Then use  ITabSheet.BeginUpdate  and  ITabSheet.EndUpdate , that results in rendering of a label with fitting position.

  2. The chart is dynamically located on a regular report sheet or on a Fore.NET form. Use IChartExporter.GetBitmap after previous passing exact size of the chart (IChartExporter.PixelHeight and IChartExporter.PixelWidth).

Below is the example of data labels layout without auto layout (left) and with auto layout (right):

Fore Examples

  1. Dynamic creation of a chart on the form. The example is an event handler for a button. Add links to the Drawing, Tab, Chart system assemblies.
    Executing the example requires the Button1 button and the UiReport, ReportBox components named UiReport1 and ReportBox1.

Sub Button1OnClick(Sender: Object; Args: IMouseEventArgs);
Var 
    tsheet: ITabSheet;
    Placement: IGxRectF;
    Obj: ITabObject;
Begin
    tsheet := ((UiReport1.Instance As IPrxReport).ActiveSheet As IPrxTable).TabSheet;
    Placement := New GxRectF.Create(10107575);
    Self.BeginUpdate;
    Obj := tsheet.Objects.Add("PrxChart", Placement);
    (Obj As IPrxChart).Data := "A0:B7";
    (Obj As IPrxChart).SeriesInRows := False;
    (Obj As IChart).Series.DisplayLabels := True;
    (Obj As IChart).Type := ChartType.Areas;
    Self.EndUpdate; 
    tsheet.BeginUpdate;
    (Obj As IChart).Series.AutoplaceLabels;
    tsheet.EndUpdate;
End Sub Button1OnClick;

After executing the example the ReportBox component contains a chart and the labels positioned to avoid their overlapping.

  1. Dynamic creation of a chart on a sheet of a regular report using a macro. The example is a procedure in the unit, which must be connected to a regular report. A regular report must contain a cell with a hyperlink to this procedure. In A0:B7 cells enter data, based on which the chart will be plotted. Add links to the Drawing, Tab, Chart system assemblies.

Sub UserProc;
Var
    Report: IPrxReport;
    tsheet: ITabSheet;
    Placement: IGxRectF;
    Obj: ITabObject;
    chart: IChart;
    Exp: IChartExporter;
Begin
    Report := PrxReport.ActiveReport;
    tsheet := (Report.ActiveSheet As IPrxTable).TabSheet;
    Placement := New GxRectF.Create(10107575);
    Obj := tsheet.Objects.Add("PrxChart", Placement);
    chart := Obj As IChart; 
    (Obj As IPrxChart).Data := "A0:B7";
    (Obj As IPrxChart).SeriesInRows := False;
    chart.Series.DisplayLabels := True;
    chart.Type := ChartType.Areas;
    Exp := New ChartExporter.Create;
    Exp.Chart := chart;
    Exp.GetBitmap;
    tsheet.BeginUpdate;
    (Obj As IChart).Series.AutoplaceLabels;
    tsheet.EndUpdate;
End Sub UserProc;

After executing the example the report sheet contains a chart and the labels positioned to avoid their overlapping.

Fore.NET Examples

  1. Dynamic creation of a chart on the form. The example is an event handler for a button. Add links to the Drawing, Tab, Chart and Report system assemblies.
    Executing the example requires the Button1 button and the UiReportNet, ReportBoxNet components named UiReportNet1 and ReportBoxNet1. In A0:B7 cells enter data, based on which the chart will be plotted.

Imports Prognoz.Platform.Interop.Chart;
Imports Prognoz.Platform.Interop.Drawing;
Imports Prognoz.Platform.Interop.Report;
Imports Prognoz.Platform.Interop.Tab;
...
Sub button1_Click(sender: System.Object; e: System.EventArgs);
Var 
    tsheet: ITabSheet;
    Obj: ITabObject;
    Placement: GxRectF = New GxRectFClass();
    chart: IChart;
    Exp: IChartExporter = New ChartExporterClass();
    btmp: IGxBitmap;
    
Begin
    tsheet := (uiReportNet1.ReportUi.Report.ActiveSheet As IPrxTable).TabSheet;
    Placement.Create(10105555);
    Obj := tsheet.Objects.Add("PrxChart", Placement);
    chart := Obj As IChart;
    (Obj As IPrxChart).Data := "A0:B7";
    (Obj As IPrxChart).SeriesInRows := False;
    chart.Series.DisplayLabels := True;
    chart.Type := ChartType.chtBars;
    If chart<>Null Then
        Exp.Chart := chart As DxChart;
        btmp := Exp.GetBitmap();
        //Chart update is required to make 
        //marker sizes available in the kernel, which are calculated
        //on rendering
        chart.Refresh();
        chart.Series.AutoplaceLabels();
    End If
End Sub;

After executing the example the ReportBox component contains a chart and the labels positioned to avoid their overlapping.

  1. Dynamic creation of a chart on a sheet of a regular report using event handler. The example is a handler of the Data Area Calculation event in the unit, which must be connected to the regular report. Add links to the Drawing, Tab, Chart system assemblies. After adding a data area to the report sheet calculate it.

Public Override Sub OnAfterExecuteDataIsland(DataIsland : IPrxDataIsland);
Var
    Report: IPrxReport;
    tsheet: ITabSheet;
    Placement: GxRectF = New GxRectFClass();
    Obj: ITabObject;
    chart: IChart;
    Exp: IChartExporter = New ChartExporterClass();
    btmp: IGxBitmap;
Begin
    Report := DataIsland.Report;
    tsheet := (Report.ActiveSheet As IPrxTable).TabSheet;
    Placement.Create(10105555);
    tsheet.Objects.Clear();
    Obj := tsheet.Objects.Add("PrxChart", Placement);
    chart := Obj As IChart;
    (Obj As IPrxChart).Data := DataIsland.Range.Address;
    (Obj As IPrxChart).SeriesInRows := False;
    chart.Series.DisplayLabels := True;
    If chart<>Null Then
        Exp.Chart := chart As DxChart;
        btmp := Exp.GetBitmap();
        //Chart update is required to make marker sizes available in the kernel, which are calculated
        //on rendering
        chart.Refresh();
        chart.Series.AutoplaceLabels();
    End If;
End Sub OnAfterExecuteDataIsland;

After executing the example the report sheet contains a chart plotted by the data area with labels positioned to avoid their overlapping.

See also:

IChartSeries