Back to Devexpress

ChartControl.Diagram Property

windowsforms-devexpress-dot-xtracharts-dot-chartcontrol-227053ac.md

latest11.3 KB
Original Source

ChartControl.Diagram Property

Gets the chart control’s diagram and provides access to its settings.

Namespace : DevExpress.XtraCharts

Assembly : DevExpress.XtraCharts.v25.2.UI.dll

NuGet Package : DevExpress.Win.Charts

Declaration

csharp
[ResetNotSupported]
public Diagram Diagram { get; set; }
vb
<ResetNotSupported>
Public Property Diagram As Diagram

Property Value

TypeDescription
Diagram

A Diagram object that represents the chart control’s diagram.

|

Remarks

Note that you can’t set the Diagram property manually. It’s available to be set for serialization purposes only. For more information on the chart control’s diagram see the Diagram topic and the Diagram object’s description.

Example

The following example demonstrates how to create a ChartControl with two series of the SideBySideBarSeriesView type, and add this chart to a form at runtime. Before proceeding with this example, first create a Windows Forms Application in Visual Studio, and include all necessary assemblies to the References list of your project.

Then, add the following code to the Form.Load event handler.

View Example

csharp
using System;
using System.Windows.Forms;
using DevExpress.XtraCharts;
// ...

namespace SideBySideBar2D {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e) {
            // Create an empty chart.
            ChartControl sideBySideBarChart = new ChartControl();

            // Create the first side-by-side bar series and add points to it.
            Series series1 = new Series("Side-by-Side Bar Series 1", ViewType.Bar);
            series1.Points.Add(new SeriesPoint("A", 10));
            series1.Points.Add(new SeriesPoint("B", 12));
            series1.Points.Add(new SeriesPoint("C", 14));
            series1.Points.Add(new SeriesPoint("D", 17));

            // Create the second side-by-side bar series and add points to it.
            Series series2 = new Series("Side-by-Side Bar Series 2", ViewType.Bar);
            series2.Points.Add(new SeriesPoint("A", 15));
            series2.Points.Add(new SeriesPoint("B", 18));
            series2.Points.Add(new SeriesPoint("C", 25));
            series2.Points.Add(new SeriesPoint("D", 33));

            // Add the series to the chart.
            sideBySideBarChart.Series.Add(series1);
            sideBySideBarChart.Series.Add(series2);

            // Hide the legend (if necessary).
            sideBySideBarChart.Legend.Visibility = DevExpress.Utils.DefaultBoolean.False;

            // Rotate the diagram (if necessary).
            ((XYDiagram)sideBySideBarChart.Diagram).Rotated = true;

            // Add a title to the chart (if necessary).
            ChartTitle chartTitle1 = new ChartTitle();
            chartTitle1.Text = "Side-by-Side Bar Chart";
            sideBySideBarChart.Titles.Add(chartTitle1);

            // Add the chart to the form.
            sideBySideBarChart.Dock = DockStyle.Fill;
            this.Controls.Add(sideBySideBarChart);
        }

    }
}
vb
Imports System
Imports System.Windows.Forms
Imports DevExpress.XtraCharts
' ...

Namespace SideBySideBar2D
    Partial Public Class Form1
        Inherits Form

        Public Sub New()
            InitializeComponent()
        End Sub

        Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
            ' Create an empty chart.
            Dim sideBySideBarChart As New ChartControl()

            ' Create the first side-by-side bar series and add points to it.
            Dim series1 As New Series("Side-by-Side Bar Series 1", ViewType.Bar)
            series1.Points.Add(New SeriesPoint("A", 10))
            series1.Points.Add(New SeriesPoint("B", 12))
            series1.Points.Add(New SeriesPoint("C", 14))
            series1.Points.Add(New SeriesPoint("D", 17))

            ' Create the second side-by-side bar series and add points to it.
            Dim series2 As New Series("Side-by-Side Bar Series 2", ViewType.Bar)
            series2.Points.Add(New SeriesPoint("A", 15))
            series2.Points.Add(New SeriesPoint("B", 18))
            series2.Points.Add(New SeriesPoint("C", 25))
            series2.Points.Add(New SeriesPoint("D", 33))

            ' Add the series to the chart.
            sideBySideBarChart.Series.Add(series1)
            sideBySideBarChart.Series.Add(series2)

            ' Hide the legend (if necessary).
            sideBySideBarChart.Legend.Visibility = DevExpress.Utils.DefaultBoolean.False

            ' Rotate the diagram (if necessary).
            CType(sideBySideBarChart.Diagram, XYDiagram).Rotated = True

            ' Add a title to the chart (if necessary).
            Dim chartTitle1 As New ChartTitle()
            chartTitle1.Text = "Side-by-Side Bar Chart"
            sideBySideBarChart.Titles.Add(chartTitle1)

            ' Add the chart to the form.
            sideBySideBarChart.Dock = DockStyle.Fill
            Me.Controls.Add(sideBySideBarChart)
        End Sub

    End Class
End Namespace

The following code snippets (auto-collected from DevExpress Examples) contain references to the Diagram property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-charts-show-chart-legend-with-markers-in-separate-control/CS/Form1.cs#L58

csharp
{
    XYDiagram2D diagram = chart.Diagram as XYDiagram2D;
    if (diagram != null)

winforms-visualize-data-grid-rows-in-a-chart/CS/ControlRowSourceSample/MainForm.cs#L35

csharp
XYDiagram diagram = (XYDiagram)chartControl.Diagram;
diagram.AxisY.Label.TextPattern = "{V:C0}";

winforms-charts-create-model-for-custom-chart-element/CS/CustomChartElementModel/Form1.cs#L127

csharp
XYDiagram diagram = chart.Diagram as XYDiagram;
diagram.AxisX.Label.TextPattern = "{A:MMM, d (HH:mm)}";

winforms-dashboard-custom-properties/CS/WinForms-Dashboard-Custom-Properties/Modules/ChartScaleBreakModule.cs#L70

csharp
if(e.ChartControl != null)
        UpdateChartScaleBreaks(designer.Dashboard.Items[e.DashboardItemName], e.ChartControl.Diagram);
}

winforms-dashboard-display-each-series-in-separate-pane-for-chart-items/CS/MultiPaneExtension/MultiPaneModule.cs#L97

csharp
MultiPaneSettings settings = MultiPaneSettings.FromJson(chartItem.CustomProperties[customPropertyName]);
    CustomizeDiagram(e.ChartControl.Diagram as XYDiagram, e.ChartControl.Series, settings);
}

winforms-charts-show-chart-legend-with-markers-in-separate-control/VB/Form1.vb#L54

vb
If currentSeries IsNot Nothing Then
    Dim diagram As XYDiagram2D = TryCast(chart.Diagram, XYDiagram2D)
    If diagram IsNot Nothing Then diagram.DefaultPane.Visibility = ChartElementVisibility.Hidden

winforms-visualize-data-grid-rows-in-a-chart/VB/ControlRowSourceSample/MainForm.vb#L32

vb
seriesTemplate.SummaryFunction = "SUM([Revenue])"
Dim diagram As XYDiagram = CType(chartControl.Diagram, XYDiagram)
diagram.AxisY.Label.TextPattern = "{V:C0}"

winforms-charts-create-model-for-custom-chart-element/VB/CustomChartElementModel/Form1.vb#L185

vb
chart.Titles.Add(chartTitle)
Dim diagram As XYDiagram = TryCast(chart.Diagram, XYDiagram)
diagram.AxisX.Label.TextPattern = "{A:MMM, d (HH:mm)}"

winforms-dashboard-custom-properties/VB/WinForms-Dashboard-Custom-Properties/Modules/ChartScaleBreakModule.vb#L72

vb
If e.ChartControl IsNot Nothing Then
    UpdateChartScaleBreaks(designer.Dashboard.Items(e.DashboardItemName), e.ChartControl.Diagram)
End If

winforms-dashboard-display-each-series-in-separate-pane-for-chart-items/VB/MultiPaneExtension/MultiPaneModule.vb#L96

vb
Dim settings As MultiPaneSettings = MultiPaneSettings.FromJson(chartItem.CustomProperties(customPropertyName))
    CustomizeDiagram(TryCast(e.ChartControl.Diagram, XYDiagram), e.ChartControl.Series, settings)
End Sub

See Also

ChartControl Class

ChartControl Members

DevExpress.XtraCharts Namespace