Example E1465
Visible to All Users

How to: Create a Drill-Down Chart

Files to look at:

This example demonstrates how to demonstrate master-detail data in the same chart.

You can only use the Drill-Down functionality when chart series are generated by series templates.

Refer to the Drill Down article for more information.

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

Example Code

Form1.cs(vb)
C#
using DevExpress.Drawing; using DevExpress.Utils; using DevExpress.XtraCharts; using DevExpress.XtraEditors; using System.Collections.Generic; using System.Drawing; namespace DrillDownChart { public partial class Form1 : XtraForm { List<string> categories; DXFont linkFont; DXFont regularFont; ChartControl chartControl { get { return chartControl1; } } public Form1() { InitializeComponent(); } private void Form1_Load(object sender, System.EventArgs e) { var keys = SaleItem.CategorizedProducts.Keys; categories = new List<string>(keys.Count); foreach (string category in SaleItem.CategorizedProducts.Keys) categories.Add(category); List<SaleItem> data = SaleItem.GetTotalIncome(); chartControl.DataSource = data; chartControl.SeriesTemplate.SeriesDataMember = "Category"; chartControl.SeriesTemplate.ArgumentDataMember = "Company"; chartControl.SeriesTemplate.QualitativeSummaryOptions.SummaryFunction = "SUM([Income])"; chartControl.SeriesTemplate.View = new StackedBarSeriesView(); SeriesTemplate argumentDrillTemplate = new SeriesTemplate(); argumentDrillTemplate.SeriesDataMember = "Category"; argumentDrillTemplate.ArgumentDataMember = "OrderDate"; argumentDrillTemplate.View = new StackedAreaSeriesView(); argumentDrillTemplate.DateTimeSummaryOptions.MeasureUnit = DateTimeMeasureUnit.Month; argumentDrillTemplate.DateTimeSummaryOptions.UseAxisMeasureUnit = false; argumentDrillTemplate.DateTimeSummaryOptions.SummaryFunction = "SUM([Income])"; chartControl.SeriesTemplate.ArgumentDrillTemplate = argumentDrillTemplate; SeriesTemplate seriesDrillTemplate = new SeriesTemplate(); seriesDrillTemplate.SeriesDataMember = "Product"; seriesDrillTemplate.ArgumentDataMember = "Company"; seriesDrillTemplate.QualitativeSummaryOptions.SummaryFunction = "SUM([Income])"; seriesDrillTemplate.View = new StackedBarSeriesView(); chartControl.SeriesTemplate.SeriesDrillTemplate = seriesDrillTemplate; SeriesTemplate seriesPointDrillTemplate = new SeriesTemplate(); seriesPointDrillTemplate.SeriesDataMember = "Product"; seriesPointDrillTemplate.ArgumentDataMember = "OrderDate"; seriesPointDrillTemplate.DateTimeSummaryOptions.MeasureUnit = DateTimeMeasureUnit.Month; seriesPointDrillTemplate.DateTimeSummaryOptions.UseAxisMeasureUnit = false; seriesPointDrillTemplate.DateTimeSummaryOptions.SummaryFunction = "SUM([Income])"; seriesPointDrillTemplate.View = new StackedAreaSeriesView(); chartControl.SeriesTemplate.SeriesPointDrillTemplate = seriesPointDrillTemplate; if (chartControl.Diagram is XYDiagram diagram) { diagram.Rotated = true; regularFont = diagram.AxisX.Label.DXFont; linkFont = new DXFont(regularFont, DXFontStyle.Underline); diagram.AxisX.Label.DXFont = linkFont; } chartControl.DrillDownStateChanged += chart_DrillDownStateChanged; } void chart_DrillDownStateChanged(object sender, DrillDownStateChangedEventArgs e) { if (chartControl.Diagram is XYDiagram diagram && e.Series.Length > 0) { if (e.Series[0].View is StackedBarSeriesView) { chartControl.CrosshairEnabled = DefaultBoolean.False; chartControl.ToolTipEnabled = DefaultBoolean.True; diagram.Rotated = true; diagram.AxisX.Label.DXFont = this.linkFont; diagram.EnableAxisXScrolling = false; diagram.EnableAxisXZooming = false; } else { chartControl.CrosshairEnabled = DefaultBoolean.True; chartControl.ToolTipEnabled = DefaultBoolean.False; diagram.Rotated = false; diagram.AxisX.Label.DXFont = this.regularFont; diagram.EnableAxisXScrolling = true; diagram.EnableAxisXZooming = true; } } foreach (DrillDownItem item in e.States) { if (item.Parameters.ContainsKey("Category")) { chartControl.PaletteBaseColorNumber = categories.IndexOf(item.Parameters["Category"].ToString()) + 1; return; } } chartControl.PaletteBaseColorNumber = 0; } } }

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.