IChartSeries.AutoplaceLabels

Fore Syntax

AutoplaceLabels;

Fore.Net syntax

AutoplaceLabels();

Description

The AutoplaceLabels method locates labels in a way, that prevents their overlapping each other.

Comments

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

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

  2. The chart is dynamically arranged on the sheet of a regular report or on Fore.Net form. Use IChartExporter.GetBitmap, previously passed exact size of the chart (IChartExporter.PixelHeight and IChartExporter.PixelWidth).

The following example shows layout of lables 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.
    Execution of the example requires the button with Button1 name and UiReport, ReportBox components with UiReport1 and ReportBox1 names.

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 in a way to avoid overlapping.

  1. Dynamic creation of a chart on a sheet of a regular report using macro. The example is a procedure in a module which should 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 built. 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 in a way to avoid 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.
    Execution of the example requires the button with Button1 name and UiReportNet, ReportBoxNet components with UiReportNet1 and ReportBoxNet1 names. In A0:B7 cells enter data, based on which the chart will be built.

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 the 
        //marker sizes available in the kernel, which are calculated
        //on drawing
        chart.Refresh();
        chart.Series.AutoplaceLabels();
    End If
End Sub;

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

  1. Dynamic creation of a chart on a sheet of a regular report using event handler. The example is the handler of Calculating Data Area event in the module which must be connected to the regular report. Add links to the Drawing, Tab, Chart system assemblies. After adding 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 the marker sizes available in the kernel, which are calculated
        //on drawing
        chart.Refresh();
        chart.Series.AutoplaceLabels();
    End If;
End Sub OnAfterExecuteDataIsland;

After executing the example the report sheet contains a chart, built by the data area with labels, arranged in a way to avoid overlapping.

See also:

IChartSeries