Chart Nested Component Structure
- 6 minutes to read
The DxChart component can include multiple sub-elements, such as a series, title, legend, or annotation. To display sub-elements on the chart plane, add the corresponding nested components to chart markup. You should declare nested components at appropriate nesting levels to render the chart component correctly.
This topic contains detailed information about available nesting levels and components permitted at each level.
First-Level Components
The Chart’s root level (<DxChart>...</DxChart>
) can contain the following components:
- One or more individual series
- DxChartCommonSeries
- DxChartLegend
- DxChartTitle
- DxChartArgumentAxis
- One or more DxChartValueAxis
- One or more DxChartPane
- One or more DxChartAnnotation
- DxChartTooltip
- DxChartZoomAndPanSettings
- DxChartAnimationSettings
- DxChartScrollBarSettings
The following code snippet adds first-level components to chart markup. For a sample data source, refer to our GitHub repository.
<DxChart Data="@Sales.dataSource">
<DxChartLegend AllowToggleSeries="true"
HorizontalAlignment="HorizontalAlignment.Center" />
<DxChartTitle Text="Sales amount" />
<DxChartArgumentAxis EndOnTick="false" />
<DxChartValueAxis EndOnTick="false" />
<DxChartPane Name="Pane1" />
<DxChartPane Name="Pane2" />
<DxChartLineSeries Name="2017" Filter="@((SaleInfo s) => s.Date.Year == 2017)"
ArgumentField="@(s => s.City)" ValueField="@(s => s.Amount)"
Pane="Pane1" />
<DxChartLineSeries Name="2018" Filter="@((SaleInfo s) => s.Date.Year == 2018)"
ArgumentField="@(s => s.City)" ValueField="@(s => s.Amount)"
Pane="Pane2" />
<DxChartTooltip Enabled="true" Position="RelativePosition.Outside">
<div style="margin: 0.75rem">
<div>City: @context.Point.Argument</div>
<div>Number of Sales: @context.Point.Value</div>
</div>
</DxChartTooltip>
<DxChartZoomAndPanSettings ArgumentAxisZoomAndPanMode="ChartAxisZoomAndPanMode.Zoom" />
<DxChartAnimationSettings Enabled="false" />
<DxChartScrollBarSettings ArgumentAxisScrollBarVisible="true" />
</DxChart>
Second-Level Components
This section lists first-level components that can contain child components.
Individual Series
An individual series of any type can include:
- DxChartSeriesPoint
- DxChartSeriesLabel
- DxChartSeriesLegendItem
- DxChartAggregationSettings
- DxChartSeriesValueErrorBar
Financial series (DxChartCandlestickSeries and DxChartStockSeries) can also include DxChartFinancialReduction objects.
The following code snippet creates a line series and adds second-level components to series markup:
<DxChartLineSeries Name="2017" Filter="@((SaleInfo s) => s.Date.Year == 2017)"
ArgumentField="@(s => s.City)" ValueField="@(s => s.Amount)"
Pane="Pane1">
<DxChartSeriesPoint Color="@System.Drawing.Color.Orange" />
<DxChartSeriesLabel Position="RelativePosition.Outside" />
<DxChartSeriesLegendItem IconCssClass="oi oi-flag" />
<DxChartAggregationSettings Enabled="true"
Method="ChartAggregationMethod.Sum" />
</DxChartLineSeries>
Common Series
The DxChartCommonSeries component can only contain the SeriesTemplate. The template should include at least one series. To specify series-related settings, add the corresponding components to series markup. For more information on supported child components, refer to the section above.
The following code snippet defines SeriesTemplate
inside the DxChartCommonSeries
component:
<DxChartCommonSeries NameField="@((SaleInfo s) => s.Date.Year)"
ArgumentField="@((SaleInfo s) => s.City)"
ValueField="@((SaleInfo s) => s.Amount)">
<SeriesTemplate Context="settings">
<DxChartLineSeries Settings="@settings">
<DxChartSeriesPoint Color="@System.Drawing.Color.Orange" />
<DxChartSeriesLabel Position="RelativePosition.Outside" />
<DxChartSeriesLegendItem IconCssClass="oi oi-flag" />
<DxChartAggregationSettings Enabled="true" Method="ChartAggregationMethod.Sum" />
</DxChartLineSeries>
</SeriesTemplate>
</DxChartCommonSeries>
Axes
The argument and value axes can contain the following components:
- DxChartAxisGridLines
- DxChartAxisTick
- DxChartAxisMinorTick
- DxChartAxisTitle
- DxChartConstantLine
- DxChartAxisRange
- DxChartAxisLabel
- DxChartScaleBreak
- One or more DxChartAxisStrip
The following code snippet adds second-level components to the markup of chart axes:
<DxChartArgumentAxis EndOnTick="false">
<DxChartAxisGridLines Visible="true" />
</DxChartArgumentAxis>
<DxChartValueAxis EndOnTick="false">
<DxChartConstantLine Value="60000" />
<DxChartValueBreaks StartValue="10000" EndValue="15000" />
<DxChartAxisRange StartValue="0" EndValue="82000" />
<DxChartAxisLabel Format="ChartElementFormat.Thousands()" />
<DxChartAxisTitle Text="Items" />
</DxChartValueAxis>
Title
The DxChartTitle component can contain the DxChartSubTitle.
<DxChartTitle Text="Sales amount">
<DxChartSubTitle Text="by cities" />
</DxChartTitle>
Third-Level Components
This section lists second-level components that can contain child components.
Legend
The DxChartLegend component can contain DxChartTitle and DxChartSubTitle (inside the title’s markup) objects.
<DxChartLegend AllowToggleSeries="true"
HorizontalAlignment="HorizontalAlignment.Center">
<DxChartTitle Text="Sales amount">
<DxChartSubTitle Text="by cities" />
</DxChartTitle>
</DxChartLegend>
Legend Item
The DxChartSeriesLegendItem component can contain the TextTemplate that customizes a legend item’s text.
<DxChartLineSeries Name="2017" Filter="@((SaleInfo s) => s.Date.Year == 2017)"
ArgumentField="@(s => s.City)" ValueField="@(s => s.Amount)"
Pane="Pane1">
<DxChartSeriesLegendItem IconCssClass="oi oi-flag">
<TextTemplate><b>Current year</b></TextTemplate>
</DxChartSeriesLegendItem>
</DxChartLineSeries>
Constant Line
The DxChartConstantLine component can contain the DxChartConstantLineLabel that configures the constant line’s label.
<DxChartValueAxis EndOnTick="false">
<DxChartConstantLine Value="60000">
<DxChartConstantLineLabel Text="Planned Value" />
</DxChartConstantLine>
</DxChartValueAxis>
Series Point
The DxChartSeriesPoint component can contain a DxChartSeriesPointImage object that customizes the series point image.
<DxChartLineSeries Name="2017" Filter="@((SaleInfo s) => s.Date.Year == 2017)"
ArgumentField="@(s => s.City)" ValueField="@(s => s.Amount)"
Pane="Pane1">
<DxChartSeriesPoint Color="@System.Drawing.Color.Orange">
<DxChartSeriesPointImage Width="50" Height="50" />
</DxChartSeriesPoint>
</DxChartLineSeries>
Series Label
The DxChartSeriesLabel component can contain the following child components:
- DxChartSeriesLabelConnector
- Customizes a line displayed between a point and its label.
- DxChartFont
- Contains the element’s font settings.
- DxChartSeriesLabelBorder
- Defines series label border settings.
<DxChartLineSeries Name="2017" Filter="@((SaleInfo s) => s.Date.Year == 2017)"
ArgumentField="@(s => s.City)" ValueField="@(s => s.Amount)"
Pane="Pane1">
<DxChartSeriesLabel Position="RelativePosition.Outside">
<DxChartSeriesLabelConnector Width="3" />
<DxChartFont Size="14" Weight="600" />
</DxChartSeriesLabel>
</DxChartLineSeries>
Annotation
The DxChartAnnotation component can contain the following child components:
- DxChartAnnotationImage
- Defines settings for image annotations.
- DxChartAnnotationBorder
- Defines annotation border settings.
- DxChartAnnotationShadow
- Defines annotation shadow settings.
- DxChartFont
- Contains the element’s font settings.
<DxChartAnnotation Argument="new DateTime(2019, 9, 10)"
Series="AAPL"
Text="Watch Series 5"
Opacity="0.3">
<DxChartAnnotationBorder Color="#FFC107" Width="2" CornerRadius="4" Opacity="0.8"/>
<DxChartAnnotationShadow Color="#FFC107" Blur="6" Opacity="0.7"/>
</DxChartAnnotation>
Axis Strip
The DxChartAxisStrip component can contain a DxChartAxisStripLabel component that configures strip label settings.
<DxChartAxisStrip StartValue="@HighAverage"
Color="rgba(255, 155, 85, 0.15)">
<DxChartAxisStripLabel Text="Above average high">
<DxChartFont Color="@HighAverageColor" Weight="500" Size="14"/>
</DxChartAxisStripLabel>