Professional Documents
Culture Documents
612
Examples
Charting > Examples
This section provides a list of examples, contained in this help, that are grouped by features (General, Creating
Charts, Chart Elements, End-User Interaction and Producing Output).
General
How to: Add a Chart to a W indows Forms Application
How to: Add a Chart to a W eb Application
Creating Charts
Providing Data
How to: Bind Individual Chart Series to Data
How to: Bind Individual Chart Series to Data (Runtime Sample)
How to: Bind a Chart to Data Using Series Templates
How to: Bind a Chart to Data Using Series Templates (Runtime Sample)
How to: Individually Change the View Type of Automatically Created Series
How to: Change Colors of Automatically Created Series
How to: Bind Series to Data and Display Them In Separate Panes (Runtime Sample)
How to: Bind a Chart to an MDB Database (Runtime Sample)
How to: Bind a Chart to an Array List
How to: Bind a Chart to an XML Data Source
How to: Bind a Chart to an XPO Data Source
How to: Link a Chart to the PivotGridControl's Data Source
How to: Create a Custom Summary Function
Data Representation
How to: Change the Display Format for Series Labels
How to: Change the Display Format for Axis Labels
How to: Change the Display Format for Axis Labels (Runtime Sample)
How to: Show Values as Percents in the Legend of a Pie Chart
How to: Filter Data
How to: Show N Top Points as a Single Section in a Pie Chart
How to: Use Automatic Date-Time Scale Modes of an Axis
How to: Obtain Values Calculated for Automatic Axis Date-Time Scale Modes
How to: Exclude W eekends and Holidays from the Axis Scale
How to: Adjust Point Options of the Pie Series View Type at Runtime
Appearance Customization
How to: Customize a Chart's Appearance
How to: Customize the Appearance of a Chart's Legend
How to: Customize Gridlines and Tickmarks of an Axis
How to: Customize the Appearance of a Pane's Scroll Bar (Runtime Sample)
How to: Custom Paint Series
How to: Custom Paint Series Points
How to: Conditionally Hide Series Labels
612
Examples
613
How to: Make Series Labels Display Custom Information
How to: Avoid Overlapping of Series Labels
How to: Change the Names for Auto-Created Series
How to: Custom Draw a Crosshair Cursor
Series Views
How to: Change the View of a Series
How to: Create a Gantt Chart with Task Links
How to: Explode Points of a Pie Chart
Panes
How to: Create a Multi-Pane Chart
How to: Display a Series in an Additional Pane (Runtime Sample)
How to: Display Automatically Created Series in Separate Panes
Axes
How to: Add a Title to an Axis
How to: Determine whether an Axis Title is Being Hovered by the Mouse Pointer
How to: Add Secondary Axes to a Chart
How to: Create Custom Axis Labels
How to: Individually Customize Axis Labels
How to: Add a Constant Line to an Axis
How to: Add a Strip to an Axis
How to: Enable Automatic Scale Breaks for an Axis
How to: Manually Insert a Scale Break into an Axis
How to: Manually Insert a Scale Break into an Axis (Runtime Sample)
Indicators
How to: Add a Trend Line to a Chart
How to: Show a Regression Line for a Stock Chart
How to: Show a Regression Line for a Stock Chart (Runtime Sample)
2013 DevExpress Inc.
613
Examples
614
How to: Add a Fibonacci Indicator to a Chart
How to: Add a Fibonacci Indicator to a Chart (Runtime Sample)
Annotations
How to: Create a Text Annotation Anchored to a Series Point
How to: Create an Image Annotation Anchored to a Chart or Pane
How to: Add an Annotation at Runtime
End-User Interaction
Hit Testing, Hot-Tracking and Selection
How to: Determine which Chart Element Is Hovered by the Mouse Pointer
How to: Determine which Series Point Is Located Under the Test Point
How to: Show a Tooltip with a Series Point's Data
How to: Show Series Labels Only for Hot-tracked Points
How to: Implement Custom Hot-Tracking and Selection
How to: Provide a Custom Cursor for a Chart
How to: Provide Interactive Editing for Series Points
How to: Provide Interactive Editing for a Constant Line
How to: Create a Drill-Dow n Chart
How to: Show Tooltips for a W ebChartControl
How to: Format Values in a Crosshair Cursor via a Label's Patterns
Chart Wizard
How to: Invoke the Chart Wizard at Runtime
How to: Change the Page Order in a W izard
How to: Add a New Page to a Wizard
How to: Hide Certain Tabs on a W izard's Page
Producing Output
Storing Chart Definitions
How to: Save and Restore a Layout
Printing
How to: Print a Chart and Show Its Print Preview
How to: Use the PrintableComponentLink to Print DevExpress Controls
Exporting
How to: Export a Chart to PDF
How to: Export a Chart to HTML and MHT
How to: Export a Chart to XLS
2013 DevExpress Inc.
614
Examples
615
How to: Export a Chart to Image
Localization
How to: Localize DevExpress W inForms Controls Using Satellite Assemblies
How to: Localize DevExpress Controls by Changing Default Resources
How to: Replace Default Resources with Their Equivalents
615
Examples
616
General
How to: Add a Chart to a Windows Forms Application
Charting > Examples > How to: Add a Chart to a W indows Forms Application
The follow ing example demonstrates how to add the ChartControl to a form. Note that the Chart Control can be
added to your charting application at both design time and runtime.
Design time.
By default, the ChartControl item is added to the DX.12.2: Data toolbox tab of the VS IDE. So, to add the
Chart Control to your project, simply drag the corresponding toolbox item, and drop it onto the form.
Note
W hile adding the ChartControl, the Chart Wizard window may be invoked (in case its "Show wizard every time a
new chart is added" option is enabled). Click Cancel if you don't w ant to use it, or go through its steps to customize
the initial look of your chart.
Runtime.
To add a Chart Control to a form at runtime, don't forget to inclide all necessary assemblies to the
References list of your project.
C#
C opy C ode
using System.Drawing;
using System.Windows.Forms;
using DevExpress.XtraCharts;
// ...
private void OnButtonClick(object sender, System.EventArgs e) {
// Create a new Chart control.
ChartControl chart = new ChartControl();
// Set the chart's location.
chart.Location = new Point(10, 10);
// Perform any other initialization here.
// ...
// ...
// Add the chart to the Form.
this.Controls.AddRange(new Control[] {chart});
}
Visual Basic
C opy C ode
616
Examples
617
Imports System.Drawing
Imports System.Windows.Forms
Imports DevExpress.XtraCharts
' ...
Private Sub OnButtonClick(sender As Object, e As System.EventArgs) _
Handles Button1.Click
' Create a new Chart control.
Dim chart As New ChartControl()
' Set the chart's location.
chart.Location = New Point(10, 10)
' Perform any other initialization here.
' ...
' ...
' Add the chart to the Form.
Me.Controls.AddRange(New Control() {chart})
End Sub
617
Examples
618
After that, you can add series (of either 2D series view s or 3D series views) to your chart, and populate them w ith
data.
Note
After a W ebChartControl is dropped onto a page, your w eb application's Web.config file is affected. To learn more
on these changes, refer to Adding a Web Chart.
For specific information on working with XtraCharts in an ASP.NET platform, refer to Web Charting Specifics.
See Also
How to: Add a Chart to a W eb Page (Runtime Sample)
618
Examples
619
Creating Charts
Providing Data
How to: Bind Individual Chart Series to Data
Charting > Examples > How to: Bind Individual Chart Series to Data
This tutorial demonstrates how to bind a chart to an external data source, manually add a series to the chart, and
adjust its data bindings. This means that it is possible to provide an individual data source for each series.
To learn how to manually bind a chart's series to data, do the follow ing.
Create a Chart and Bind it to Data
Specify a Series Data Source
Populate w ith Data at Design and Runtime
Customize the Chart
Get the Result
Create a Chart and Bind it to Data
1.Start Microsoft Visual Studio (2008, 2010 or 2012) and create a new Windows Forms Application or
open an existing one.
2.From the DX.12.2: Visualization toolbox tab, drop the ChartControl onto the form.
Note that in this instance the Chart W izard may be invoked (if its "Show w izard every time a new chart
is added" option is enabled). In this example, we don't need to use the w izard, so click the Cancel
button to close the W izard and manually customize the chart.
Note
For the chart to occupy all the available space on the form, click the chart's smart tag, and in its actions list, click
Dock in parent container.
3.To define a data source for the chart, click its smart tag, and in its actions list, expand the Choose Data
Source drop-dow n list and click on Add Project Data Source... link.
619
Examples
620
The Data Source Configuration Wizard appears. It allow s you to select a data source.
4.In the W izard's first page, select the Database icon and click Next.
5.On the follow ing page, click New Connection and specify the path to the Northwind database file (leave
the Password option blank). Then, you may use the Test Connection option to test data source
availability.
620
Examples
621
621
Examples
622
7.Now , choose the tables or views containing information required for the chart. Select the "Products"
table as shown below and click Finish.
622
Examples
623
As a result, Visual Studio w ill generate a set of classes for data manipulation w ithin the project. The main ones
are:
nwindDataSet - represents a DataSet object (a collection of tables, relationships, and constraints), which
contains the Products table from the Northwind database.
productsTableAdapter - represents a TableAdapter object, providing communication between the
application and a database. Its methods are used for executing queries and stored procedures, fetching
data and filling DataTables in DataSets, and sending data back to the database. It is assigned to the
ChartControl.DataAdapter property.
productsBindingSource - represents a System.Windows.Forms.BindingSource component, used to
simplify the data binding of the nw indDataSet to the ChartControl. It is assigned to the ChartControl.
DataSource property.
Now, the chart has been bound to data. The next steps specify which data fields should be used to provide data
for the chart's series.
Specify a Series Data Source
8.Now , let's add series to the chart. To do this, click the chart's smart tag and in its actions list, choose
the Series... link.
623
Examples
624
9.In the invoked Series Collection Editor, click Add..., and select the Bar view.
Note
After you create a series, the chart displays fake data, to give you an idea of what the chart w ill look like after
genuine data is provided.
10.Now , sw itch to the Properties tab on the right of the editor's w indow and make the following
assignments for the Series1 properties.
624
Examples
625
C opy C ode
C opy C ode
625
Examples
626
collision detection and resolution for series labels via the SeriesLabelBase.ResolveOverlappingMode
property.
Create additional elements.
There are plenty of special elements that you can enable for your charts, such as annotations,
trendlines, strips, regression lines and Fibonacci indicators. To produce a clear representation of large
amounts of data, you can enable logarithmic axis scaling (via the AxisBase.Logarithmic property), enable
scale breaks (via the Axis.ScaleBreaks property), and provide zooming and scrolling capabilities.
Change the chart's appearance.
To specify a color for series points, use the ChartControl.PaletteBaseColorNumber, ChartControl.
PaletteName and ChartControl.AppearanceName properties. For more information on their use, refer to
Appearance Customization.
See Also
How to: Bind a Chart to Data Using Series Templates
626
Examples
627
C opy C ode
(Form1.cs)
using System;
using System.Data;
using System.Windows.Forms;
using DevExpress.XtraCharts;
// ...
namespace BindIndividualSeriesRuntimeCS {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
private DataTable CreateChartData(int rowCount) {
// Create an empty table.
DataTable table = new DataTable("Table1");
// Add two columns to the table.
table.Columns.Add("Argument", typeof(Int32));
table.Columns.Add("Value", typeof(Int32));
// Add data rows to the table.
Random rnd = new Random();
DataRow row = null;
for (int i = 0; i < rowCount; i++) {
row = table.NewRow();
row["Argument"] = i;
row["Value"] = rnd.Next(100);
table.Rows.Add(row);
}
return table;
}
private void Form1_Load(object sender, EventArgs e) {
// Create a chart.
ChartControl chart = new ChartControl();
// Create an empty Bar series and add it to the chart.
Series series = new Series("Series1", ViewType.Bar);
chart.Series.Add(series);
// Generate a data table and bind the series to it.
series.DataSource = CreateChartData(50);
// Specify data members to bind the series.
series.ArgumentScaleType = ScaleType.Numerical;
series.ArgumentDataMember = "Argument";
series.ValueScaleType = ScaleType.Numerical;
series.ValueDataMembers.AddRange(new string[] { "Value" });
// Set some properties to get a nice-looking chart.
((SideBySideBarSeriesView)series.View).ColorEach = true;
((XYDiagram)chart.Diagram).AxisY.Visible = false;
chart.Legend.Visible = false;
2013 DevExpress Inc.
627
Examples
628
// Dock the chart into its parent and add it to the current form.
chart.Dock = DockStyle.Fill;
this.Controls.Add(chart);
}
}
}
Visual Basic
C opy C ode
(Form1.vb)
Imports System
Imports System.Data
Imports System.Windows.Forms
Imports DevExpress.XtraCharts
' ...
Public Class Form1
Private Function CreateChartData(ByVal rowCount As Integer) As DataTable
' Create an empty table.
Dim Table As New DataTable("Table1")
' Add two columns to the table.
Table.Columns.Add("Argument", GetType(Int32))
Table.Columns.Add("Value", GetType(Int32))
' Add data rows to the table.
Dim Rnd As New Random()
Dim Row As DataRow = Nothing
Dim i As Integer
For i = 0 To rowCount - 1
Row = Table.NewRow()
Row("Argument") = i
Row("Value") = Rnd.Next(100)
Table.Rows.Add(Row)
Next i
Return Table
End Function
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) _
Handles MyBase.Load
' Create a chart.
Dim Chart As New ChartControl()
' Create an empty Bar series and add it to the chart.
Dim Series As New Series("Series1", ViewType.Bar)
Chart.Series.Add(Series)
' Generate a data table and bind the series to it.
Series.DataSource = CreateChartData(50)
' Specify data members to bind the series.
Series.ArgumentScaleType = ScaleType.Numerical
Series.ArgumentDataMember = "Argument"
Series.ValueScaleType = ScaleType.Numerical
Series.ValueDataMembers.AddRange(New String() {"Value"})
' Set some properties to get a nice-looking chart.
CType(Series.View, SideBySideBarSeriesView).ColorEach = True
CType(Chart.Diagram, XYDiagram).AxisY.Visible = False
Chart.Legend.Visible = False
' Dock the chart into its parent and add it to the current form.
Chart.Dock = DockStyle.Fill
Me.Controls.Add(Chart)
End Sub
End Class
See Also
How to: Bind Individual Chart Series to Data
628
Examples
629
Then, proceed through the follow ing steps suggested by the invoked Data Source Configuration W izard.
4.In the first step, choose the Database icon and click Next.
629
Examples
630
5.Then, specify the GSP database. If it doesn't appear in the drop-dow n list, click the New Connection...
button, and specify the path to the MDB file.
630
Examples
631
the configuration file of your project.
631
Examples
632
632
Examples
633
Note that series names (as they will appear in the Legend) w ill correspond to this field's values.
9.Now , adjust a series template w hich is accessed via the chart's ChartControl.SeriesTemplate property.
In particular, it is required to define the data fields w here series obtain information for their point
and
.
So, set the SeriesBase.ArgumentDataMember property to Region, ...
Note that some series view types may require more than one value for each argument (such as Stock or
Bubble series). In such cases, multiple data members should be specified for the SeriesBase.
ValueDataMembers collection.
633
Examples
634
Now, the chart possesses complete information about the data source and its data members. However, it still
doesn't show the real data at design time. To populate your chart with genuine data, click the chart's smart tag
and click Populate.
Populate with Data at Runtime (Optional)
Note that Microsoft Visual Studio automatically adds the following code to the form's Load event, and normally you
don't need to add it manually.
10.To populate a
object with data from the database, the corresponding
's Fill
method can be used. In this example, the chart's
is populated w ith data using the Fill method
of the gSPTableAdapter object. The form's Load event is used to handle data loading.
C#
C opy C ode
C opy C ode
634
Examples
635
See Also
How to: Bind Series to Data and Display Them In Separate Panes (Runtime Sample)
635
Examples
636
How to: Bind a Chart to Data Using Series Templates (Runtime Sample)
Charting > Examples > How to: Bind a Chart to Data Using Series Templates (Runtime Sample)
Show Me
The complete sample project is available in the DevExpress Code Central database at http://w ww .devexpress.com/
example=E3. Depending on the target platform type (ASP.NET, W inForms, etc), you can either run this example
online or dow nload an auto-executable sample.
The follow ing example demonstrates how to bind a chart to data at runtime using series templates. It uses the
same approach as the design-time example, but another data table is generated in this code to simplify the
example. For this example to w ork correctly, don't forget to include all necessary assemblies to the References list
of your project.
C#
C opy C ode
(Form1.cs)
using System;
using System.Data;
using System.Windows.Forms;
using DevExpress.XtraCharts;
// ...
namespace BindUsingTemplatesRuntimeCS {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
private DataTable CreateChartData() {
// Create an empty table.
DataTable table = new DataTable("Table1");
// Add three columns to the table.
table.Columns.Add("Month", typeof(String));
table.Columns.Add("Section", typeof(String));
table.Columns.Add("Value", typeof(Int32));
// Add data rows to the table.
table.Rows.Add(new object[] { "Jan", "Section1", 10 });
table.Rows.Add(new object[] { "Jan", "Section2", 20 });
table.Rows.Add(new object[] { "Feb", "Section1", 20 });
table.Rows.Add(new object[] { "Feb", "Section2", 30 });
table.Rows.Add(new object[] { "March", "Section1", 15 });
table.Rows.Add(new object[] { "March", "Section2", 25 });
return table;
}
private void Form1_Load(object sender, EventArgs e) {
// Create a chart.
ChartControl chart = new ChartControl();
// Generate a data table and bind the chart to it.
chart.DataSource = CreateChartData();
// Specify data members to bind the chart's series template.
chart.SeriesDataMember = "Month";
chart.SeriesTemplate.ArgumentDataMember = "Section";
chart.SeriesTemplate.ValueDataMembers.AddRange(new string[] {"Value"});
// Specify the template's series view.
chart.SeriesTemplate.View = new StackedBarSeriesView();
// Specify the template's name prefix.
chart.SeriesNameTemplate.BeginText = "Month: ";
// Dock the chart into its parent, and add it to the current form.
chart.Dock = DockStyle.Fill;
this.Controls.Add(chart);
}
}
}
636
Examples
Visual Basic
637
C opy C ode
(Form1.vb)
Imports System
Imports System.Data
Imports System.Windows.Forms
Imports DevExpress.XtraCharts
' ...
Public Class Form1
Private Function CreateChartData() As DataTable
' Create an empty table.
Dim Table As New DataTable("Table1")
' Add three columns to the table.
Table.Columns.Add("Month", GetType([String]))
Table.Columns.Add("Section", GetType([String]))
Table.Columns.Add("Value", GetType(Int32))
' Add data rows to the table.
Table.Rows.Add(New Object() {"Jan", "Section1", 10})
Table.Rows.Add(New Object() {"Jan", "Section2", 20})
Table.Rows.Add(New Object() {"Feb", "Section1", 20})
Table.Rows.Add(New Object() {"Feb", "Section2", 30})
Table.Rows.Add(New Object() {"March", "Section1", 15})
Table.Rows.Add(New Object() {"March", "Section2", 25})
Return Table
End Function
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) _
Handles MyBase.Load
' Create a chart.
Dim Chart As New ChartControl()
' Generate a data table and bind the chart to it.
Chart.DataSource = CreateChartData()
' Specify data members to bind the chart's series template.
Chart.SeriesDataMember = "Month"
Chart.SeriesTemplate.ArgumentDataMember = "Section"
Chart.SeriesTemplate.ValueDataMembers.AddRange(New String() {"Value"})
' Specify the template's series view.
Chart.SeriesTemplate.View = New StackedBarSeriesView()
' Specify the template's name prefix.
Chart.SeriesNameTemplate.BeginText = "Month: "
' Dock the chart into its parent, and add it to the current form.
Chart.Dock = DockStyle.Fill
Me.Controls.Add(Chart)
End Sub
End Class
Show Me
The complete sample project is available in the DevExpress Code Central database at http://w ww .devexpress.com/
example=E3. Depending on the target platform type (ASP.NET, W inForms, etc), you can either run this example
online or dow nload an auto-executable sample.
See Also
How to: Bind a Chart to Data Using Series Templates
How to: Bind Series to Data and Display Them In Separate Panes (Runtime Sample)
637
Examples
638
How to: Individually Change the View Type of Automatically Created Series
Charting > Examples > How to: Individually Change the View Type of Automatically Created Series
This example demonstrates how an auto-created series (a series generated automatically based on the series
template settings) can be accessed at runtime, to individually change its view type.
This is performed in a special BoundDataChanged event of the chart control.
C#
C opy C ode
using System;
using System.Data;
using System.Windows.Forms;
using DevExpress.XtraCharts;
// ...
private DataTable CreateChartData() {
// Create an empty table.
DataTable table = new DataTable("Table1");
// Add three columns to the table.
table.Columns.Add("Month", typeof(String));
table.Columns.Add("Section", typeof(String));
table.Columns.Add("Value", typeof(Int32));
// Add data rows to the table.
table.Rows.Add(new object[] { "Jan", "Section1", 10 });
table.Rows.Add(new object[] { "Jan", "Section2", 20 });
table.Rows.Add(new object[] { "Jan", "Section3", 40 });
table.Rows.Add(new object[] { "Feb", "Section1", 20 });
table.Rows.Add(new object[] { "Feb", "Section2", 30 });
table.Rows.Add(new object[] { "Feb", "Section3", 80 });
table.Rows.Add(new object[] { "March", "Section1", 30 });
table.Rows.Add(new object[] { "March", "Section2", 40 });
table.Rows.Add(new object[] { "March", "Section3", 100 });
return table;
}
private void Form1_Load(object sender, EventArgs e) {
// Create a chart.
ChartControl chart = new ChartControl();
// Generate a data table and bind the chart to it.
chart.DataSource = CreateChartData();
// Specify data members to bind the chart's series template.
chart.SeriesDataMember = "Month";
chart.SeriesTemplate.ArgumentDataMember = "Section";
chart.SeriesTemplate.ValueDataMembers.AddRange(new string[] { "Value" });
// Specify the template's series view.
chart.SeriesTemplate.View = new SideBySideBarSeriesView();
// Specify the BoundDataChanged event handler.
chart.BoundDataChanged +=
new BoundDataChangedEventHandler(chart_BoundDataChanged);
// Specify the template's name prefix.
chart.SeriesNameTemplate.BeginText = "Month: ";
// Dock the chart into its parent, and add it to the current form.
chart.Dock = DockStyle.Fill;
this.Controls.Add(chart);
}
private void chart_BoundDataChanged(object sender, EventArgs e) {
ChartControl chart = (ChartControl)sender;
// Change the view of the "Month: Feb" series from
// SideBySideBarSeriesView to LineSeriesView.
Series feb = chart.GetSeriesByName("Month: Feb");
if(feb != null)
feb.ChangeView(ViewType.Line);
// Change the view of the "Month: March" series from
2013 DevExpress Inc.
638
Examples
639
// SideBySideBarSeriesView to SplineSeriesView.
Series march = chart.GetSeriesByName("Month: March");
if(march != null)
march.ChangeView(ViewType.Spline);
}
Visual Basic
C opy C ode
Imports System
Imports System.Data
Imports System.Windows.Forms
Imports DevExpress.XtraCharts
' ...
Private Function CreateChartData() As DataTable
' Create an empty table.
Dim table As New DataTable("Table1")
' Add three columns to the table.
table.Columns.Add("Month", GetType(String))
table.Columns.Add("Section", GetType(String))
table.Columns.Add("Value", GetType(Int32))
' Add data rows to the table.
table.Rows.Add(New Object() { "Jan", "Section1", 10 })
table.Rows.Add(New Object() { "Jan", "Section2", 20 })
table.Rows.Add(New Object() { "Jan", "Section3", 40 })
table.Rows.Add(New Object() { "Feb", "Section1", 20 })
table.Rows.Add(New Object() { "Feb", "Section2", 30 })
table.Rows.Add(New Object() { "Feb", "Section3", 80 })
table.Rows.Add(New Object() { "March", "Section1", 30 })
table.Rows.Add(New Object() { "March", "Section2", 40 })
table.Rows.Add(New Object() { "March", "Section3", 100 })
Return table
End Function
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
' Create a chart.
Dim chart As New ChartControl()
' Generate a data table and bind the chart to it.
chart.DataSource = CreateChartData()
' Specify data members to bind the chart's series template.
chart.SeriesDataMember = "Month"
chart.SeriesTemplate.ArgumentDataMember = "Section"
chart.SeriesTemplate.ValueDataMembers.AddRange(New String() { "Value" })
' Specify the template's series view.
chart.SeriesTemplate.View = New SideBySideBarSeriesView()
' Specify the BoundDataChanged event handler.
AddHandler chart.BoundDataChanged, AddressOf chart_BoundDataChanged
' Specify the template's name prefix.
chart.SeriesNameTemplate.BeginText = "Month: "
' Dock the chart into its parent, and add it to the current form.
chart.Dock = DockStyle.Fill
Me.Controls.Add(chart)
End Sub
Private Sub chart_BoundDataChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim chart As ChartControl = CType(sender, ChartControl)
' Change the view of the "Month: Feb" series from
' SideBySideBarSeriesView to LineSeriesView.
Dim feb As Series = chart.GetSeriesByName("Month: Feb")
If feb IsNot Nothing Then
feb.ChangeView(ViewType.Line)
End If
' Change the view of the "Month: March" series from
' SideBySideBarSeriesView to SplineSeriesView.
Dim march As Series = chart.GetSeriesByName("Month: March")
2013 DevExpress Inc.
639
Examples
640
Show Me
The complete sample project is available in the DevExpress Code Central database at http://w ww .devexpress.com/
example=E1518. Depending on the target platform type (ASP.NET, W inForms, etc), you can either run this example
online or dow nload an auto-executable sample.
See Also
Series View s
How to: Change the View of a Series
640
Examples
641
C opy C ode
using System;
using System.Drawing;
using System.Windows.Forms;
using DevExpress.XtraCharts;
// ...
private void chartControl1_BoundDataChanged(object sender, EventArgs e) {
for(int i = 0; i < chartControl1.Series.Count; i++) {
BarSeriesView view = (BarSeriesView)chartControl1.Series[i].View;
view.Color = Color.Blue;
view.FillStyle.FillMode = FillMode.Gradient;
((GradientFillOptionsBase)view.FillStyle.Options).Color2 = Color.Beige;
}
}
Visual Basic
Imports
Imports
Imports
Imports
' ...
Private
Handles
For
C opy C ode
System
System.Drawing
System.Windows.Forms
DevExpress.XtraCharts
641
Examples
642
How to: Bind Series to Data and Display Them In Separate Panes (Runtime Sa
Charting > Examples > How to: Bind Series to Data and Display Them In Separate Panes (Runtime Sample)
This example demonstrates how to display a chart's series in separate panes.
For this example to work correctly, do the follow ing.
1.Start MS Visual Studio (2008 or 2010), and create a new Windows Forms Application, or open an
existing one.
2.Include all necessary assemblies to the References list of your project.
3.Open the Solution Explorer window (e.g. by pressing CTRL+ALT+L), right-click the
WindowsApplication1 item and in the invoked menu, point to Add and click Existing Item.... Then,
locate the gsp.mdb file (it is shipped with XtraCharts suite and located in the directory, w here you
installed DevExpress demos) and click Add. In the displayed dialog, select the GSP table of this
database.
A dataset (named gspDataSet) is automatically created after performing the above steps.
4.Drop a button onto the form and add the following code to the Button1.Click event handler.
C#
C opy C ode
using System;
using System.Drawing;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraCharts;
using gspDataSetTableAdapters;
// ...
private void button1_Click(object sender, EventArgs e) {
// Create and customize a form.
XtraForm form = new XtraForm();
form.Text = "Multiple Panes";
form.Size = new Size(800, 600);
// Create a chart.
ChartControl chart = new ChartControl();
// Initialize a dataset and fill the data adapter.
gspDataSet dataSet = new gspDataSet();
GSPTableAdapter dataAdapter = new GSPTableAdapter();
dataAdapter.Fill(dataSet.GSP);
// Define the chart's datasource.
chart.DataSource = dataSet.GSP;
// Create a series. Define its data member and create a data filter, to display a required year.
Series series1 = new Series();
series1.Name = "2003";
series1.ArgumentDataMember = "Region";
series1.ValueDataMembers[0] = "GSP";
series1.DataFilters.Add(new DataFilter("Year", "System.Int32",
DataFilterCondition.Equal, 2003));
// Create a second series in a similar manner.
Series series2 = new Series();
series2.Name = "2004";
series2.ArgumentDataMember = "Region";
series2.ValueDataMembers[0] = "GSP";
series2.DataFilters.Add(new DataFilter("Year", "System.Int32",
DataFilterCondition.Equal, 2004));
// Add both series to the chart's collection.
chart.Series.Add(series1);
chart.Series.Add(series2);
// Initialize a chart's diagram.
XYDiagram diagram = (XYDiagram)chart.Diagram;
// Create a new pane.
XYDiagramPane secondPane = new XYDiagramPane("The Pane's Name");
642
Examples
643
C opy C ode
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports DevExpress.XtraEditors
Imports DevExpress.XtraCharts
Imports gspDataSetTableAdapters
' ...
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) _
Handles button1.Click
' Create and customize a form.
Dim form As XtraForm = New XtraForm()
form.Text = "Multiple Panes"
form.Size = New Size(800, 600)
' Create a chart.
Dim chart As ChartControl = New ChartControl()
' Initialize a dataset and fill the data adapter.
Dim dataSet As gspDataSet = New gspDataSet()
Dim dataAdapter As GSPTableAdapter = New GSPTableAdapter()
dataAdapter.Fill(dataSet.GSP)
' Define the chart's datasource.
chart.DataSource = dataSet.GSP
' Create a series. Define its data member and create a data filter, to display a required year.
Dim series1 As Series = New Series()
series1.Name = "2003"
series1.ArgumentDataMember = "Region"
series1.ValueDataMembers(0) = "GSP"
series1.DataFilters.Add(New DataFilter("Year", "System.Int32", _
DataFilterCondition.Equal, 2003))
' Create a second series in a similar manner.
Dim series2 As Series = New Series()
series2.Name = "2004"
series2.ArgumentDataMember = "Region"
series2.ValueDataMembers(0) = "GSP"
series2.DataFilters.Add(New DataFilter("Year", "System.Int32", _
DataFilterCondition.Equal, 2004))
' Add both series to the chart's collection.
chart.Series.Add(series1)
chart.Series.Add(series2)
' Initialize a chart's diagram.
Dim diagram As XYDiagram = CType(chart.Diagram, XYDiagram)
' Create a new pane.
Dim secondPane As XYDiagramPane = New XYDiagramPane("The Pane's Name")
' Add the pane to the diagram's collection.
diagram.Panes.Add(secondPane)
CType(series2.View, XYDiagramSeriesViewBase).Pane = secondPane
' Add the chart to the form and fit it to the parent form's size.
chart.Dock = DockStyle.Fill
form.Controls.Add(chart)
' Display the form containing the chart.
form.Show()
2013 DevExpress Inc.
643
Examples
644
End Sub
Show Me
The complete sample project is available in the DevExpress Code Central database at http://w ww .devexpress.com/
example=E431. Depending on the target platform type (ASP.NET, WinForms, etc), you can either run this example
online or dow nload an auto-executable sample.
See Also
Panes
644
Examples
645
C opy C ode
using System;
using System.Data;
using System.Data.OleDb;
using System.Windows.Forms;
using DevExpress.XtraCharts;
// ...
private void Form1_Load(object sender, EventArgs e) {
// Create an empty chart.
ChartControl chart = new ChartControl();
// Create data objects.
OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * FROM GSP",
@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\..\gsp.mdb");
DataSet ds = new DataSet();
//adapter.FillSchema(ds, SchemaType.Source);
adapter.Fill(ds);
// Bind the chart to data.
chart.DataSource = ds;
chart.DataAdapter = adapter;
// Specify data members to bind the chart's series template.
chart.SeriesDataMember = "Table.Year";
chart.SeriesTemplate.ArgumentDataMember = "Table.Region";
chart.SeriesTemplate.ValueDataMembers.AddRange(new string[] { "Table.GSP" });
// Specify the template's series view.
chart.SeriesTemplate.View = new StackedBarSeriesView();
// Dock the chart into its parent, and add it to the current form.
chart.Dock = DockStyle.Fill;
this.Controls.Add(chart);
}
Visual Basic
C opy C ode
Imports System
Imports System.Data
Imports System.Data.OleDb
Imports System.Windows.Forms
Imports DevExpress.XtraCharts
' ...
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) _
Handles MyBase.Load
' Create an empty chart.
Dim chart As New ChartControl()
' Create data objects.
Dim adapter As New OleDbDataAdapter("SELECT * FROM GSP", _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\..\gsp.mdb")
Dim ds As New DataSet()
'adapter.FillSchema(ds, SchemaType.Source);
adapter.Fill(ds)
' Bind the chart to data.
chart.DataSource = ds
chart.DataAdapter = adapter
' Specify data members to bind the chart's series template.
chart.SeriesDataMember = "Table.Year"
chart.SeriesTemplate.ArgumentDataMember = "Table.Region"
chart.SeriesTemplate.ValueDataMembers.AddRange(New String() { "Table.GSP" })
' Specify the template's series view.
2013 DevExpress Inc.
645
Examples
646
646
Examples
647
C opy C ode
C opy C ode
647
Examples
648
End Get
Set(ByVal Value As String)
_name = Value
End Set
End Property
Public Property Age() As Integer
Get
Return _age
End Get
Set(ByVal Value As Integer)
_age = Value
End Set
End Property
End Class
4.Once the record class has been declared, the data source object can be filled with records. This example
will use an ArrayList as the report's data source. So, there is no need to create a custom object
implementing the IList, ITypedList or IBindingList interfaces.
The code below fills the ArrayList with records and assigns it to the chart's ChartControl.DataSource
property. Then, you can adjust the SeriesBase.ArgumentDataMember and SeriesBase.
ValueDataMembers properties of the chart's series.
C#
C opy C ode
C opy C ode
648
Examples
649
' Adjust the series data members.
series1.ArgumentDataMember = "name"
series1.ValueDataMembers.AddRange(New String() { "age" })
' Access the view-type-specific options of the series.
CType(series1.View, BarSeriesView).ColorEach = True
series1.LegendPointOptions.Pattern = "{A}"
End Sub
Now, the chart has been bound to data. Run the application, and view the result.
See Also
How to: Bind a Chart to Data Using Series Templates (Runtime Sample)
649
Examples
650
C opy C ode
using System;
using System.Data;
using System.Windows.Forms;
using DevExpress.XtraCharts;
// ...
private void Form1_Load(object sender, EventArgs e) {
// Create a DataSet instance and, make it read the xml file.
DataSet ds = new DataSet();
ds.ReadXml(@"..\..\Departments.xml");
// Specify the dataset as the chart's data source.
chartControl1.DataSource = ds;
// Specify the argument and value data members for the series.
chartControl1.Series[0].ArgumentDataMember = "Table.Department";
chartControl1.Series[0].ValueDataMembers.AddRange(new string[] { "Table.Budget" });
// Define an appropriate scale type for the series points' values.
chartControl1.Series[0].ValueScaleType = ScaleType.Numerical;
}
Visual Basic
C opy C ode
Imports System
Imports System.Data
Imports System.Windows.Forms
Imports DevExpress.XtraCharts
' ...
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) _
Handles MyBase.Load
' Create a DataSet instance and, make it read the xml file.
Dim ds As New DataSet()
ds.ReadXml("..\..\Departments.xml")
' Specify the dataset as the chart's data source.
chartControl1.DataSource = ds
' Specify the argument and value data members for the series.
chartControl1.Series(0).ArgumentDataMember = "Table.Department"
chartControl1.Series(0).ValueDataMembers.AddRange(New String() { "Table.Budget" })
' Define an appropriate scale type for the series points' values.
chartControl1.Series(0).ValueScaleType = ScaleType.Numerical
End Sub
The result is show n in the following image.
650
Examples
651
Show Me
The complete sample project is available in the DevExpress Code Central database at http://w ww .devexpress.com/
example=E1583. Depending on the target platform type (ASP.NET, W inForms, etc), you can either run this example
online or dow nload an auto-executable sample.
651
Examples
652
4.Now , sw itch from the design view of the form to its code, and declare the XPObject class descendant.
For example, use the following code.
C#
C opy C ode
using DevExpress.Xpo;
// ...
public class SeriesRecord : XPObject {
public string Argument;
public int Value;
}
Visual Basic
C opy C ode
Imports DevExpress.Xpo
652
Examples
653
' ...
Public Class SeriesRecord
Inherits XPObject
Public Argument As String
Public Value As Integer
End Class
5.To populate the data source, handle the Form1_Load event using the follow ing code.
C#
C opy C ode
C opy C ode
And, define w here the chart's series should obtain data for its points' arguments and their values, set
the SeriesBase.ArgumentDataMember property to Argument, and the SeriesBase.ValueDataMembers
property to Value.
653
Examples
654
The chart is now bound to the XPO data source, and the result is show n in the following image.
Show Me
The complete sample project is available in the DevExpress Code Central database at http://w ww .devexpress.com/
example=E1576. Depending on the target platform type (ASP.NET, W inForms, etc), you can either run this example
online or dow nload an auto-executable sample.
654
Examples
655
4.At this time, all the chart's binding and layout settings are adjusted automatically, and you can launch
the application, yielding the following result.
655
Examples
656
5.To exclude the column grand totals from the chart, set the corresponding option in the chart's
ChartControl.PivotGridDataSourceOptions.
656
Examples
657
As a result, a user can choose the required rows in the Pivot Grid, to see only the actual cell values.
657
Examples
658
6.If this result is not satisfactory, adjustments to the automatic options can be made (e.g. disable the
AxisLabel.Staggered property of axis labels, and change the series view type to Line).
To so this, handle the corresponding events as the follow ing code demonstrates.
C#
C opy C ode
using DevExpress.XtraCharts;
// ...
private void chartControl1_CustomizeXAxisLabels(object sender, CustomizeXAxisLabelsEventArgs e
e.Staggered = false;
}
private void chartControl1_BoundDataChanged(object sender, EventArgs e) {
((ChartControl)sender).SeriesTemplate.ChangeView(ViewType.Line);
}
Visual Basic
C opy C ode
Imports DevExpress.XtraCharts
' ...
Private Sub chartControl1_CustomizeXAxisLabels(ByVal sender As Object, _
ByVal e As CustomizeXAxisLabelsEventArgs) Handles chartControl1.CustomizeXAxisLabels
e.Staggered = False
End Sub
Private Sub chartControl1_BoundDataChanged(ByVal sender As Object, _
ByVal e As EventArgs) Handles chartControl1.BoundDataChanged
CType(sender, ChartControl).SeriesTemplate.ChangeView(ViewType.Line)
658
Examples
659
End Sub
The result (w ith the point labels completely hidden) is shown in the follow ing image.
For the complete list of the automatic settings, as well as the event handlers where they can be
adjusted, see Pivot Charting (Integration with a Pivot Grid Control).
See Also
Pivot Charting (Integration w ith a Pivot Grid Control)
Pivot Charting on the W eb (Integration with the ASPxPivotGrid)
659
Examples
660
C opy C ode
using System;
using System.Windows.Forms;
using DevExpress.XtraCharts;
// ...
namespace WindowsApplication1 {
public partial class Form1 : Form {
// Declare the Product summary function.
private static SeriesPoint[] CalcProductValue(Series series, object argument,
string[] functionArguments, DataSourceValues[] values) {
// Create an array of the resulting series points.
SeriesPoint[] points = new SeriesPoint[values.Length];
// Calculate the resulting series points as Price * Count.
for (int i = 0; i < values.Length; i++)
points[i] = new SeriesPoint(argument,
Convert.ToDouble(values[i][functionArguments[0]]) *
Convert.ToDouble(values[i][functionArguments[1]]));
// Return the result.
return points;
}
public Form1() {
InitializeComponent();
// Create argument descriptions for the summary function.
SummaryFunctionArgumentDescription argument1Description =
new SummaryFunctionArgumentDescription("Price", ScaleType.Numerical);
SummaryFunctionArgumentDescription argument2Description =
new SummaryFunctionArgumentDescription("Count", ScaleType.Numerical);
// Register the summary function in a chart.
chartControl1.RegisterSummaryFunction("PRODUCT", "PRODUCT", 1,
new SummaryFunctionArgumentDescription[] {
argument1Description, argument2Description },
CalcProductValue);
// Provide a datasource for the chart.
chartControl1.DataSource = nwindDataSet.Products;
}
private void Form1_Load(object sender, EventArgs e) {
// This line of code loads data into the 'nwindDataSet.Products' table.
this.productsTableAdapter.Fill(this.nwindDataSet.Products);
}
}
}
Visual Basic
C opy C ode
Imports System
Imports System.Windows.Forms
Imports DevExpress.XtraCharts
660
Examples
661
' ...
Public Class Form1
' Declare the Product summary function.
Private Shared Function CalcProductValue(ByVal series As Series, _
ByVal argument As Object, ByVal functionArguments() As String, _
ByVal values() As DataSourceValues) As SeriesPoint()
' Create an array of the resulting series points.
Dim points(values.Length - 1) As SeriesPoint
' Calculate the resulting series points as Price * Count.
For i As Integer = 0 To values.Length - 1
points(i) = New SeriesPoint(argument, _
Convert.ToDouble(values(i)(functionArguments(0))) * _
Convert.ToDouble(values(i)(functionArguments(1))))
Next i
' Return the result.
Return points
End Function
Public Sub New()
InitializeComponent()
' Create argument descriptions for the summary function.
Dim argument1Description As New SummaryFunctionArgumentDescription("Price", _
ScaleType.Numerical)
Dim argument2Description As New SummaryFunctionArgumentDescription("Count", _
ScaleType.Numerical)
' Register the summary function in a chart.
ChartControl1.RegisterSummaryFunction("PRODUCT", "PRODUCT", 1, _
New SummaryFunctionArgumentDescription() {argument1Description, _
argument2Description}, AddressOf CalcProductValue)
' Provide a datasource for the chart.
ChartControl1.DataSource = ProductsBindingSource
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
' This line of code loads data into the 'NwindDataSet.Products' table.
Me.ProductsTableAdapter.Fill(Me.NwindDataSet.Products)
End Sub
End Class
Show Me
The complete sample project is available in the DevExpress Code Central database at http://w ww .devexpress.com/
example=E368. Depending on the target platform type (ASP.NET, WinForms, etc), you can either run this example
online or dow nload an auto-executable sample.
See Also
Calculating Summaries
661
Examples
662
Data Representation
How to: Change the Display Format for Series Labels
Charting > Examples > How to: Change the Display Format for Series Labels
This tutorial demonstrates how to change the display format of series labels of a Pie chart at design time, to show
both arguments and values (as real values, as opposed to percents).
To change the display format of series labels for the Pie chart, do the follow ing.
1.Create a simple unbound chart of the PieSeriesView type. Or, for an existing chart, change the view of
its series to Pie. The following image demonstrates the points added to the series in this example (for
more information, refer to Manually Add Points to a Series).
2.After this step, the Pie chart has the following look (w ith its legend hidden).
The following steps demonstrate how to customize the display format of its series labels.
3.By default, a Pie series labels display their points' values as percents. To make them display real values,
do the follow ing.
Click the Pie series in the ChartControl, to select it. In the Properties window , expand its SeriesBase.
PointOptions property. Then, expand the SimplePointOptions.PercentOptions property, to access the
PercentOptions.ValueAsPercent property and disable it.
662
Examples
663
4.To display both arguments and values in series labels, in the SeriesBase.PointOptions property, locate
the PointOptions.PointView property, and set it to ArgumentAndValuess.
5.Finally, w e'll apply the currency format to the points' values. To do this, expand the PointOptions.
ValueNumericOptions property, and set its NumericOptions.Format property to Currency. To disable
decimals, we will set the NumericOptions.Precision property - to 0.
In addition, you can perform similar operations with regard to the Pie chart's legend, e.g. to make it display values
2013 DevExpress Inc.
663
Examples
664
in percentages, and show their arguments, too. To learn how to do this, refer to How to: Show Values as
Percents in the Legend of a Pie Chart.
See Also
Series Point Labels
664
Examples
665
However, the approach shown here can also be applied to a data-bound chart.
To change the display format of the date-time values for axis labels, do the following.
1.Since it's critical to use the DateTime argument's scale type, first ensure that the scale type for the
series argument is set correctly. To do this, select the series, and in the Properties w indow, locate the
SeriesBase.ArgumentScaleType property. If it's set to Qualitative (the default value), change it to
DateTime. Otherwise, the date-time options will not become available.
2.Then, select the axis of arguments (X-axis), and in the Properties window , set the AxisBase.
DateTimeMeasureUnit property to Month. After this, the AxisBase.DateTimeGridAlignment property will
be automatically set to Month, too.
665
Examples
666
3.Now , expand the AxisBase.DateTimeOptions property. Via the DateTimeOptions.Format property, you
can either define one of the built-in formats for the axis labels, or set this property to Custom, to apply
another format. In this example, we use a custom format, and then set the DateTimeOptions.
FormatString property to MMMM, to display the full names of months, only.
See Also
How to: Change the Display Format for Axis Labels (Runtime Sample)
How to: Exclude Weekends and Holidays from the Axis Scale
Axis Scale Types
Axis Labels
666
Examples
667
How to: Change the Display Format for Axis Labels (Runtime Sample)
Charting > Examples > How to: Change the Display Format for Axis Labels (Runtime Sample)
This example demonstrates how you can customize the numerical and date-time options of an axis.
C#
C opy C ode
using System;
using System.Windows.Forms;
using DevExpress.XtraCharts;
// ...
private void Form1_Load(object sender, EventArgs e) {
// Create an empty chart.
ChartControl chartControl1 = new ChartControl();
// Create a bar series and add points to it.
Series series1 = new Series("Series 1", ViewType.Bar);
series1.Points.Add(new SeriesPoint(new DateTime(2009, 1, 1), new double[] { 26.25
series1.Points.Add(new SeriesPoint(new DateTime(2009, 2, 1), new double[] { 16.52
series1.Points.Add(new SeriesPoint(new DateTime(2009, 3, 1), new double[] { 22.21
series1.Points.Add(new SeriesPoint(new DateTime(2009, 4, 1), new double[] { 15.35
series1.Points.Add(new SeriesPoint(new DateTime(2009, 5, 1), new double[] { 24.15
// Add the series to the chart.
chartControl1.Series.Add(series1);
// Hide the legend (if necessary).
chartControl1.Legend.Visible = false;
// Set the scale type for the series' arguments and values.
series1.ArgumentScaleType = ScaleType.DateTime;
series1.ValueScaleType = ScaleType.Numerical;
// Cast the chart's diagram to the XYDiagram type, to access its axes.
XYDiagram diagram = (XYDiagram)chartControl1.Diagram;
// Define the date-time measurement unit, to which the beginning of
// a diagram's gridlines and labels should be aligned.
diagram.AxisX.DateTimeGridAlignment = DateTimeMeasurementUnit.Day;
// Define the detail level for date-time values.
diagram.AxisX.DateTimeMeasureUnit = DateTimeMeasurementUnit.Month;
// Define the custom date-time format (name of a month) for the axis labels.
diagram.AxisX.DateTimeOptions.Format = DateTimeFormat.Custom;
diagram.AxisX.DateTimeOptions.FormatString = "MMMM";
// Since the ValueScaleType of the chart's series is Numerical,
// it is possible to customize the NumericOptions of Y-axis.
diagram.AxisY.NumericOptions.Format = NumericFormat.Currency;
diagram.AxisY.NumericOptions.Precision = 1;
// Add the chart to the form.
chartControl1.Dock = DockStyle.Fill;
this.Controls.Add(chartControl1);
}
}));
}));
}));
}));
}));
Visual Basic
Imports System
Imports System.Windows.Forms
Imports DevExpress.XtraCharts
' ...
Private Sub Form1_Load(ByVal sender As Object, ByVal e As
' Create an empty chart.
Dim chartControl1 As New ChartControl()
' Create a bar series and add points to it.
Dim series1 As New Series("Series 1", ViewType.Bar)
series1.Points.Add(New SeriesPoint(New DateTime(2009,
series1.Points.Add(New SeriesPoint(New DateTime(2009,
series1.Points.Add(New SeriesPoint(New DateTime(2009,
series1.Points.Add(New SeriesPoint(New DateTime(2009,
2013 DevExpress Inc.
C opy C ode
1,
2,
3,
4,
1),
1),
1),
1),
New
New
New
New
Double()
Double()
Double()
Double()
{
{
{
{
26.25
16.52
22.21
15.35
}))
}))
}))
}))
667
Examples
668
Show Me
The complete sample project is available in the DevExpress Code Central database at http://w ww .devexpress.com/
example=E1361. Depending on the target platform type (ASP.NET, W inForms, etc), you can either run this example
online or dow nload an auto-executable sample.
See Also
How to: Change the Display Format for Axis Labels
Axis Labels
Axis Scale Types
668
Examples
669
669
Examples
670
In addition, it's possible to define the accuracy of the percentage values (via the PercentOptions.
PercentageAccuracy property), and the number of decimal places (via the NumericOptions.Precision
property).
The result is show n in the following image.
See Also
Legend Overview
How to: Change the Display Format for Series Labels
670
Examples
671
C opy C ode
using DevExpress.XtraCharts;
// ...
// Create new data filters and specify conditions for them.
DataFilter dataFilter1 = new DataFilter("CategoryID", "System.Int32", DataFilterCondition.Equal, 1);
DataFilter dataFilter2 = new DataFilter("CategoryID", "System.Int32", DataFilterCondition.Equal, 4);
DataFilter dataFilter3 = new DataFilter("CategoryID", "System.Int32", DataFilterCondition.Equal, 7);
// Obtain the first series of the chart.
Series series1 = chartControl1.Series[0];
// Set the logical operator used to combine individual data filter conditions for this series.
series1.DataFiltersConjunctionMode = ConjunctionTypes.Or;
// Remove all other filters.
series1.DataFilters.Clear();
// Add new filters to apply to the series data.
series1.DataFilters.AddRange(new DataFilter[] {dataFilter1, dataFilter2, dataFilter3});
Visual Basic
C opy C ode
Imports DevExpress.XtraCharts
' ...
' Create new data filters and specify conditions for them.
Dim dataFilter1 As New DataFilter("CategoryID", "System.Int32", DataFilterCondition.Equal, 1)
Dim dataFilter2 As New DataFilter("CategoryID", "System.Int32", DataFilterCondition.Equal, 4)
Dim dataFilter3 As New DataFilter("CategoryID", "System.Int32", DataFilterCondition.Equal, 7)
' Obtain the first series of the chart.
Dim series1 As Series = chartControl1.Series(0)
' Set the logical operator used to combine individual data filter conditions for this series.
series1.DataFiltersConjunctionMode = ConjunctionTypes.Or
' Remove all other filters.
series1.DataFilters.Clear()
' Add new filters to apply to the series data.
series1.DataFilters.AddRange(New DataFilter() {dataFilter1, dataFilter2, dataFilter3})
See Also
Filtering Data
671
Examples
672
The following steps demonstrate how to aggregate some of the Pie series points into a single slice.
2.Select the Pie series, and in the Properties w indow, expand its SeriesBase.TopNOptions property. Then,
set the TopNOptions.Enabled property to true.
3.Now , the available options are visible. They are briefly described below.
The key option is the TopNOptions.Mode property, w hich allows you to choose from three different
modes in which the TopN feature can be implemented:
Count
This setting determines that the defined
of series points should be aggregated into the single
slice.
After you set the TopNOptions.Mode property to Count, define the number of series points
, via the TopNOptions.Count property. The result is shown in the follow ing image.
672
Examples
673
ThresholdValue
This setting determines that series points are aggregated into a single slice, if their
, determined by the TopNOptions.ThresholdValue property.
ThresholdPercent
This setting determines that series points are aggregated into a single slice, if their
, relative to the series points' overall value. The TopNOptions.
ThresholdPercent property determines the threshold percent.
Note
You can completely exclude the aggregated points from the chart, by disabling the TopNOptions.Show Others
property.
To customize the text of the argument, which is shown instead of the real points' arguments, use the
TopNOptions.OthersArgument property. The follow ing images demonstrate how this property w orks.
OthersArgument isn't defined (default)
OthersArgument = "Rest"
673
Examples
674
See Also
Using The Top-N Feature
How to: Explode Points of a Pie Chart
674
Examples
675
C opy C ode
using System;
using System.Windows.Forms;
using DevExpress.XtraCharts;
// ...
private void Form1_Load(object sender, EventArgs e) {
this.comboBox1.SelectedIndex = 0;
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) {
switch (comboBox1.SelectedIndex) {
case 0:
((XYDiagram)this.chartControl1.Diagram).AxisX.DateTimeScaleMode =
DateTimeScaleMode.Manual;
((XYDiagram)this.chartControl1.Diagram).AxisX.DateTimeMeasureUnit =
DateTimeMeasurementUnit.Day;
((XYDiagram)this.chartControl1.Diagram).AxisX.DateTimeGridAlignment =
DateTimeMeasurementUnit.Day;
break;
case 1:
((XYDiagram)this.chartControl1.Diagram).AxisX.DateTimeScaleMode =
DateTimeScaleMode.AutomaticAverage;
break;
case 2:
((XYDiagram)this.chartControl1.Diagram).AxisX.DateTimeScaleMode =
DateTimeScaleMode.AutomaticIntegral;
break;
}
}
Visual Basic
C opy C ode
Imports System
Imports System.Windows.Forms
Imports DevExpress.XtraCharts
' ...
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
Me.comboBox1.SelectedIndex = 0
End Sub
Private Sub comboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) _
Handles comboBox1.SelectedIndexChanged
Select Case comboBox1.SelectedIndex
Case 0
CType(Me.chartControl1.Diagram, XYDiagram).AxisX.DateTimeScaleMode = _
DateTimeScaleMode.Manual
CType(Me.chartControl1.Diagram, XYDiagram).AxisX.DateTimeMeasureUnit = _
2013 DevExpress Inc.
675
Examples
676
DateTimeMeasurementUnit.Day
CType(Me.chartControl1.Diagram, XYDiagram).AxisX.DateTimeGridAlignment = _
DateTimeMeasurementUnit.Day
Case 1
CType(Me.chartControl1.Diagram, XYDiagram).AxisX.DateTimeScaleMode = _
DateTimeScaleMode.AutomaticAverage
Case 2
CType(Me.chartControl1.Diagram, XYDiagram).AxisX.DateTimeScaleMode = _
DateTimeScaleMode.AutomaticIntegral
End Select
End Sub
Show Me
The complete sample project is available in the DevExpress Code Central database at http://w ww .devexpress.com/
example=E1531. Depending on the target platform type (ASP.NET, W inForms, etc), you can either run this example
online or dow nload an auto-executable sample.
See Also
Date-Time Data Representation
How to: Exclude Weekends and Holidays from the Axis Scale
How to: Obtain Values Calculated for Automatic Axis Date-Time Scale Modes
676
Examples
677
How to: Obtain Values Calculated for Automatic Axis Date-Time Scale Modes
Charting > Examples > How to: Obtain Values Calculated for Automatic Axis Date-Time Scale Modes
This example demonstrates how you can obtain the values calculated for an axis' date-time grid alignment and
measure unit properties w hich are read-only, w hen automatic axis date-time scale modes are used. Moreover, in
the ChartControl.DateTimeMeasurementUnitsCalculated (W ebChartControl.DateTimeMeasurementUnitsCalculated
) event, you can access the axis itself, and customize its properties.
C#
C opy C ode
using DevExpress.XtraCharts;
// ...
private void chartControl1_DateTimeMeasurementUnitsCalculated
(object sender, DateTimeMeasurementUnitsCalculatedEventArgs e) {
// In this event, you can access the properties of the corresponding axis,
// and obtain the automatically calculated value
// for the axis date-time grid alignment and measure unit.
((AxisX)e.Axis).Title.Visible = true;
((AxisX)e.Axis).Title.Text = "The Axis Grid Alignment Unit is " + e.GridAlignment.ToString() +
"\r\nThe Axis Measure Unit is " + e.MeasureUnit.ToString();
}
Visual Basic
C opy C ode
Imports DevExpress.XtraCharts
' ...
Private Sub chartControl1_DateTimeMeasurementUnitsCalculated(ByVal sender As Object, _
ByVal e As DateTimeMeasurementUnitsCalculatedEventArgs) _
Handles chartControl1.DateTimeMeasurementUnitsCalculated
' In this event, you can access the properties of the corresponding axis,
' and obtain the automatically calculated value
' for the axis date-time grid alignment and measure unit.
CType(e.Axis, AxisX).Title.Visible = True
CType(e.Axis, AxisX).Title.Text = _
"The Axis Grid Alignment Unit is " & e.GridAlignment.ToString() & _
Constants.vbCrLf & "The Axis Measure Unit is " & e.MeasureUnit.ToString()
End Sub
The result is show n in the following image.
Show Me
The complete sample project is available in the DevExpress Code Central database at http://w ww .devexpress.com/
example=E1529. Depending on the target platform type (ASP.NET, W inForms, etc), you can either run this example
online or dow nload an auto-executable sample.
677
Examples
678
See Also
Date-Time Data Representation
How to: Use Automatic Date-Time Scale Modes of an Axis
How to: Exclude Weekends and Holidays from the Axis Scale
678
Examples
679
How to: Exclude Weekends and Holidays from the Axis Scale
Charting > Examples > How to: Exclude W eekends and Holidays from the Axis Scale
Show Me
The complete sample project is available in the DevExpress Code Central database at http://w ww .devexpress.com/
example=E2365. Depending on the target platform type (ASP.NET, W inForms, etc), you can either run this example
online or dow nload an auto-executable sample.
This example demonstates how to exclude non-working days (weekdays and holidays) from an axis range, via
the AxisBase.W orkdaysOnly and AxisBase.WorkdaysOptions properties.
C#
C opy C ode
(Form1.cs)
using System;
using System.Windows.Forms;
using DevExpress.XtraCharts;
// ...
AxisX axisX = ((XYDiagram)chartControl1.Diagram).AxisX;
// Exclude holidays from the axis scale.
axisX.WorkdaysOnly = true;
// Specify custom working days.
axisX.WorkdaysOptions.Workdays = Weekday.Sunday | Weekday.Monday | Weekday.Tuesday |
Weekday.Wednesday | Weekday.Thursday | Weekday.Friday;
// Specify holidays
axisX.WorkdaysOptions.Holidays.AddRange(new KnownDate[] {
new KnownDate("Custom Holiday 1", new DateTime(1994, 3, 2, 0, 0, 0, 0)),
new KnownDate("Custom Holiday 2", new DateTime(1994, 4, 2, 0, 0, 0, 0))});
// Specify strict working days.
// Thay will have a priority over the holidays specified.
axisX.WorkdaysOptions.ExactWorkdays.Add(
new KnownDate("Community Work Day", new DateTime(1994, 3, 2, 0, 0, 0, 0)));
Visual Basic
C opy C ode
(Form1.vb)
Imports System
Imports System.Windows.Forms
Imports DevExpress.XtraCharts
' ...
Dim axisX As AxisX = (CType(chartControl1.Diagram, XYDiagram)).AxisX
' Exclude holidays from the axis scale.
axisX.WorkdaysOnly = True
' Specify custom working days.
axisX.WorkdaysOptions.Workdays = Weekday.Sunday Or Weekday.Monday Or _
Weekday.Tuesday Or Weekday.Wednesday Or Weekday.Thursday Or Weekday.Friday
' Specify holidays
axisX.WorkdaysOptions.Holidays.AddRange(New KnownDate() { _
New KnownDate("Custom Holiday 1", New DateTime(1994, 3, 2, 0, 0, 0, 0)), _
New KnownDate("Custom Holiday 2", New DateTime(1994, 4, 2, 0, 0, 0, 0))})
' Specify strict working days.
' Thay will have a priority over the holidays specified.
axisX.WorkdaysOptions.ExactWorkdays.Add(New KnownDate _
("Community Work Day", New DateTime(1994, 3, 2, 0, 0, 0, 0)))
The follow ing images demonstrate a chart with non-working days excluded, and included.
WorkdaysOnly = false
WorkdaysOnly = true
679
Examples
680
See Also
Date-Time Data Representation
How to: Change the Display Format for Axis Labels
How to: Use Automatic Date-Time Scale Modes of an Axis
How to: Obtain Values Calculated for Automatic Axis Date-Time Scale Modes
680
Examples
681
How to: Adjust Point Options of the Pie Series View Type at Runtime
Charting > Examples > How to: Adjust Point Options of the Pie Series View Type at Runtime
Show Me
The complete sample project is available in the DevExpress Code Central database at http://w ww .devexpress.com/
example=E3801. Depending on the target platform type (ASP.NET, W inForms, etc), you can either run this example
online or dow nload an auto-executable sample.
The follow ing example demonstrates how to specify the appearance of series labels in the Pie chart using its point
options.
To accomplish this at runtime, it is necessary to handle the Form.Load event and then transform series labels of
the Series object to the corresponding labels of the PieSeriesLabel object.
And finally, get access to the point view and point value numeric options via the PointOptions.PointView and
PointOptions.ValueNumericOptions properties correspondingly.
C#
C opy C ode
(Form1.cs)
using System;
using System.Windows.Forms;
using DevExpress.XtraCharts;
namespace XtraChart_PointOptions
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// Create an empty chart.
ChartControl pieChart = new ChartControl();
// Create a pie series.
Series series1 = new Series("A Pie Series", ViewType.Pie);
// Populate the series with points.
series1.Points.Add(new SeriesPoint("Russia", 17.0752));
series1.Points.Add(new SeriesPoint("Canada", 9.98467));
series1.Points.Add(new SeriesPoint("USA", 9.63142));
series1.Points.Add(new SeriesPoint("China", 9.59696));
series1.Points.Add(new SeriesPoint("Brazil", 8.511965));
series1.Points.Add(new SeriesPoint("Australia", 7.68685));
series1.Points.Add(new SeriesPoint("India", 3.28759));
series1.Points.Add(new SeriesPoint("Others", 81.2));
// Add the series to the chart.
pieChart.Series.Add(series1);
// Adjust the point options of the series label.
PieSeriesLabel label = (PieSeriesLabel)series1.Label;
label.PointOptions.PointView = PointView.ArgumentAndValues;
label.PointOptions.ValueNumericOptions.Format = NumericFormat.Percent;
label.PointOptions.ValueNumericOptions.Precision = 0;
// Detect overlapping of series labels.
label.ResolveOverlappingMode = ResolveOverlappingMode.Default;
// Add the chart to the form.
pieChart.Dock = DockStyle.Fill;
this.Controls.Add(pieChart);
}
}
}
681
Examples
Visual Basic
682
C opy C ode
(Form1.vb)
Imports Microsoft.VisualBasic
Imports System
Imports System.Windows.Forms
Imports DevExpress.XtraCharts
Namespace XtraChart_PointOptions
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 pieChart As New ChartControl()
' Create a pie series.
Dim series1 As New Series("A Pie Series", ViewType.Pie)
' Populate the series with points.
series1.Points.Add(New SeriesPoint("Russia", 17.0752))
series1.Points.Add(New SeriesPoint("Canada", 9.98467))
series1.Points.Add(New SeriesPoint("USA", 9.63142))
series1.Points.Add(New SeriesPoint("China", 9.59696))
series1.Points.Add(New SeriesPoint("Brazil", 8.511965))
series1.Points.Add(New SeriesPoint("Australia", 7.68685))
series1.Points.Add(New SeriesPoint("India", 3.28759))
series1.Points.Add(New SeriesPoint("Others", 81.2))
' Add the series to the chart.
pieChart.Series.Add(series1)
' Adjust the point options of the series label.
Dim label As PieSeriesLabel = CType(series1.Label, PieSeriesLabel)
label.PointOptions.PointView = PointView.ArgumentAndValues
label.PointOptions.ValueNumericOptions.Format = NumericFormat.Percent
label.PointOptions.ValueNumericOptions.Precision = 0
' Detect overlapping of series labels.
label.ResolveOverlappingMode = ResolveOverlappingMode.Default
' Add the chart to the form.
pieChart.Dock = DockStyle.Fill
Me.Controls.Add(pieChart)
End Sub
End Class
End Namespace
682
Examples
683
Appearance Customization
How to: Customize a Chart's Appearance
Charting > Examples > How to: Customize a Chart's Appearance
Show Me
The complete sample project is available in the DevExpress Code Central database at http://w ww .devexpress.com/
example=E2664. Depending on the target platform type (ASP.NET, W inForms, etc), you can either run this example
online or dow nload an auto-executable sample.
This example demonstrates how to customize a chart's appearance at runtime, via the ChartControl.
AppearanceName, ChartControl.PaletteName and ChartControl.PaletteBaseColorNumber properties.
Note that you can define a separate palette for painting all indicators available in your chart, via the ChartControl.
IndicatorsPaletteName property.
C#
C opy C ode
(Form1.cs)
using System;
using System.Windows.Forms;
using DevExpress.XtraCharts;
// ...
private void Form1_Load(object sender, EventArgs e) {
// Create an empty chart.
ChartControl barChart = new ChartControl();
// Create a series and add points to it.
Series series1 = new Series("Bar Series", ViewType.Bar);
series1.Points.Add(new SeriesPoint("A", new double[] { 10 }));
series1.Points.Add(new SeriesPoint("B", new double[] { 12 }));
series1.Points.Add(new SeriesPoint("C", new double[] { 14 }));
series1.Points.Add(new SeriesPoint("D", new double[] { 17 }));
// Create an indicator (e.g. Regression Line),
// and add it to the series' collection.
RegressionLine myLine = new RegressionLine(ValueLevel.Value);
((SideBySideBarSeriesView)series1.View).Indicators.Add(myLine);
// Add the series to the chart.
barChart.Series.Add(series1);
// Define the chart's appearance and palette.
barChart.AppearanceName = "Dark";
barChart.PaletteName = "Opulent";
barChart.PaletteBaseColorNumber = 5;
// Define a separate palette for the chart's indicators.
barChart.IndicatorsPaletteName = "Default";
// Add the chart to the form.
barChart.Dock = DockStyle.Fill;
this.Controls.Add(barChart);
}
Visual Basic
C opy C ode
(Form1.vb)
Imports System
Imports System.Windows.Forms
Imports DevExpress.XtraCharts
' ...
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As EventArgs) Handles MyBase.Load
' Create an empty chart.
Dim barChart As New ChartControl()
' Create a series and add points to it.
Dim series1 As New Series("Bar Series", ViewType.Bar)
683
Examples
684
Show Me
The complete sample project is available in the DevExpress Code Central database at http://w ww .devexpress.com/
example=E1179. Depending on the target platform type (ASP.NET, W inForms, etc), you can either run this example
online or dow nload an auto-executable sample.
684
Examples
685
C opy C ode
C opy C ode
685
Examples
686
legend.MarkerVisible = True
legend.MarkerSize = New Size(20, 20)
legend.Padding.All = 4
' Define the limits for the legend to occupy the chart's space.
legend.MaxHorizontalPercentage = 50
legend.MaxVerticalPercentage = 50
' Customize the legend appearance.
legend.BackColor = Color.Beige
legend.FillStyle.FillMode = FillMode.Gradient
CType(legend.FillStyle.Options, RectangleGradientFillOptions).Color2 = Color.Bisque
legend.Border.Visible = True
legend.Border.Color = Color.DarkBlue
legend.Border.Thickness = 2
legend.Shadow.Visible = True
legend.Shadow.Color = Color.LightGray
legend.Shadow.Size = 2
' Customize the legend text properties.
legend.Antialiasing = False
legend.Font = New Font("Arial", 9, FontStyle.Bold)
legend.TextColor = Color.DarkBlue
Show Me
The complete sample project is available in the DevExpress Code Central database at http://w ww .devexpress.com/
example=E1373. Depending on the target platform type (ASP.NET, W inForms, etc), you can either run this example
online or dow nload an auto-executable sample.
See Also
Legend Appearance
686
Examples
687
C opy C ode
// Cast the chart's diagram to the XYDiagram type, to access its axes.
XYDiagram diagram = (XYDiagram)chartControl1.Diagram;
// Customize the appearance of the axes' tickmarks.
diagram.AxisX.Tickmarks.CrossAxis = true;
diagram.AxisX.Tickmarks.Length = 5;
diagram.AxisX.Tickmarks.Thickness = 2;
diagram.AxisY.Tickmarks.Visible = false;
diagram.AxisY.Tickmarks.MinorVisible = false;
diagram.AxisX.Tickmarks.MinorLength = 3;
diagram.AxisX.Tickmarks.MinorThickness = 1;
diagram.AxisX.MinorCount = 2;
diagram.AxisY.MinorCount = 4;
// Customize the appearance of the axes' grid lines.
diagram.AxisX.GridLines.Visible = false;
diagram.AxisX.GridLines.MinorVisible = false;
diagram.AxisY.GridLines.Visible = true;
diagram.AxisY.GridLines.MinorVisible = true;
diagram.AxisY.GridLines.Color = Color.Red;
diagram.AxisY.GridLines.LineStyle.DashStyle = DashStyle.Solid;
diagram.AxisY.GridLines.LineStyle.Thickness = 2;
diagram.AxisY.GridLines.MinorColor = Color.Blue;
diagram.AxisY.GridLines.MinorLineStyle.DashStyle = DashStyle.Dash;
diagram.AxisY.GridLines.MinorLineStyle.Thickness = 1;
Visual Basic
C opy C ode
' Cast the chart's diagram to the XYDiagram type, to access its axes.
Dim diagram As XYDiagram = CType(chartControl1.Diagram, XYDiagram)
' Customize the appearance of the axes' tickmarks.
diagram.AxisX.Tickmarks.CrossAxis = True
diagram.AxisX.Tickmarks.Length = 5
diagram.AxisX.Tickmarks.Thickness = 2
diagram.AxisY.Tickmarks.Visible = False
diagram.AxisY.Tickmarks.MinorVisible = False
diagram.AxisX.Tickmarks.MinorLength = 3
diagram.AxisX.Tickmarks.MinorThickness = 1
diagram.AxisX.MinorCount = 2
diagram.AxisY.MinorCount = 4
' Customize the appearance of the axes' grid lines.
diagram.AxisX.GridLines.Visible = False
diagram.AxisX.GridLines.MinorVisible = False
diagram.AxisY.GridLines.Visible = True
diagram.AxisY.GridLines.MinorVisible = True
diagram.AxisY.GridLines.Color = Color.Red
diagram.AxisY.GridLines.LineStyle.DashStyle = DashStyle.Solid
diagram.AxisY.GridLines.LineStyle.Thickness = 2
diagram.AxisY.GridLines.MinorColor = Color.Blue
diagram.AxisY.GridLines.MinorLineStyle.DashStyle = DashStyle.Dash
diagram.AxisY.GridLines.MinorLineStyle.Thickness = 1
The result is show n in the following image.
687
Examples
688
Show Me
The complete sample project is available in the DevExpress Code Central database at http://w ww .devexpress.com/
example=E1367. Depending on the target platform type (ASP.NET, W inForms, etc), you can either run this example
online or dow nload an auto-executable sample.
See Also
Grid Lines, Tickmarks and Interlacing
688
Examples
689
How to: Customize the Appearance of a Pane's Scroll Bar (Runtime Sample)
Charting > Examples > How to: Customize the Appearance of a Pane's Scroll Bar (Runtime Sample)
This example demonstrates how the appearance of a pane's
can be customized.
Note that for a pane, it's possible to individually adjust the position and visibility of its X and Y-axis' scroll bars.
C#
C opy C ode
C opy C ode
Show Me
The complete sample project is available in the DevExpress Code Central database at http://w ww .devexpress.com/
example=E1382. Depending on the target platform type (ASP.NET, W inForms, etc), you can either run this example
online or dow nload an auto-executable sample.
See Also
Panes
Axis Visible and Scrolling Ranges
689
Examples
690
C opy C ode
using DevExpress.XtraCharts;
// ...
private void chartControl1_CustomDrawSeries(object sender,
CustomDrawSeriesEventArgs e) {
// Find all Bar Series by their view type,
// and fill them with Aqua color.
if (e.Series.View is BarSeriesView)
e.SeriesDrawOptions.Color = Color.Aqua;
// Find the series by its name,
// and change its line style to dash-dot-dot.
// (Here it's assumed that the series view type is LineSeriesView).
if (e.Series.Name == "Line Series")
((LineDrawOptions)e.SeriesDrawOptions).LineStyle.DashStyle =
DashStyle.DashDotDot;
// Find all Point Series by the type of its DrawOptions,
// and change their marker kind to diamond.
if (e.SeriesDrawOptions.GetType() == typeof(PointDrawOptions))
((PointDrawOptions)e.SeriesDrawOptions).Marker.Kind =
MarkerKind.Diamond;
}
Visual Basic
C opy C ode
Imports DevExpress.XtraCharts
' ...
Private Sub OnCustomDrawSeries(sender As Object, e As CustomDrawSeriesEventArgs) _
Handles ChartControl1.CustomDrawSeries
' Find all Bar Series by their view type, and fill them with Aqua color.
If TypeOf e.Series.View Is BarSeriesView Then
e.SeriesDrawOptions.Color = Color.Aqua
End If
' Find the series by its name, and change its line style to dash-dot-dot.
' (Here it's assumed that the series view type is LineSeriesView).
If e.Series.Name = "Line Series" Then
CType(e.SeriesDrawOptions, LineDrawOptions).LineStyle.DashStyle = DashStyle.DashDotDot
End If
' Find all Point Series by the type of its DrawOptions,
' and change their marker kind to diamond.
If e.SeriesDrawOptions.GetType() Is GetType(PointDrawOptions) Then
CType(e.SeriesDrawOptions, PointDrawOptions).Marker.Kind = MarkerKind.Diamond
End If
End Sub
See Also
Series
How to: Custom Paint Series Points
690
Examples
691
C opy C ode
using DevExpress.XtraCharts;
// ...
private void chartControl1_CustomDrawSeriesPoint(object sender,
CustomDrawSeriesPointEventArgs e) {
// These changes will be applied to Bar Series only.
BarDrawOptions drawOptions = e.SeriesDrawOptions as BarDrawOptions;
if (drawOptions == null)
return;
// Get the fill options for the series point.
drawOptions.FillStyle.FillMode = FillMode.Gradient;
RectangleGradientFillOptions options =
drawOptions.FillStyle.Options as RectangleGradientFillOptions;
if (options == null)
return;
// Get the value at the current series point.
double val = e.SeriesPoint[0];
// If the value is less than 2.5, then fill the bar with green colors.
if (val < 2.5) {
options.Color2 = Color.FromArgb(154, 196, 84);
drawOptions.Color = Color.FromArgb(81, 137, 3);
drawOptions.Border.Color = Color.FromArgb(100, 39, 91, 1);
}
// ... if the value is less than 5.5, then fill the bar with yellow colors.
else if (val < 5.5) {
options.Color2 = Color.FromArgb(254, 233, 124);
drawOptions.Color = Color.FromArgb(249, 170, 15);
drawOptions.Border.Color = Color.FromArgb(60, 165, 73, 5);
}
// ... if the value is greater, then fill the bar with red colors.
else {
options.Color2 = Color.FromArgb(242, 143, 112);
drawOptions.Color = Color.FromArgb(199, 57 ,12);
drawOptions.Border.Color = Color.FromArgb(100, 155, 26, 0);
}
}
Visual Basic
C opy C ode
Imports DevExpress.XtraCharts
' ...
Private Sub OnCustomDrawSeriesPoint(ByVal sender As Object, _
ByVal e As CustomDrawSeriesPointEventArgs) _
Handles chartControl1.CustomDrawSeriesPoint
' These changes will be applied to Bar Series only.
Dim drawOptions = CType(e.SeriesDrawOptions, BarDrawOptions)
If drawOptions Is Nothing Then
Return
End If
' Get the fill options for the series point.
drawOptions.FillStyle.FillMode = FillMode.Gradient
691
Examples
692
692
Examples
693
C opy C ode
using System;
using System.Windows.Forms;
using DevExpress.XtraCharts;
// ...
private void chart_CustomDrawSeriesPoint (object sender, CustomDrawSeriesPointEventArgs e) {
// If the value is less than 1, hide the point's label.
if(e.SeriesPoint[0] < 1) {
e.LabelText = "";
}
}
Visual Basic
C opy C ode
Imports System
Imports System.Windows.Forms
Imports DevExpress.XtraCharts
' ...
Private Sub chart_CustomDrawSeriesPoint (ByVal sender As Object, _
ByVal e As CustomDrawSeriesPointEventArgs)
' If the value is less than 1, hide the point's label.
If e.SeriesPoint(0) < 1 Then
e.LabelText = ""
End If
End Sub
Show Me
The complete sample project is available in the DevExpress Code Central database at http://w ww .devexpress.com/
example=E452. Depending on the target platform type (ASP.NET, WinForms, etc), you can either run this example
online or dow nload an auto-executable sample.
See Also
2013 DevExpress Inc.
693
Examples
694
694
Examples
695
C opy C ode
using System;
using System.Windows.Forms;
using DevExpress.XtraCharts;
// ...
private void chartControl1_CustomDrawSeriesPoint(object sender,
CustomDrawSeriesPointEventArgs e) {
if(e.SeriesPoint.Values[0] > 1) {
e.LabelText = "Critical value";
}
}
Visual Basic
C opy C ode
Imports System
Imports System.Windows.Forms
Imports DevExpress.XtraCharts
' ...
Private Sub chartControl1_CustomDrawSeriesPoint(ByVal sender As Object, _
ByVal e As CustomDrawSeriesPointEventArgs) Handles chartControl1.CustomDrawSeriesPoint
If e.SeriesPoint.Values(0) > 1 Then
e.LabelText = "Critical value"
End If
End Sub
The result is show n in the following image.
See Also
How to: Conditionally Hide Series Labels
How to: Avoid Overlapping of Series Labels
695
Examples
696
XtraCharts can help to avoid this, by applying an overlap resolving algorithm to series labels. Then, label overlap
is auto-detected, and based on a chosen algorithm, either hides the overlapped labels, or distributes labels to
avoid overlap. This functionality is available for both 2D and 3D chart types.
Note
The available modes differ from one series view type to another, and in this example we'll use the most popular Line
view type. To learn w hich options are available for each view type, refer to Series Point Labels.
To enable overlap detection, simply set the SeriesLabelBase.ResolveOverlappingMode property to a value other
than None. The set of modes that are available for this property depend on the view type of the series. For the
Line series, the following options are available:
For example, set the SeriesLabelBase.ResolveOverlappingMode property to HideOverlapped, to get the following
result.
696
Examples
697
For information on the availability of specific overlap resolving modes for every chart type, refer to the
corresponding section of the Series Point Labels document.
In addition, you can specify the minimum indent which should be preserved between adjacent series labels, via
the SeriesLabelBase.ResolveOverlappingMinIndent property.
Show Me
The complete sample project is available in the DevExpress Code Central database at http://w ww .devexpress.com/
example=E1273. Depending on the target platform type (ASP.NET, W inForms, etc), you can either run this example
online or dow nload an auto-executable sample.
See Also
Series Point Labels
697
Examples
698
C opy C ode
using System;
using System.Windows.Forms;
using DevExpress.XtraCharts;
// ...
private void chartControl1_CustomDrawSeries(object sender, CustomDrawSeriesEventArgs e) {
e.LegendText = e.LegendText.Remove(0, 3);
}
Visual Basic
C opy C ode
698
Examples
699
C opy C ode
(Form1.cs)
using System;
using System.Drawing;
using System.Windows.Forms;
using DevExpress.XtraCharts;
namespace CustomDrawCrosshair {
public partial class Form1 : Form {
bool handleCustomDraw;
public Form1() {
InitializeComponent();
}
public void button1_Click(object sender, EventArgs e) {
handleCustomDraw = true;
chartControl1.CustomDrawCrosshair += chartControl1_CustomDrawCrosshair;
}
private void chartControl1_CustomDrawCrosshair(object sender, DevExpress.XtraCharts.CustomDrawC
if (!handleCustomDraw) return;
// Specify the crosshair argument line color, dash style and thickness.
e.CrosshairLineElement.Color = Color.Green;
e.CrosshairLineElement.LineStyle.DashStyle = DashStyle.DashDot;
e.CrosshairLineElement.LineStyle.Thickness = 3;
// Specify the back color for crosshair argument label.
foreach (CrosshairAxisLabelElement axisLabelElement in e.CrosshairAxisLabelElements)
axisLabelElement.BackColor = Color.Blue;
foreach (CrosshairElement element in e.CrosshairElements) {
// Specify the color, dash style and thickness for the crosshair value lines.
element.LineElement.Color = Color.DarkViolet;
element.LineElement.LineStyle.DashStyle = DashStyle.Dash;
element.LineElement.LineStyle.Thickness = 2;
// Specify the text color and back color for the crosshair value labels.
element.AxisLabelElement.TextColor = Color.Red;
element.AxisLabelElement.BackColor = Color.Yellow;
// Specify the text color and marker size for the crosshair cursor label that shows se
element.LabelElement.TextColor = Color.Red;
element.LabelElement.MarkerSize = new Size(15, 15);
}
}
}
}
Visual Basic
C opy C ode
699
Examples
700
(Form1.vb)
Imports Microsoft.VisualBasic
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports DevExpress.XtraCharts
Namespace CustomDrawCrosshair
Partial Public Class Form1
Inherits Form
Private handleCustomDraw As Boolean
Public Sub New()
InitializeComponent()
End Sub
Public Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button1.Click
handleCustomDraw = True
AddHandler chartControl1.CustomDrawCrosshair, AddressOf chartControl1_CustomDrawCrosshair
End Sub
Private Sub chartControl1_CustomDrawCrosshair(ByVal sender As Object, ByVal e As DevExpress.Xtr
If (Not handleCustomDraw) Then
Return
End If
' Specify the crosshair argument line color, dash style and thickness.
e.CrosshairLineElement.Color = Color.Green
e.CrosshairLineElement.LineStyle.DashStyle = DashStyle.DashDot
e.CrosshairLineElement.LineStyle.Thickness = 3
' Specify the back color for crosshair argument label.
For Each axisLabelElement As CrosshairAxisLabelElement In e.CrosshairAxisLabelElements
axisLabelElement.BackColor = Color.Blue
Next axisLabelElement
For Each element As CrosshairElement In e.CrosshairElements
' Specify the color, dash style and thickness for the crosshair value lines.
element.LineElement.Color = Color.DarkViolet
element.LineElement.LineStyle.DashStyle = DashStyle.Dash
element.LineElement.LineStyle.Thickness = 2
' Specify the text color and back color for the crosshair value labels.
element.AxisLabelElement.TextColor = Color.Red
element.AxisLabelElement.BackColor = Color.Yellow
' Specify the text color and marker size for the crosshair cursor label that shows ser
element.LabelElement.TextColor = Color.Red
element.LabelElement.MarkerSize = New Size(15, 15)
Next element
End Sub
End Class
End Namespace
700
Examples
701
Series Views
How to: Change the View of a Series
Charting > Examples > How to: Change the View of a Series
This topic illustrates how to change the current view type of a series at both design and runtime.
Design time.
To change the view type of a particular series, select this series at design time, and in the Property Grid,
click the ellipsis button for the SeriesBase.View property.
In the invoked Series View Types dialog, choose the new view type and click OK.
701
Examples
702
Runtime.
The follow ing example demonstrates how to programmatically change the current series view via the
SeriesBase.ChangeView method. Note that this method is better than directly changing the SeriesBase.
View property, because the ChangeView is implemented in a w ay that saves the property values of the
old view to the greatest degree possible.
C#
C opy C ode
using DevExpress.XtraCharts;
// ...
public void ToPie(SeriesBase series) {
series.ChangeView(ViewType.Pie);
}
public void ToBars(SeriesBase series) {
series.ChangeView(ViewType.Bar);
}
Visual Basic
C opy C ode
Imports DevExpress.XtraCharts
' ...
Public Sub ToPie(series As SeriesBase)
702
Examples
703
series.ChangeView(ViewType.Pie)
End Sub
Public Sub ToBars(series As SeriesBase)
series.ChangeView(ViewType.Bar)
End Sub
See Also
Series View s
How to: Individually Change the View Type of Automatically Created Series
703
Examples
704
Note
Note that you may also invoke this editor by clicking on the ellipsis button for the ChartControl.Series property in
the Properties w indow.
4.Then, a dialog appears that allow s you to add a new series to a chart, and maintain their properties.
Click Add... and select the Gantt series view from the list.
704
Examples
705
This series w ill display the planned duration. Switch to the Properties tab and change the series' Name
to Planned.
5.Click Copy to create the similar series.
705
Examples
706
706
Examples
707
Add a task link to each point except the first, connecting it with a "Finish-to-Start" type link to the
previous one. The linked points are listed below:
Parent Point
Link Type
Child Point
Implementation
Finish-to-Start
Planning
Demos&Docs
Finish-to-Start
Implementation
Testing
Finish-to-Start
Demos&Docs
Presentation
Finish-to-Start
Testing
Note that in the link representation an arrow is oriented tow ards the parent point of relation.
8.A constant line w ill act as a "progress line" of a Gantt chart. Select the horizontal AxisY (date-time axis
in this instance), click the ConstantLines item at the Property window and invoke the Constant Line
Collection Editor. Click Add to add an item and set its Name to PROGRESS, LineStyle.DashStyle - to
Dash and AxisValue - to 10/10/2008.
707
Examples
708
708
Examples
709
Result
The resulting chart is show n in the following image.
See Also
Gantt Series Views
Gantt Diagram
709
Examples
710
Then, select the Pie series, and in the Properties w indow, expand its SeriesBase.View property, to access options
specific for the Pie series. Among these options, locate the PieSeriesViewBase.ExplodeMode property, allow ing
you to choose from several modes where the exploded points are defined. These modes are briefly described
below .
UsePoints
If you choose the PieExplodeMode.UsePoints mode, you should explicitly determine which points to explode, via
the PieSeriesViewBase.ExplodedPoints property. So, click the ellipsis button of this property, and in the invoked
dialog, check the series points to be exploded, and click Close.
710
Examples
711
UseFilters
W hen you select the PieExplodeMode.UseFilters mode, the PieSeriesViewBase.ExplodedPointsFilters property
becomes available. Click its ellipsis button, and in the invoked dialog, create a new filtering criteria, and define its
properties.
For example, to explode points whose values are greater than 30, set the SeriesPointFilter.Condition property to
GreaterThan, SeriesPointFilter.Key - to Value, and SeriesPointFilter.Value - to 30. The result is shown in the
following image.
711
Examples
712
PieExplodeMode = MaxValue
PieExplodeMode = None
Others
The special PieExplodeMode.Others mode should be applied when the "TopN" feature is enabled, to explode the
points aggregated under the "Others" argument. The image below demonstrates this mode in a chart created for
the following tutorial: How to: Show N Top Points as a Single Section in a Pie Chart.
712
Examples
713
In addition, use the PieSeriesView Base.ExplodedDistancePercentage property, to define the distance at which the
exploded points are sliced out.
To allow your end users interactively explode the required series points at runtime, enable the PieSeriesView.
RuntimeExploding property.
See Also
How to: Show N Top Points as a Single Section in a Pie Chart
713
Examples
714
C opy C ode
using System;
using DevExpress.XtraCharts;
using DevExpress.XtraCharts.Web;
// ...
protected void ASPxButton1_Click(object sender, EventArgs e) {
// Create a WebChartControl instance.
WebChartControl WebChartControl1 = new WebChartControl();
// Add the chart to the form.
// Note that a chart isn't initialized until it's added to the form's collection of contro
this.form1.Controls.Add(WebChartControl1);
// Create a line series and add points to it.
Series series1 = new Series("My Series", ViewType.Line);
series1.Points.Add(new SeriesPoint("A", new double[] { 2 }));
series1.Points.Add(new SeriesPoint("B", new double[] { 7 }));
series1.Points.Add(new SeriesPoint("C", new double[] { 5 }));
series1.Points.Add(new SeriesPoint("D", new double[] { 9 }));
// Add the series to the chart.
WebChartControl1.Series.Add(series1);
}
Visual Basic
C opy C ode
Imports System
Imports DevExpress.XtraCharts
Imports DevExpress.XtraCharts.Web
' ...
Protected Sub ASPxButton1_Click(ByVal sender As Object, ByVal e As EventArgs)
2013 DevExpress Inc.
714
Examples
715
' Create a WebChartControl instance.
Dim WebChartControl1 As New WebChartControl()
' Add the chart to the form.
' Note that a chart isn't initialized until it's added
Me.form1.Controls.Add(WebChartControl1)
' Create a line series and add points to it.
Dim series1 As New Series("My Series", ViewType.Line)
series1.Points.Add(New SeriesPoint("A", New Double() {
series1.Points.Add(New SeriesPoint("B", New Double() {
series1.Points.Add(New SeriesPoint("C", New Double() {
series1.Points.Add(New SeriesPoint("D", New Double() {
' Add the series to the chart.
WebChartControl1.Series.Add(series1)
End Sub
2
7
5
9
}))
}))
}))
}))
Run the w eb application, and click the ASPxButton1 to see the resulting chart.
Show Me
The complete sample project is available in the DevExpress Code Central database at http://w ww .devexpress.com/
example=E1171. Depending on the target platform type (ASP.NET, W inForms, etc), you can either run this example
online or dow nload an auto-executable sample.
See Also
Web Charting Specifics
How to: Add a Chart to an ASPxCallbackPanel during its Callback (Runtime Sample)
How to: Bind a W eb Chart to Data (Runtime Sample)
How to: Bind a W eb Chart to an ASPxPivotGrid
715
Examples
716
The complete sample project is available in the DevExpress Code Central database at http://w ww .devexpress.com/
example=E568. Depending on the target platform type (ASP.NET, WinForms, etc), you can either run this example
online or dow nload an auto-executable sample.
1.Create a new ASP.NET Web Application (Visual Studio 2008 or 2010), or open an existing one.
2.Add the required assemblies to the project.
Note that if you prefer that the assemblies be added automatically (by dropping a WebChartControl
instance onto the page), this affects your web application's Web.config file. To learn about the changes
being made to it, refer to Adding a W eb Chart.
3.Switch to the Design view of the Default.aspx page, and from the DX.12.2: Common Controls toolbox
tab, drop an ASPxButton onto the page.
4.Then, click the button's smart tag. In the invoked actions list, disable the AutoPostBack property, and
click Client-Side Events... link.
In the invoked dialog, from w ithin the client-side Click event handler, call the PerformCallback() for the
callback panel.
716
Examples
717
6.Set its ClientInstanceName to panel, and handle its Callback event in the follow ing way.
C#
C opy C ode
using System;
using DevExpress.XtraCharts;
using DevExpress.XtraCharts.Web;
using DevExpress.Web.ASPxClasses;
using DevExpress.Web.ASPxCallbackPanel;
// ...
protected void ASPxCallbackPanel1_Callback(object sender,
CallbackEventArgsBase e) {
WebChartControl wbc = new WebChartControl();
wbc.Series.Add(new Series("Series", ViewType.Line));
wbc.Series[0].ArgumentScaleType = ScaleType.DateTime;
wbc.Series[0].ValueScaleType = ScaleType.Numerical;
Random r = new Random();
for (int i = 0; i < 5; i++) {
wbc.Series[0].Points.Add(new SeriesPoint(DateTime.Today.AddDays(i),
((int)((r.NextDouble() * 100) * 10)) / 10.0));
}
wbc.Width = ((ASPxCallbackPanel)sender).Width;
((ASPxCallbackPanel)sender).Controls.Add(wbc);
}
Visual Basic
C opy C ode
Imports System
Imports DevExpress.XtraCharts
Imports DevExpress.XtraCharts.Web
Imports DevExpress.Web.ASPxClasses
Imports DevExpress.Web.ASPxCallbackPanel
' ...
Protected Sub ASPxCallbackPanel1_Callback(ByVal sender As Object, _
ByVal e As CallbackEventArgsBase)
Dim wbc As New WebChartControl()
wbc.Series.Add(New Series("Series", ViewType.Line))
wbc.Series(0).ArgumentScaleType = ScaleType.DateTime
wbc.Series(0).ValueScaleType = ScaleType.Numerical
Dim r As New Random()
For i As Integer = 0 To 4
wbc.Series(0).Points.Add(New SeriesPoint(DateTime.Today.AddDays(i), _
(CInt(Fix((r.NextDouble() * 100) * 10))) / 10.0))
Next i
wbc.Width = (CType(sender, ASPxCallbackPanel)).Width
CType(sender, ASPxCallbackPanel).Controls.Add(wbc)
End Sub
Run the application, and view the result.
717
Examples
718
See Also
How to: Bind a W eb Chart to Data (Runtime Sample)
How to: Bind a W eb Chart to an ASPxPivotGrid
718
Examples
719
C opy C ode
(Default.aspx.cs)
using System;
using DevExpress.XtraCharts;
// ...
namespace WebChartDataBinding {
public partial class _Default : System.Web.UI.Page {
protected void Button1_Click(object sender, EventArgs e) {
WebChartControl1.DataSourceID = "AccessDataSource1";
WebChartControl1.SeriesDataMember = "Year";
WebChartControl1.SeriesTemplate.ArgumentDataMember = "Region";
WebChartControl1.SeriesTemplate.ValueDataMembers.AddRange(new string[] {"GSP"});
WebChartControl1.SeriesTemplate.View = new SideBySideBarSeriesView();
WebChartControl1.DataBind();
}
}
}
Visual Basic
C opy C ode
(Default.aspx.vb)
Imports System
Imports DevExpress.XtraCharts
' ...
Namespace WebChartDataBinding
Partial Public Class _Default
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
WebChartControl1.DataSourceID = "AccessDataSource1"
WebChartControl1.SeriesDataMember = "Year"
WebChartControl1.SeriesTemplate.ArgumentDataMember = "Region"
WebChartControl1.SeriesTemplate.ValueDataMembers.AddRange(New String() {"GSP"})
WebChartControl1.SeriesTemplate.View = New SideBySideBarSeriesView()
WebChartControl1.DataBind()
End Sub
End Class
End Namespace
See Also
Web Charting Specifics
2013 DevExpress Inc.
719
Examples
720
3.To bind the pivot grid to a data base, click its smart tag, and in the invoked actions list, expand the
drop-dow n menu for the Choose Data Source entry.
And, click New data source... link.
720
Examples
721
4.Then, proceed w ith the steps of the Data Source Configuration Wizard, to connect to your data
source. In this example, we'll use the gsp.mdb file (w hich is shipped w ith the installation of the
XtraCharts suite), copied to the application's folder.
5.After you've connected to a data source, click the pivot grid's smart tag again, and in its actions list,
choose Fields.
721
Examples
722
6.In the invoked dialog, click Retrieve fields, and among the obtained fields, remove the ID field, since it
is unnecessary in this project.
722
Examples
723
Now, the pivot grid has been successfully bound to data, and it's only left to create a W eb chart bound to this
grid. This is explained in the next section of this tutorial.
723
Examples
724
11.In the Properties w indow, specify the follow ing properties of the chart's
12.Then, you can adjust other chart's options, e.g. disable its series labels.
Get the Result
The W ebChartControl has now successfully bound to the ASPxPivotGrid. Run the application, and view the result.
724
Examples
725
Note that after you filter the grid's columns and row s right in the browser, this has an immediate effect on the
linked chart.
See Also
How to: Add a Chart to an ASPxCallbackPanel during its Callback (Runtime Sample)
725
Examples
726
How to: Show Custom Data Over a Web Chart Using ASPxPopupControl
Charting > Examples > How to: Show Custom Data Over a Web Chart Using ASPxPopupControl
This example demonstrates how to show custom data obtained from a WebChartControl's data source, when a
series point is hovered with the mouse. This can be implemented, using the ASPxPopupControl, with the
ASPxCallbackPanel being placed in it, so that data is obtained during its
.
Show Me
The complete sample project is available in the DevExpress Code Central database at http://w ww .devexpress.com/
example=E258. Depending on the target platform type (ASP.NET, WinForms, etc), you can either run this example
online or dow nload an auto-executable sample.
To implement tooltips for a Web chart, do the follow ing.
1.Create a new ASP.NET Web Application (Visual Studio 2008 or 2010), or open an existing one.
2.Drop a chart onto the W eb page, and bind it to a data source.
3.From the DX.12.2: Navigation & Layout toolbox tab, drop an ASPxPopupControl onto the page.
726
Examples
727
6.Now , select the ASPxCallbackPanel1, and click its smart tag. In its actions list, click Client-Side
Events... link.
In the invoked dialog, handle the CallbackClientSideEvents.EndCallback event in the following way.
JScript
C opy C ode
function(s, e) {
pc.SetHeaderText(s.cpHeaderText);
pc.ShowAtPos(pcX, pcY);
}
7.In a similar w ay, click the chart's smart tag, and in its actions list, click Client-Side Events... link.
727
Examples
728
In the invoked dialog, handle the ChartClientSideEvents.ObjectSelected event in the following way.
JScript
C opy C ode
function(s, e) {
if (e.hitInfo.inSeries) {
var obj = e.additionalHitObject;
if (obj != null){
pcX = e.absoluteX;
pcY = e.absoluteY;
cbp.PerformCallback(obj.argument);
}
}
}
8.Now , handle the ASPxCallbackPanel.Callback event in the following w ay.
C#
using
using
using
using
using
C opy C ode
System;
System.Data;
System.Web.UI;
System.Collections;
DevExpress.Web.ASPxClasses;
728
Examples
729
// ...
string headerText = null;
protected void ASPxCallbackPanel1_Callback(object sender, CallbackEventArgsBase e) {
String param = e.Parameter.Replace("'", "''");
AccessDataSource1.SelectCommand =
"SELECT * FROM [Products] WHERE ProductName = '" + param + "'";
IEnumerable data = AccessDataSource1.Select(DataSourceSelectArguments.Empty);
foreach (DataRowView row in data) {
ASPxLabel1.Text = "Price: " + row["UnitPrice"].ToString();
ASPxLabel2.Text = "Units in Stock: " + row["UnitsInStock"].ToString();
headerText = row["ProductName"].ToString();
break;
}
}
Visual Basic
C opy C ode
Imports System
Imports System.Data
Imports System.Web.UI
Imports System.Collections
Imports DevExpress.Web.ASPxClasses
' ...
Private headerText As String = Nothing
Protected Sub ASPxCallbackPanel1_Callback(ByVal source As Object, _
ByVal e As CallbackEventArgsBase)
AccessDataSource1.SelectCommand = _
"SELECT * FROM [Products] WHERE ProductName = '" & e.Parameter & "'"
Dim data As IEnumerable = AccessDataSource1.Select(DataSourceSelectArguments.Empty)
For Each row As DataRowView In data
ASPxLabel1.Text = "Price: " & row("UnitPrice").ToString()
ASPxLabel2.Text = "Units in Stock: " & row("UnitsInStock").ToString()
headerText = row("ProductName").ToString()
Exit For
Next row
End Sub
9.And, write the follow ing code into the ASPxCallbackPanel.CustomJSProperties event handler.
C#
C opy C ode
C opy C ode
729
Examples
730
See Also
Web Charting Specifics
How to: Add a Chart to an ASPxCallbackPanel during its Callback (Runtime Sample)
How to: Bind a W eb Chart to an ASPxPivotGrid
730
Examples
731
3.Then, from the DX.12.2: Navigation & Layout toolbox tab, drop an ASPxRoundPanel onto the page.
And, from the DX.12.2: Common Controls toolbox tab, drop two ASPxLabel controls onto the panel.
And, set their ClientInstanceName properties to lblArgument and lblValue, respectively.
4.Again, select the chart, and click its smart tag. In its actions list, choose Client-Side Events... link.
In the invoked dialog, handle the ASPxClientW ebChartControl.ObjectHotTracked event as follows.
JScript
C opy C ode
function(s, e) {
var chart = s.GetChart();
var coord = chart.diagram.PointToDiagram(e.x, e.y);
lblArgument.SetText(coord.dateTimeArgument);
lblValue.SetText(Math.round(coord.numericalValue*100)/100);
}
Run the application, and view the result.
731
Examples
732
In a similar way, it's possible to obtain the diagram coordinates of a series (e.g. Line Chart). A sample project is
available online, in the DevExpress Code Central database at How to use the client-side model of the
W ebChartControl.
See Also
Web Charting Specifics
How to: Add a Chart to an ASPxCallbackPanel during its Callback (Runtime Sample)
How to: Show Custom Data Over a W eb Chart Using ASPxPopupControl
732
Examples
733
C opy C ode
(Default.aspx.cs)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DevExpress.Web.ASPxClasses;
public partial class _Default : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
ASPxWebControl.RegisterBaseScript(this);
}
}
Visual Basic
C opy C ode
(Default.aspx.vb)
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports DevExpress.Web.ASPxClasses
Partial Public Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
ASPxWebControl.RegisterBaseScript(Me)
End Sub
End Class
aspx
C opy C ode
(Default.aspx)
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register assembly="DevExpress.XtraCharts.v11.2.Web, Version=11.2.5.0, Culture=neutral, PublicKeyTok
<%@ Register assembly="DevExpress.XtraCharts.v11.2, Version=11.2.5.0, Culture=neutral, PublicKeyToken=b
<%@ Register assembly="DevExpress.Web.v11.2, Version=11.2.5.0, Culture=neutral, PublicKeyToken=b88d1754
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style type="text/css">
.style1
{
height: 94px;
}
</style>
</head>
<body>
733
Examples
734
734
Examples
735
</OptionsSerializable>
</FillStyle>
<seriesserializable>
<cc1:Series Name="Series 1">
<points>
<cc1:SeriesPoint ArgumentSerializable="A" Values="1">
</cc1:SeriesPoint>
<cc1:SeriesPoint ArgumentSerializable="B" Values="3">
</cc1:SeriesPoint>
<cc1:SeriesPoint ArgumentSerializable="C" Values="5">
</cc1:SeriesPoint>
</points>
<viewserializable>
<cc1:SideBySideBarSeriesView>
</cc1:SideBySideBarSeriesView>
</viewserializable>
<labelserializable>
<cc1:SideBySideBarSeriesLabel LineVisible="True">
<fillstyle>
<optionsserializable>
<cc1:SolidFillOptions />
</optionsserializable>
</fillstyle>
<pointoptionsserializable>
<cc1:PointOptions>
</cc1:PointOptions>
</pointoptionsserializable>
</cc1:SideBySideBarSeriesLabel>
</labelserializable>
<legendpointoptionsserializable>
<cc1:PointOptions>
</cc1:PointOptions>
</legendpointoptionsserializable>
</cc1:Series>
<cc1:Series Name="Series 2">
<points>
<cc1:SeriesPoint ArgumentSerializable="A" Values="2">
</cc1:SeriesPoint>
<cc1:SeriesPoint ArgumentSerializable="B" Values="4">
</cc1:SeriesPoint>
<cc1:SeriesPoint ArgumentSerializable="C" Values="6">
</cc1:SeriesPoint>
</points>
<viewserializable>
<cc1:SideBySideBarSeriesView>
</cc1:SideBySideBarSeriesView>
</viewserializable>
<labelserializable>
<cc1:SideBySideBarSeriesLabel LineVisible="True">
<fillstyle>
<optionsserializable>
<cc1:SolidFillOptions />
</optionsserializable>
</fillstyle>
<pointoptionsserializable>
<cc1:PointOptions>
</cc1:PointOptions>
</pointoptionsserializable>
</cc1:SideBySideBarSeriesLabel>
</labelserializable>
<legendpointoptionsserializable>
2013 DevExpress Inc.
735
Examples
736
<cc1:PointOptions>
</cc1:PointOptions>
</legendpointoptionsserializable>
</cc1:Series>
</seriesserializable>
<diagramserializable>
<cc1:XYDiagram>
<axisx visibleinpanesserializable="-1">
<range sidemarginsenabled="True" />
</axisx>
<axisy visibleinpanesserializable="-1">
<range sidemarginsenabled="True" />
</axisy>
</cc1:XYDiagram>
</diagramserializable>
</dxchartsui:WebChartControl>
</tr>
</table>
<dx:ASPxPopupControl ID="ASPxPopupControl1" runat="server"
ClientInstanceName="Tooltip" ShowHeader="false" Width="0" Height="0">
<ContentStyle Wrap="False"></ContentStyle>
</dx:ASPxPopupControl>
</form>
</body>
</html>
736
Examples
737
Chart Elements
How to: Add Titles to a Chart
Charting > Examples > How to: Add Titles to a Chart
This example demonstrates how chart titles can be accessed and customized at runtime.
C#
C opy C ode
C opy C ode
737
Examples
738
Show Me
The complete sample project is available in the DevExpress Code Central database at http://w ww .devexpress.com/
example=E1375. Depending on the target platform type (ASP.NET, W inForms, etc), you can either run this example
online or dow nload an auto-executable sample.
See Also
Chart Titles
738
Examples
739
C opy C ode
C opy C ode
The title is cut by the ellipsis, since it's text exceeds the defined tw o lines. If required, you can increase the
DockableTitle.MaximumLinesCount property's value, so the entire text w ill fit. Note that in this case, the chart's
diagram, in turn, w ill be shrunk.
Show Me
The complete sample project is available in the DevExpress Code Central database at http://w ww .devexpress.com/
example=E1375. Depending on the target platform type (ASP.NET, W inForms, etc), you can either run this example
online or dow nload an auto-executable sample.
739
Examples
740
See Also
Chart Titles
740
Examples
741
Series 1 value
Series 2 value
Series 3 value
741
Examples
742
selected series is placed on it.
Repeat this procedure for the Series3, so that it is placed in the Pane2.
5.Select the DefaultPane element, and set its XYDiagramPaneBase.Weight property to 1.5, XYDiagram2D.
PaneLayoutDirection to Horizontal, XYDiagram.Rotated to true and XYDiagram2D.PaneDistance to 5.
6.Select the Axis X element. In the Property w indow, locate the VisibleInPanes property and click its
ellipsis button. In the invoked Axis Visibility dialog, check DefaultPane, so that only the current axis is
show n in it.
Also, for the AxisX, you can set the Axis.Reverse property to true, so that arguments are displayed
descending from top to bottom.
Get the Result
The complete chart is show n in the following image.
See Also
Panes
2013 DevExpress Inc.
742
Examples
743
C opy C ode
using System;
using System.Drawing;
using System.Windows.Forms;
using DevExpress.XtraCharts;
// ...
private void Form1_Load(object sender, EventArgs e) {
// Create a new chart.
ChartControl chartControl1 = new ChartControl();
// Create two series.
Series series1 = new Series("Series 1", ViewType.Bar);
Series series2 = new Series("Series 2", ViewType.Line);
// Add points to them, with their arguments different.
series1.Points.Add(new SeriesPoint("A", 10));
series1.Points.Add(new SeriesPoint("B", 12));
series1.Points.Add(new SeriesPoint("C", 17));
series1.Points.Add(new SeriesPoint("D", 14));
series2.Points.Add(new SeriesPoint("I", 2500));
series2.Points.Add(new SeriesPoint("II", 3800));
series2.Points.Add(new SeriesPoint("III", 1500));
series2.Points.Add(new SeriesPoint("IV", 1300));
// Add both series to the chart.
chartControl1.Series.AddRange(new Series[] { series1, series2 });
// Hide the legend (optional).
chartControl1.Legend.Visible = false;
// Cast the chart's diagram to the XYDiagram type,
// to access its axes and panes.
XYDiagram diagram = (XYDiagram)chartControl1.Diagram;
// Add secondary axes to the diagram, and adjust their options.
diagram.SecondaryAxesX.Add(new SecondaryAxisX("My Axis X"));
diagram.SecondaryAxesY.Add(new SecondaryAxisY("My Axis Y"));
diagram.SecondaryAxesX[0].Alignment = AxisAlignment.Near;
diagram.SecondaryAxesY[0].Alignment = AxisAlignment.Near;
// Add a new additional pane to the diagram.
diagram.Panes.Add(new XYDiagramPane("My Pane"));
// Assign both the additional pane and, if required,
// the secondary axes to the second series.
LineSeriesView myView = (LineSeriesView)series2.View;
myView.AxisX = diagram.SecondaryAxesX[0];
myView.AxisY = diagram.SecondaryAxesY[0];
// Note that the created pane has the zero index in the collection,
// because the existing Default pane is a separate entity.
myView.Pane = diagram.Panes[0];
// Customize the layout of the diagram's panes.
diagram.PaneDistance = 10;
diagram.PaneLayoutDirection = PaneLayoutDirection.Horizontal;
diagram.DefaultPane.SizeMode = PaneSizeMode.UseWeight;
diagram.DefaultPane.Weight = 1.2;
// Add the chart to the form.
chartControl1.Dock = DockStyle.Fill;
this.Controls.Add(chartControl1);
}
2013 DevExpress Inc.
743
Examples
Visual Basic
744
C opy C ode
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports DevExpress.XtraCharts
' ...
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As EventArgs) Handles MyBase.Load
' Create a new chart.
Dim chartControl1 As New ChartControl()
' Create two series.
Dim series1 As New Series("Series 1", ViewType.Bar)
Dim series2 As New Series("Series 2", ViewType.Line)
' Add points to them, with their arguments different.
series1.Points.Add(New SeriesPoint("A", 10))
series1.Points.Add(New SeriesPoint("B", 12))
series1.Points.Add(New SeriesPoint("C", 17))
series1.Points.Add(New SeriesPoint("D", 14))
series2.Points.Add(New SeriesPoint("I", 2500))
series2.Points.Add(New SeriesPoint("II", 3800))
series2.Points.Add(New SeriesPoint("III", 1500))
series2.Points.Add(New SeriesPoint("IV", 1300))
' Add both series to the chart.
chartControl1.Series.AddRange(New Series() { series1, series2 })
' Hide the legend (optional).
chartControl1.Legend.Visible = False
' Cast the chart's diagram to the XYDiagram type,
' to access its axes and panes.
Dim diagram As XYDiagram = CType(chartControl1.Diagram, XYDiagram)
' Add secondary axes to the diagram, and adjust their options.
diagram.SecondaryAxesX.Add(New SecondaryAxisX("My Axis X"))
diagram.SecondaryAxesY.Add(New SecondaryAxisY("My Axis Y"))
diagram.SecondaryAxesX(0).Alignment = AxisAlignment.Near
diagram.SecondaryAxesY(0).Alignment = AxisAlignment.Near
' Add a new additional pane to the diagram.
diagram.Panes.Add(New XYDiagramPane("My Pane"))
' Assign both the additional pane and, if required,
' the secondary axes to the second series.
Dim myView As LineSeriesView = CType(series2.View, LineSeriesView)
myView.AxisX = diagram.SecondaryAxesX(0)
myView.AxisY = diagram.SecondaryAxesY(0)
' Note that the created pane has the zero index in the collection,
' because the existing Default pane is a separate entity.
myView.Pane = diagram.Panes(0)
' Customize the layout of the diagram's panes.
diagram.PaneDistance = 10
diagram.PaneLayoutDirection = PaneLayoutDirection.Horizontal
diagram.DefaultPane.SizeMode = PaneSizeMode.UseWeight
diagram.DefaultPane.Weight = 1.2
' Add the chart to the form.
chartControl1.Dock = DockStyle.Fill
Me.Controls.Add(chartControl1)
End Sub
The result is show n in the following image.
744
Examples
745
Show Me
The complete sample project is available in the DevExpress Code Central database at http://w ww .devexpress.com/
example=E1066. Depending on the target platform type (ASP.NET, W inForms, etc), you can either run this example
online or dow nload an auto-executable sample.
See Also
Panes
745
Examples
746
C opy C ode
using System;
using System.Drawing;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraCharts;
using gspDataSetTableAdapters;
// ...
private void button1_Click(object sender, EventArgs e) {
// Create and customize a form.
XtraForm form = new XtraForm();
form.Text = "Multiple Panes and Chart Binding";
form.Size = new Size(800, 600);
// Create a chart.
ChartControl chart = new ChartControl();
// Handle the chart's BoundDataChanged event.
chart.BoundDataChanged += new BoundDataChangedEventHandler(chart_BoundDataChanged);
// Initialize a dataset. Initialize and fill data adapter.
gspDataSet dataSet = new gspDataSet();
GSPTableAdapter dataAdapter = new GSPTableAdapter();
dataAdapter.Fill(dataSet.GSP);
// Assign the chart's datasource to the created dataset.
chart.DataSource = dataSet.GSP;
// Define a data member for the chart's series.
chart.SeriesDataMember = "Year";
// Define an argument and value data members for the chart's series template,
// so that the created series inherit these properties.
chart.SeriesTemplate.ArgumentDataMember = "Region";
chart.SeriesTemplate.ValueDataMembers[0] = "GSP";
// Add the chart to the form's controls collection and fit the chart to the form's dimensions.
chart.Dock = DockStyle.Fill;
form.Controls.Add(chart);
// Show the result.
form.Show();
}
private void chart_BoundDataChanged(object sender, EventArgs e) {
ChartControl chart = (ChartControl)sender;
// Check whether the chart contains series.
if(chart.Series.Count > 0) {
// Obtain a diagram and clear its collection of panes.
XYDiagram diagram = (XYDiagram)chart.Diagram;
diagram.Panes.Clear();
746
Examples
747
// Create a pane for each series.
for(int i = 1; i < chart.Series.Count; i++) {
XYDiagramPane pane = new XYDiagramPane("The Pane's Name");
diagram.Panes.Add(pane);
XYDiagramSeriesViewBase view = (XYDiagramSeriesViewBase)chart.Series[i].View;
view.Pane = pane;
}
}
}
Visual Basic
C opy C ode
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports DevExpress.XtraEditors
Imports DevExpress.XtraCharts
Imports gspDataSetTableAdapters
' ...
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) _
Handles button1.Click
' Create and customize a form.
Dim form As XtraForm = New XtraForm()
form.Text = "Multiple Panes and Chart Binding"
form.Size = New Size(800, 600)
' Create a chart.
Dim chart As ChartControl = New ChartControl()
' Handle the chart's BoundDataChanged event.
AddHandler chart.BoundDataChanged, AddressOf chart_BoundDataChanged
' Initialize a dataset. Initialize and fill data adapter.
Dim dataSet As gspDataSet = New gspDataSet()
Dim dataAdapter As GSPTableAdapter = New GSPTableAdapter()
dataAdapter.Fill(dataSet.GSP)
' Assign the chart's datasource to the created dataset.
chart.DataSource = dataSet.GSP
' Define a data member for the chart's series.
chart.SeriesDataMember = "Year"
' Define an argument and value data members for the chart's series template,
' so that the created series inherit these properties.
chart.SeriesTemplate.ArgumentDataMember = "Region"
chart.SeriesTemplate.ValueDataMembers(0) = "GSP"
' Add the chart to the form's controls collection and fit the chart to the form's dimensions.
chart.Dock = DockStyle.Fill
form.Controls.Add(chart)
' Show the result.
form.Show()
End Sub
Private Sub chart_BoundDataChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim chart As ChartControl = CType(sender, ChartControl)
' Check whether the chart contains series.
If chart.Series.Count > 0 Then
' Obtain a diagram and clear its collection of panes.
Dim diagram As XYDiagram = CType(chart.Diagram, XYDiagram)
diagram.Panes.Clear()
' Create a pane for each series.
Dim i As Integer = 1
Do While i < chart.Series.Count
Dim pane As XYDiagramPane = New XYDiagramPane("The Pane's Name")
diagram.Panes.Add(pane)
Dim view As XYDiagramSeriesViewBase = CType _
(chart.Series(i).View, XYDiagramSeriesViewBase)
view.Pane = pane
2013 DevExpress Inc.
747
Examples
748
i += 1
Loop
End If
End Sub
Show Me
The complete sample project is available in the DevExpress Code Central database at http://w ww .devexpress.com/
example=E433. Depending on the target platform type (ASP.NET, WinForms, etc), you can either run this example
online or dow nload an auto-executable sample.
See Also
Panes
748
Examples
749
C opy C ode
// Cast the chart's diagram to the XYDiagram type, to access its axes.
XYDiagram diagram = (XYDiagram)chartControl1.Diagram;
// Customize the appearance of the X-axis title.
diagram.AxisX.Title.Visible = true;
diagram.AxisX.Title.Alignment = StringAlignment.Center;
diagram.AxisX.Title.Text = "X-axis Title";
diagram.AxisX.Title.TextColor = Color.Red;
diagram.AxisX.Title.Antialiasing = true;
diagram.AxisX.Title.Font = new Font("Tahoma", 14, FontStyle.Bold);
// Customize the appearance of the Y-axis title.
diagram.AxisY.Title.Visible = true;
diagram.AxisY.Title.Alignment = StringAlignment.Center;
diagram.AxisY.Title.Text = "Y-axis Title";
diagram.AxisY.Title.TextColor = Color.Blue;
diagram.AxisY.Title.Antialiasing = true;
diagram.AxisY.Title.Font = new Font("Tahoma", 14, FontStyle.Bold);
Visual Basic
C opy C ode
' Cast the chart's diagram to the XYDiagram type, to access its axes.
Dim diagram As XYDiagram = CType(chartControl1.Diagram, XYDiagram)
' Customize the appearance of the X-axis title.
diagram.AxisX.Title.Visible = True
diagram.AxisX.Title.Alignment = StringAlignment.Center
diagram.AxisX.Title.Text = "X-axis Title"
diagram.AxisX.Title.TextColor = Color.Red
diagram.AxisX.Title.Antialiasing = True
diagram.AxisX.Title.Font = New Font("Tahoma", 14, FontStyle.Bold)
' Customize the appearance of the Y-axis title.
diagram.AxisY.Title.Visible = True
diagram.AxisY.Title.Alignment = StringAlignment.Center
diagram.AxisY.Title.Text = "Y-axis Title"
diagram.AxisY.Title.TextColor = Color.Blue
diagram.AxisY.Title.Antialiasing = True
diagram.AxisY.Title.Font = New Font("Tahoma", 14, FontStyle.Bold)
The result is show n in the following image.
749
Examples
750
Show Me
The complete sample project is available in the DevExpress Code Central database at http://w ww .devexpress.com/
example=E1366. Depending on the target platform type (ASP.NET, W inForms, etc), you can either run this example
online or dow nload an auto-executable sample.
See Also
Axis Titles
How to: Determine w hether an Axis Title is Being Hovered by the Mouse Pointer
750
Examples
751
How to: Determine whether an Axis Title is Being Hovered by the Mouse
Pointer
Charting > Examples > How to: Determine whether an Axis Title is Being Hovered by the Mouse Pointer
This example demonstrates how you can determine whether an axis title is being hovered by the mouse pointer,
and if so, display its type (AxisTitleX or AxisTitleY) in a message box.
C#
C opy C ode
using System;
using System.Windows.Forms;
using DevExpress.XtraCharts;
// ...
private void chartControl1_ObjectHotTracked(object sender, HotTrackEventArgs e) {
if (e.AdditionalObject is AxisTitle) {
MessageBox.Show(e.AdditionalObject.GetType().ToString());
}
}
Visual Basic
C opy C ode
Imports System
Imports System.Windows.Forms
Imports DevExpress.XtraCharts
' ...
Private Sub chartControl1_ObjectHotTracked(ByVal sender As Object, _
ByVal e As HotTrackEventArgs) Handles chartControl1.ObjectHotTracked
If TypeOf e.AdditionalObject Is AxisTitle Then
MessageBox.Show(e.AdditionalObject.GetType().ToString())
End If
End Sub
The result is show n in the following image.
Show Me
2013 DevExpress Inc.
751
Examples
752
The complete sample project is available in the DevExpress Code Central database at http://w ww .devexpress.com/
example=E1727. Depending on the target platform type (ASP.NET, W inForms, etc), you can either run this example
online or dow nload an auto-executable sample.
See Also
Axis Titles
752
Examples
753
C opy C ode
using System;
using System.Drawing;
using System.Windows.Forms;
using DevExpress.XtraCharts;
// ...
private void Form1_Load(object sender, EventArgs e) {
// Create a new chart.
ChartControl chartControl1 = new ChartControl();
// Create two series.
Series series1 = new Series("Series 1", ViewType.Bar);
Series series2 = new Series("Series 2", ViewType.Line);
// Add points to them, with their arguments different.
series1.Points.Add(new SeriesPoint("A", 10));
series1.Points.Add(new SeriesPoint("B", 12));
series1.Points.Add(new SeriesPoint("C", 17));
series1.Points.Add(new SeriesPoint("D", 14));
series2.Points.Add(new SeriesPoint("I", 1500));
series2.Points.Add(new SeriesPoint("II", 1800));
series2.Points.Add(new SeriesPoint("III", 2500));
series2.Points.Add(new SeriesPoint("IV", 3300));
// Add both series to the chart.
chartControl1.Series.AddRange(new Series[] { series1, series2 });
// Hide the legend (optional).
chartControl1.Legend.Visible = false;
// Create two secondary axes, and add them to the chart's Diagram.
SecondaryAxisX myAxisX = new SecondaryAxisX("my X-Axis");
SecondaryAxisY myAxisY = new SecondaryAxisY("my Y-Axis");
((XYDiagram)chartControl1.Diagram).SecondaryAxesX.Add(myAxisX);
((XYDiagram)chartControl1.Diagram).SecondaryAxesY.Add(myAxisY);
// Assign the series2 to the created axes.
((LineSeriesView)series2.View).AxisX = myAxisX;
((LineSeriesView)series2.View).AxisY = myAxisY;
// Customize the appearance of the secondary axes (optional).
myAxisX.Title.Text = "A Secondary X-Axis";
myAxisX.Title.Visible = true;
myAxisX.Title.TextColor = Color.Red;
myAxisX.Label.TextColor = Color.Red;
myAxisX.Color = Color.Red;
myAxisY.Title.Text = "A Secondary Y-Axis";
myAxisY.Title.Visible = true;
myAxisY.Title.TextColor = Color.Blue;
myAxisY.Label.TextColor = Color.Blue;
myAxisY.Color = Color.Blue;
// Add the chart to the form.
chartControl1.Dock = DockStyle.Fill;
this.Controls.Add(chartControl1);
}
Visual Basic
Imports
Imports
Imports
Imports
' ...
C opy C ode
System
System.Drawing
System.Windows.Forms
DevExpress.XtraCharts
753
Examples
754
Show Me
754
Examples
755
The complete sample project is available in the DevExpress Code Central database at http://w ww .devexpress.com/
example=E1244. Depending on the target platform type (ASP.NET, W inForms, etc), you can either run this example
online or dow nload an auto-executable sample.
See Also
Primary and Secondary Axes
755
Examples
756
C opy C ode
axes.
1"));
2"));
X-axis,
should stick.
Visual Basic
C opy C ode
' Cast the chart's diagram to the XYDiagram type, to access its axes.
Dim diagram As XYDiagram = CType(chartControl1.Diagram, XYDiagram)
' Add two custom labels to the X-axis' collection.
diagram.AxisX.CustomLabels.Add(New CustomAxisLabel("Custom Label 1"))
diagram.AxisX.CustomLabels.Add(New CustomAxisLabel("Custom Label 2"))
' Define their AxisValue. Since the custom labels belong to the X-axis,
' this property determines the series argument, to which labels should stick.
diagram.AxisX.CustomLabels(0).AxisValue = "B"
diagram.AxisX.CustomLabels(1).AxisValue = "D"
' Customize the custom labels' appearance.
diagram.AxisX.Label.TextColor = Color.Red
The result is show n in the following image.
Show Me
The complete sample project is available in the DevExpress Code Central database at http://w ww .devexpress.com/
example=E1359. Depending on the target platform type (ASP.NET, W inForms, etc), you can either run this example
online or dow nload an auto-executable sample.
See Also
Axis Labels
756
Examples
757
C opy C ode
C opy C ode
757
Examples
758
Show Me
The complete sample project is available in the DevExpress Code Central database at http://w ww .devexpress.com/
example=E1469. Depending on the target platform type (ASP.NET, W inForms, etc), you can either run this example
online or dow nload an auto-executable sample.
See Also
Axis Labels
758
Examples
759
C opy C ode
// Cast the chart's diagram to the XYDiagram type, to access its axes.
XYDiagram diagram = (XYDiagram)chartControl1.Diagram;
// Create a constant line.
ConstantLine constantLine1 = new ConstantLine("Constant Line 1");
diagram.AxisY.ConstantLines.Add(constantLine1);
// Define its axis value.
constantLine1.AxisValue = 7;
// Customize the behavior of the constant line.
constantLine1.Visible = true;
constantLine1.ShowInLegend = true;
constantLine1.LegendText = "Some Threshold";
constantLine1.ShowBehind = false;
// Customize the constant line's title.
constantLine1.Title.Visible = true;
constantLine1.Title.Text = "Constant Line Title";
constantLine1.Title.TextColor = Color.Red;
constantLine1.Title.Antialiasing = false;
constantLine1.Title.Font = new Font("Tahoma", 14, FontStyle.Bold);
constantLine1.Title.ShowBelowLine = true;
constantLine1.Title.Alignment = ConstantLineTitleAlignment.Far;
// Customize the appearance of the constant line.
constantLine1.Color = Color.Red;
constantLine1.LineStyle.DashStyle = DashStyle.Dash;
constantLine1.LineStyle.Thickness = 2;
Visual Basic
C opy C ode
' Cast the chart's diagram to the XYDiagram type, to access its axes.
Dim diagram As XYDiagram = CType(chartControl1.Diagram, XYDiagram)
' Create a constant line.
Dim constantLine1 As New ConstantLine("Constant Line 1")
diagram.AxisY.ConstantLines.Add(constantLine1)
' Define its axis value.
constantLine1.AxisValue = 7
' Customize the behavior of the constant line.
constantLine1.Visible = True
constantLine1.ShowInLegend = True
constantLine1.LegendText = "Some Threshold"
constantLine1.ShowBehind = False
' Customize the constant line's title.
constantLine1.Title.Visible = True
constantLine1.Title.Text = "Constant Line Title"
constantLine1.Title.TextColor = Color.Red
constantLine1.Title.Antialiasing = False
constantLine1.Title.Font = New Font("Tahoma", 14, FontStyle.Bold)
constantLine1.Title.ShowBelowLine = True
constantLine1.Title.Alignment = ConstantLineTitleAlignment.Far
' Customize the appearance of the constant line.
constantLine1.Color = Color.Red
constantLine1.LineStyle.DashStyle = DashStyle.Dash
constantLine1.LineStyle.Thickness = 2
The result is show n in the following image.
2013 DevExpress Inc.
759
Examples
760
Show Me
The complete sample project is available in the DevExpress Code Central database at http://w ww .devexpress.com/
example=E1370. Depending on the target platform type (ASP.NET, W inForms, etc), you can either run this example
online or dow nload an auto-executable sample.
See Also
Constant Lines
760
Examples
761
C opy C ode
// Cast the chart's diagram to the XYDiagram type, to access its axes.
XYDiagram diagram = (XYDiagram)chartControl1.Diagram;
// Create a strip with its maximum and minimum axis value defined.
diagram.AxisY.Strips.Add(new Strip("Strip 1", 5, 15));
// Customize the strip's behavior.
diagram.AxisY.Strips[0].Visible = true;
diagram.AxisY.Strips[0].ShowAxisLabel = true;
diagram.AxisY.Strips[0].AxisLabelText = "My Range";
diagram.AxisY.Strips[0].ShowInLegend = true;
diagram.AxisY.Strips[0].LegendText = "A Sample Strip";
// Customize the strip's appearance.
diagram.AxisY.Strips[0].Color = Color.CornflowerBlue;
diagram.AxisY.Strips[0].FillStyle.FillMode = FillMode.Empty;
Visual Basic
C opy C ode
' Cast the chart's diagram to the XYDiagram type, to access its axes.
Dim diagram As XYDiagram = CType(chartControl1.Diagram, XYDiagram)
' Create a strip with its maximum and minimum axis value defined.
diagram.AxisY.Strips.Add(new Strip("Strip 1", 5, 15))
' Customize the strip's behavior.
diagram.AxisY.Strips(0).Visible = True
diagram.AxisY.Strips(0).ShowAxisLabel = True
diagram.AxisY.Strips(0).AxisLabelText = "My Range"
diagram.AxisY.Strips(0).ShowInLegend = True
diagram.AxisY.Strips(0).LegendText = "A Sample Strip"
' Customize the strip's appearance.
diagram.AxisY.Strips(0).Color = Color.CornflowerBlue
diagram.AxisY.Strips(0).FillStyle.FillMode = FillMode.Empty
The result is show n in the following image.
Show Me
The complete sample project is available in the DevExpress Code Central database at http://w ww .devexpress.com/
example=E1369. Depending on the target platform type (ASP.NET, W inForms, etc), you can either run this example
online or dow nload an auto-executable sample.
See Also
Strips
761
Examples
762
To define the maximum number for automatic scale breaks, use the AutoScaleBreaks.MaxCount property.
In addition, you can use the Axis.ScaleBreakOptions property, to adjust the common appearance of both manual
and auto-created scale breaks.
Use the follow ing code, to enable automatic scale breaks at runtime.
C#
C opy C ode
C opy C ode
762
Examples
763
Show Me
The complete sample project is available in the DevExpress Code Central database at http://w ww .devexpress.com/
example=E1621. Depending on the target platform type (ASP.NET, W inForms, etc), you can either run this example
online or dow nload an auto-executable sample.
See Also
Scale Breaks
How to: Manually Insert a Scale Break into an Axis
How to: Manually Insert a Scale Break into an Axis (Runtime Sample)
763
Examples
764
4.This dialog allow s you to add new series to a chart, and maintain their properties. Click Add... and
select Bar from the list of view types.
764
Examples
765
5.To populate the created series w ith data points in this example, we'll use the following arguments and
values for the series. These values have a significant spread, and simultaneously represent decimals,
hundreds, and thousands.
Argument
Value
104
2006
108
2007
105
2009
765
Examples
766
As the image above demonstrates, the default look isn't very informative, since the points that
represent thousands occupy the most of the diagram, and the specifics of lesser values are obscured.
To improve that, we'll insert scale breaks into the axis of values (Y-axis) as a replacement for two
sparsely used regions (decimals - hundreds, and hundreds - thousands) with special strips, and the axis
range w ill be adjusted appropriately.
7.To do this, select the Y-axis, and in the Properties w indow, locate the Axis.ScaleBreaks property, and
click its ellipsis button, to invoke the Scale Break Collection Editor.
In this dialog, use the Add button to create two scale breaks. For the first scale break, set its
ScaleBreak.Edge1 and ScaleBreak.Edge2 properties to 10 and 100, correspondingly. And, for the
second scale break, set these properties to 110 and 2000.
Click Close, to quit the dialog, and apply the changes.
Our goal is achieved - the scale breaks are added to the axis. The result is shown in the following image.
766
Examples
767
Now, if required, you can customize the appearance of scale breaks, via the Axis.ScaleBreakOptions property. It
provides access to the following appearance settings (note that these settings affect all scale breaks at one time,
and don't allow you to individually access a scale break entry).
767
Examples
768
How to: Manually Insert a Scale Break into an Axis (Runtime Sample)
Charting > Examples > How to: Manually Insert a Scale Break into an Axis (Runtime Sample)
This example demonstrates how scale breaks can be created w ithin an axis, and customized at runtime.
C#
C opy C ode
C opy C ode
768
Examples
769
C opy C ode
(Form1.cs)
using System;
using System.Drawing;
using System.Windows.Forms;
using DevExpress.XtraCharts;
// ...
private void Form1_Load (object sender, EventArgs e) {
// Create an empty chart.
ChartControl stockChart = new ChartControl();
// Create a stock series, add it to the chart and set its properties.
Series series1 = new Series("Series 1", ViewType.Stock);
stockChart.Series.Add(series1);
series1.ArgumentScaleType = ScaleType.DateTime;
series1.ValueScaleType = ScaleType.Numerical;
// Add points to the series.
series1.Points.Add(new SeriesPoint(new DateTime(1994, 3, 1),
new object[] { 4.00, 5.00, 5.00, 4.85 }));
series1.Points.Add(new SeriesPoint(new DateTime(1994, 3, 2),
new object[] { 6.05, 8.05, 6.05, 7.05 }));
series1.Points.Add(new SeriesPoint(new DateTime(1994, 3, 3),
new object[] { 6.25, 8.25, 6.75, 7.15 }));
// Create and customize a trendline,
TrendLine trendline1 = new TrendLine("A Trend");
trendline1.Point1.Argument = new DateTime(1994, 3, 1);
trendline1.Point1.ValueLevel = ValueLevel.High;
trendline1.Point2.Argument = new DateTime(1994, 3, 3);
trendline1.Point2.ValueLevel = ValueLevel.High;
trendline1.ExtrapolateToInfinity = false;
trendline1.Color = Color.Red;
trendline1.LineStyle.DashStyle = DashStyle.Dash;
// Cast the view type of the series to the Stock view.
StockSeriesView myView = ((StockSeriesView)series1.View);
// Define the Y-axis range.
myView.AxisY.Range.AlwaysShowZeroLevel = false;
// Add the trendline to the series collection of indicators.
myView.Indicators.Add(trendline1);
// Add the chart to the form.
stockChart.Dock = DockStyle.Fill;
this.Controls.Add(stockChart);
}
Visual Basic
C opy C ode
(Form1.vb)
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports DevExpress.XtraCharts
' ...
Private Sub Form1_Load(ByVal sender As Object, _
769
Examples
770
ByVal e As EventArgs) Handles MyBase.Load
' Create an empty chart.
Dim stockChart As New ChartControl()
' Create a stock series, add it to the chart and set its properties.
Dim series1 As New Series("Series 1", ViewType.Stock)
stockChart.Series.Add(series1)
series1.ArgumentScaleType = ScaleType.DateTime
series1.ValueScaleType = ScaleType.Numerical
' Add points to the series.
series1.Points.Add(New SeriesPoint(New DateTime(1994, 3, 1), _
New Object() {4.0, 5.0, 5.0, 4.85}))
series1.Points.Add(New SeriesPoint(New DateTime(1994, 3, 2), _
New Object() {6.05, 8.05, 6.05, 7.05}))
series1.Points.Add(New SeriesPoint(New DateTime(1994, 3, 3), _
New Object() {6.25, 8.25, 6.75, 7.15}))
' Create and customize a trendline,
Dim trendline1 As New TrendLine("A Trend")
trendline1.Point1.Argument = New DateTime(1994, 3, 1)
trendline1.Point1.ValueLevel = ValueLevel.High
trendline1.Point2.Argument = New DateTime(1994, 3, 3)
trendline1.Point2.ValueLevel = ValueLevel.High
trendline1.ExtrapolateToInfinity = False
trendline1.Color = Color.Red
trendline1.LineStyle.DashStyle = DashStyle.Dash
' Cast the view type of the series to the Stock view.
Dim myView As StockSeriesView = (CType(series1.View, StockSeriesView))
' Define the Y-axis range.
myView.AxisY.Range.AlwaysShowZeroLevel = False
' Add the trendline to the series collection of indicators.
myView.Indicators.Add(trendline1)
' Add the chart to the form.
stockChart.Dock = DockStyle.Fill
Me.Controls.Add(stockChart)
End Sub
Show Me
The complete sample project is available in the DevExpress Code Central database at http://w ww .devexpress.com/
example=E1245. Depending on the target platform type (ASP.NET, W inForms, etc), you can either run this example
online or dow nload an auto-executable sample.
See Also
Trend Lines
770
Examples
771
2.Select the series in the Property Grid, expand its SeriesBase.View property and click the ellipsis button
for the XYDiagram2DSeriesViewBase.Indicators property.
In the invoked Indicators dialog, click the Add... button.
3.Then, in the Indicator Type dialog, choose the required Fibonacci indicator kind and click OK.
771
Examples
772
If required, you can change the kind later, via the FibonacciIndicator.Kind property.
4.Now , back in the Indicators dialog, define the arguments and values for the FinancialIndicator.Point1
and FinancialIndicator.Point2 properties, and adjust other options of the indicator.
For each kind of Fibonacci indicator, it is possible to display extra lines for the
the Fibonacci sequence. The set of these levels is unique for each kind.
implied by
The follow ing image demonstrates the resulting Fibonacci Arcs indicator.
772
Examples
773
Note that as w ith other indicators, all Fibonacci indicators that exist in a chart are painted based on the palette
defined via the ChartControl.IndicatorsPaletteName property.
Show Me
The complete sample project is available in the DevExpress Code Central database at http://w ww .devexpress.com/
example=E966. Depending on the target platform type (ASP.NET, WinForms, etc), you can either run this example
online or dow nload an auto-executable sample.
See Also
Fibonacci Indicators
How to: Add a Fibonacci Indicator to a Chart (Runtime Sample)
773
Examples
774
C opy C ode
(Form1.cs)
using System;
using System.Drawing;
using System.Windows.Forms;
using DevExpress.XtraCharts;
namespace FibonacciIndicators {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
#region Initialization
private void Form1_Load(object sender, EventArgs e) {
// Create a series.
Series series = new Series("Stock", ViewType.Stock);
series.ArgumentScaleType = ScaleType.DateTime;
// Populate the series with data.
AddPoints(series);
// Add it to the chart.
this.chartControl1.Series.Add(series);
// Adjust the chart's appearance.
XYDiagram diagram = (XYDiagram)this.chartControl1.Diagram;
diagram.AxisY.Range.AlwaysShowZeroLevel = false;
diagram.AxisX.Label.Staggered = true;
}
#endregion
#region Providing Data
private void AddPoints(Series series) {
series.Points.AddRange(new SeriesPoint[] {
new SeriesPoint(new DateTime(2007, 12, 24), new object[] {110.55, 112, 111.3, 111.65}),
new SeriesPoint(new DateTime(2007, 12, 26), new object[] {110.9, 112.09, 110.9, 111.56}
new SeriesPoint(new DateTime(2007, 12, 27), new object[] {109.49, 111.3, 110.53, 109.6
new SeriesPoint(new DateTime(2007, 12, 28), new object[] {109.108, 110.76, 110.76, 110.
new SeriesPoint(new DateTime(2007, 12, 31), new object[] {107.26, 110, 109.51, 108.1}),
new SeriesPoint(new DateTime(2008, 1, 2), new object[] {104.17, 108.99, 108.99, 104.69}
new SeriesPoint(new DateTime(2008, 1, 3), new object[] {103.98, 105.57, 104.83, 104.9})
new SeriesPoint(new DateTime(2008, 1, 4), new object[] {100.48, 103.95, 103.95, 101.13}
new SeriesPoint(new DateTime(2008, 1, 7), new object[] {99.03, 101, 100.25, 100.05}),
new SeriesPoint(new DateTime(2008, 1, 8), new object[] {97.17, 100.38, 100.05, 97.59}),
new SeriesPoint(new DateTime(2008, 1, 9), new object[] {97.16, 99.15, 97.76, 98.31}),
new SeriesPoint(new DateTime(2008, 1, 10), new object[] {97.15, 100.86, 97.39, 99.92}),
new SeriesPoint(new DateTime(2008, 1, 11), new object[] {97.09, 99.46, 99.2, 97.67}),
new SeriesPoint(new DateTime(2008, 1, 14), new object[] {101.33, 105.59, 105.01, 102.93
new SeriesPoint(new DateTime(2008, 1, 15), new object[] {101.23, 104.04, 102.03, 101.83
new SeriesPoint(new DateTime(2008, 1, 16), new object[] {100.14, 102.86, 100.14, 101.63
new SeriesPoint(new DateTime(2008, 1, 17), new object[] {100.05, 103.45, 102, 101.1}),
new SeriesPoint(new DateTime(2008, 1, 18), new object[] {102.5, 106.72, 106.72, 103.4})
new SeriesPoint(new DateTime(2008, 1, 22), new object[] {98.55, 103.09, 98.55, 101.22})
2013 DevExpress Inc.
774
Examples
775
new
new
new
new
new
new
new
});
SeriesPoint(new
SeriesPoint(new
SeriesPoint(new
SeriesPoint(new
SeriesPoint(new
SeriesPoint(new
SeriesPoint(new
DateTime(2008,
DateTime(2008,
DateTime(2008,
DateTime(2008,
DateTime(2008,
DateTime(2008,
DateTime(2008,
1,
1,
1,
1,
1,
1,
1,
23),
24),
25),
28),
29),
30),
31),
new
new
new
new
new
new
new
object[]
object[]
object[]
object[]
object[]
object[]
object[]
}
#endregion
#region Processing Button_Click
private void btnArcs_Click(object sender, EventArgs e) {
AddIndicator(chartControl1.Series[0], FibonacciIndicatorKind.FibonacciArcs);
}
private void btnFans_Click(object sender, EventArgs e) {
AddIndicator(chartControl1.Series[0], FibonacciIndicatorKind.FibonacciFans);
}
private void btnRetracements_Click(object sender, EventArgs e) {
AddIndicator(chartControl1.Series[0], FibonacciIndicatorKind.FibonacciRetracement);
}
#endregion
private void AddIndicator(Series ser, FibonacciIndicatorKind kind) {
// Get a collection of indicators.
IndicatorCollection indicators =
((StockSeriesView)ser.View).Indicators;
// Clear it.
indicators.Clear();
// Add a new indicator to it.
indicators.Add(CreateIndicator(kind, new DateTime(2007, 12, 27),
new DateTime(2008, 1, 17), ValueLevel.High));
}
private FibonacciIndicator CreateIndicator(FibonacciIndicatorKind kind,
DateTime arg1, DateTime arg2, ValueLevel level) {
// Create the Fibonacci Indicator of the specified kind.
FibonacciIndicator fi = new FibonacciIndicator(kind);
// Specify its start and end points.
fi.Point1.Argument = arg1;
fi.Point1.ValueLevel = level;
fi.Point2.Argument = arg2;
fi.Point2.ValueLevel = level;
// Select the name.
switch (fi.Kind) {
case FibonacciIndicatorKind.FibonacciArcs: {
fi.Name = "Arcs";
break;
}
case FibonacciIndicatorKind.FibonacciFans: {
fi.Name = "Fans";
break;
}
case FibonacciIndicatorKind.FibonacciRetracement: {
fi.Name = "Retracement";
break;
}
}
// Make all its levels visible.
fi.ShowLevel23_6 = true;
fi.ShowLevel76_4 = true;
fi.ShowLevel0 = true;
fi.ShowLevel100 = true;
fi.ShowAdditionalLevels = true;
2013 DevExpress Inc.
775
Examples
776
// Customize its appearance.
fi.BaseLevelColor = Color.Green;
fi.BaseLevelLineStyle.DashStyle = DashStyle.Dash;
return fi;
}
}
}
Visual Basic
C opy C ode
(Form1.vb)
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports DevExpress.XtraCharts
Namespace FibonacciIndicators
Partial Public Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
End Sub
#Region "Initialization"
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) _
Handles MyBase.Load
' Create a series.
Dim series As New Series("Stock", ViewType.Stock)
series.ArgumentScaleType = ScaleType.DateTime
' Populate the series with data.
AddPoints(series)
' Add it to the chart.
Me.chartControl1.Series.Add(series)
' Adjust the chart's appearance.
Dim diagram As XYDiagram = CType(Me.chartControl1.Diagram, XYDiagram)
diagram.AxisY.Range.AlwaysShowZeroLevel = False
diagram.AxisX.Label.Staggered = True
End Sub
#EndRegion
#Region "Providing Data"
Private Sub AddPoints(ByVal series As Series)
series.Points.AddRange(New SeriesPoint() { _
New SeriesPoint(New DateTime(2007, 12, 24), New Object() {110.55, 112, 111.3, 111.65}
New SeriesPoint(New DateTime(2007, 12, 26), New Object() {110.9, 112.09, 110.9, 111.5
New SeriesPoint(New DateTime(2007, 12, 27), New Object() {109.49, 111.3, 110.53, 109.
New SeriesPoint(New DateTime(2007, 12, 28), New Object() {109.108, 110.76, 110.76, 11
New SeriesPoint(New DateTime(2007, 12, 31), New Object() {107.26, 110, 109.51, 108.1}
New SeriesPoint(New DateTime(2008, 1, 2), New Object() {104.17, 108.99, 108.99, 104.6
New SeriesPoint(New DateTime(2008, 1, 3), New Object() {103.98, 105.57, 104.83, 104.9
New SeriesPoint(New DateTime(2008, 1, 4), New Object() {100.48, 103.95, 103.95, 101.1
New SeriesPoint(New DateTime(2008, 1, 7), New Object() {99.03, 101, 100.25, 100.05}),
New SeriesPoint(New DateTime(2008, 1, 8), New Object() {97.17, 100.38, 100.05, 97.59}
New SeriesPoint(New DateTime(2008, 1, 9), New Object() {97.16, 99.15, 97.76, 98.31}),
New SeriesPoint(New DateTime(2008, 1, 10), New Object() {97.15, 100.86, 97.39, 99.92}
New SeriesPoint(New DateTime(2008, 1, 11), New Object() {97.09, 99.46, 99.2, 97.67}),
New SeriesPoint(New DateTime(2008, 1, 14), New Object() {101.33, 105.59, 105.01, 102.
New SeriesPoint(New DateTime(2008, 1, 15), New Object() {101.23, 104.04, 102.03, 101.
New SeriesPoint(New DateTime(2008, 1, 16), New Object() {100.14, 102.86, 100.14, 101.
New SeriesPoint(New DateTime(2008, 1, 17), New Object() {100.05, 103.45, 102, 101.1})
New SeriesPoint(New DateTime(2008, 1, 18), New Object() {102.5, 106.72, 106.72, 103.4
New SeriesPoint(New DateTime(2008, 1, 22), New Object() {98.55, 103.09, 98.55, 101.22
New SeriesPoint(New DateTime(2008, 1, 23), New Object() {98.5, 106.335, 99.63, 106.1}
New SeriesPoint(New DateTime(2008, 1, 24), New Object() {104.68, 107.51, 106.38, 106.
New SeriesPoint(New DateTime(2008, 1, 25), New Object() {104.1, 107.79, 107.79, 104.5
2013 DevExpress Inc.
776
Examples
777
New
New
New
New
SeriesPoint(New
SeriesPoint(New
SeriesPoint(New
SeriesPoint(New
DateTime(2008,
DateTime(2008,
DateTime(2008,
DateTime(2008,
1,
1,
1,
1,
28),
29),
30),
31),
New
New
New
New
Object()
Object()
Object()
Object()
End Sub
#EndRegion
#Region "Processing Button_Click"
Private Sub btnArcs_Click(ByVal sender As Object, ByVal e As EventArgs) _
Handles btnArcs.Click
AddIndicator(chartControl1.Series(0), FibonacciIndicatorKind.FibonacciArcs)
End Sub
Private Sub btnFans_Click(ByVal sender As Object, ByVal e As EventArgs) _
Handles btnFans.Click
AddIndicator(chartControl1.Series(0), FibonacciIndicatorKind.FibonacciFans)
End Sub
Private Sub btnRetracements_Click(ByVal sender As Object, ByVal e As EventArgs) _
Handles btnRetracements.Click
AddIndicator(chartControl1.Series(0), FibonacciIndicatorKind.FibonacciRetracement)
End Sub
#EndRegion
Private Sub AddIndicator(ByVal ser As Series, ByVal kind As FibonacciIndicatorKind)
' Get a collection of indicators.
Dim indicators As IndicatorCollection = (CType(ser.View, StockSeriesView)).Indicators
' Clear it.
indicators.Clear()
' Add a new indicator to it.
indicators.Add(CreateIndicator(kind, New DateTime(2007, 12, 27), _
New DateTime(2008, 1, 17), ValueLevel.High))
End Sub
Private Function CreateIndicator(ByVal kind As FibonacciIndicatorKind, ByVal arg1 As DateTime, _
ByVal arg2 As DateTime, ByVal level As ValueLevel) As FibonacciIndicator
' Create the Fibonacci Indicator of the specified kind.
Dim fi As New FibonacciIndicator(kind)
' Specify its start and end points.
fi.Point1.Argument = arg1
fi.Point1.ValueLevel = level
fi.Point2.Argument = arg2
fi.Point2.ValueLevel = level
' Select the name.
Select Case fi.Kind
Case FibonacciIndicatorKind.FibonacciArcs
fi.Name = "Arcs"
Exit Select
Case FibonacciIndicatorKind.FibonacciFans
fi.Name = "Fans"
Exit Select
Case FibonacciIndicatorKind.FibonacciRetracement
fi.Name = "Retracement"
Exit Select
End Select
' Make all its levels visible.
fi.ShowLevel23_6 = True
fi.ShowLevel76_4 = True
fi.ShowLevel0 = True
fi.ShowLevel100 = True
fi.ShowAdditionalLevels = True
' Customize its appearance.
fi.BaseLevelColor = Color.Green
fi.BaseLevelLineStyle.DashStyle = DashStyle.Dash
Return fi
End Function
2013 DevExpress Inc.
777
Examples
778
End Class
End Namespace
See Also
Fibonacci Indicators
778
Examples
779
To show a Regression Line for a Stock chart follow the steps below .
1.Create a new or open an existing Stock chart. For this example w e w ill use the follow ing chart.
2.Select the series in the Property Grid, expand its SeriesBase.View property and click the ellipsis button
for the XYDiagram2DSeriesViewBase.Indicators property.
In the invoked Indicators dialog, click the Add... button.
3.Then, in the Indicator Type dialog, choose Regression Line and click OK.
779
Examples
780
4.Now , back in the Indicators dialog, you can specify the Regression Line's SingleLevelIndicator.
ValueLevel and other options.
780
Examples
781
Note that as w ith other indicators, all Regression Lines that exist in a chart are painted based on the palette
defined via the ChartControl.IndicatorsPaletteName property.
See Also
Regression Lines
How to: Show a Regression Line for a Stock Chart (Runtime Sample)
781
Examples
782
How to: Show a Regression Line for a Stock Chart (Runtime Sample)
Charting > Examples > How to: Show a Regression Line for a Stock Chart (Runtime Sample)
This example demonstrates how a Regression Line can be displayed for a series of the Stock view type.
To access the series' collection of indicators (via the XYDiagram2DSeriesViewBase.Indicators property), you should
cast your series view to an appropriate type.
C#
C opy C ode
C opy C ode
Show Me
The complete sample project is available in the DevExpress Code Central database at http://w ww .devexpress.com/
example=E1494. Depending on the target platform type (ASP.NET, W inForms, etc), you can either run this example
online or dow nload an auto-executable sample.
See Also
Regression Lines
782
Examples
783
3.In the invoked Annotation Collection Editor, click Add, and then double-click the Text Annotation type.
4.For the created annotation, click the ellipsis button for its Annotation.AnchorPoint property.
783
Examples
784
784
Examples
785
7.Now , the annotation has been anchored to that point, and back in the Annotation Collection Editor you
can adjust its text (TextAnnotation.Text) and position (Annotation.ShapePosition), as well as its
appearance options.
The result is show n in the following image.
See Also
How to: Create an Image Annotation Anchored to a Chart or Pane
785
Examples
786
2.In the invoked Annotation Collection Editor, click Add, and then double-click the Image Annotation
type.
3.For the created annotation, click the ellipsis button for its Annotation.AnchorPoint property.
786
Examples
787
5.And, define the X and Y coordinates (in pixels) for the annotation's anchor point. Note that these
coordinates are absolute, and w ill not be changed w hen the chart is resized.
787
Examples
788
6.Now , the annotation has been anchored to that point, and after you specify its image (
ImageAnnotation.Image) and position (Annotation.ShapePosition), the chart looks as follows.
8.Then, choose the pane, to w hich the annotation is anchored, and specify the axes, and their values for
2013 DevExpress Inc.
788
Examples
789
the anchor point.
9.After you specify the annotation's image (ImageAnnotation.Image) and position (Annotation.
ShapePosition), the chart looks as follow s.
Note that the pane anchor point sticks to the specified axes' coordinates when the chart is being
resized, or scrolled and zoomed.
See Also
How to: Create a Text Annotation Anchored to a Series Point
789
Examples
790
C opy C ode
(Form1.cs)
using System;
using System.Windows.Forms;
using DevExpress.XtraCharts;
namespace TextAnnotationRuntime {
public partial class Form1 : Form {
public Form1 () {
InitializeComponent();
}
private void Form1_Load (object sender, EventArgs e) {
SeriesPoint sp = this.chartControl1.Series["Series 1"].Points[1];
TextAnnotation annotation = new TextAnnotation("Annotation 1", "test");
annotation.AnchorPoint = new SeriesPointAnchorPoint(sp);
annotation.ShapePosition = new RelativePosition();
RelativePosition position = annotation.ShapePosition as RelativePosition;
position.ConnectorLength = 50;
position.Angle = 270;
annotation.RuntimeMoving = true;
this.chartControl1.AnnotationRepository.Add(annotation);
}
}
}
Visual Basic
C opy C ode
(Form1.vb)
Imports Microsoft.VisualBasic
Imports System
Imports System.Windows.Forms
Imports DevExpress.XtraCharts
Namespace TextAnnotationRuntime
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
Dim sp As SeriesPoint = Me.chartControl1.Series("Series 1").Points(1)
Dim annotation As New TextAnnotation("Annotation 1", "test")
annotation.AnchorPoint = New SeriesPointAnchorPoint(sp)
annotation.ShapePosition = New RelativePosition()
Dim position As RelativePosition = TryCast(annotation.ShapePosition, RelativePosition)
position.ConnectorLength = 50
position.Angle = 270
annotation.RuntimeMoving = True
Me.chartControl1.AnnotationRepository.Add(annotation)
End Sub
End Class
End Namespace
790
Examples
791
End-User Interaction
How to: Determine which Chart Element Is Hovered by the Mouse
Pointer
Charting > Examples > How to: Determine which Chart Element Is Hovered by the Mouse Pointer
The follow ing examples demonstrates how to handle the ChartControl.MouseMove event and calculate the hit
information for the point w hich the mouse pointer is currently hovering over. Then, the name of the chart element
located under the mouse pointer is shown within the form caption.
C#
C opy C ode
using System.Windows.Forms;
using DevExpress.XtraCharts;
// ...
private void chartControl1_MouseMove(object sender, MouseEventArgs e) {
ChartHitInfo hi = chartControl1.CalcHitInfo(new System.Drawing.Point(e.X, e.Y));
this.Text = hi.HitTest.ToString();
}
Visual Basic
C opy C ode
Imports System.Windows.Forms
Imports DevExpress.XtraCharts
' ...
Private Sub ChartControl1_MouseMove(ByVal sender As System.Object, ByVal e As MouseEventArgs) _
Handles ChartControl1.MouseMove
Dim hi As ChartHitInfo = ChartControl1.CalcHitInfo(New System.Drawing.Point(e.X, e.Y))
Me.Text = hi.HitTest.ToString()
End Sub
See Also
How to: Show Series Labels Only for Hot-tracked Points
How to: Determine w hich Series Point Is Located Under the Test Point
791
Examples
792
How to: Determine which Series Point Is Located Under the Test Point
Charting > Examples > How to: Determine which Series Point Is Located Under the Test Point
Show Me
The complete sample project is available in the DevExpress Code Central database at http://w ww .devexpress.com/
example=E2717. Depending on the target platform type (ASP.NET, W inForms, etc), you can either run this example
online or dow nload an auto-executable sample.
This example demonstrates how to handle the ChartControl.MouseMove event, to determine w hich series point
is located under the test point and display information about its argument and value using ToolTipController.
To enable hit testing at runtime so that this example w orks correctly, make sure that the ChartControl.
RuntimeHitTesting property is set to true.
C#
C opy C ode
(Form1.cs)
using System;
using System.Windows.Forms;
using DevExpress.Utils;
using DevExpress.XtraCharts;
// ...
private void Form1_Load(object sender, EventArgs e) {
chartControl1.CrosshairEnabled = DefaultBoolean.False;
chartControl1.RuntimeHitTesting = true;
}
private void chartControl1_MouseMove(object sender, MouseEventArgs e) {
// Obtain hit information under the test point.
ChartHitInfo hi = chartControl1.CalcHitInfo(e.X, e.Y);
// Obtain the series point under the test point.
SeriesPoint point = hi.SeriesPoint;
// Check whether the series point was clicked or not.
if (point != null) {
// Obtain the series point argument.
string argument = "Argument: " + point.Argument.ToString();
// Obtain series point values.
string values = "Value(s): " + point.Values[0].ToString();
if (point.Values.Length > 1) {
for (int i = 1; i < point.Values.Length; i++) {
values = values + ", " + point.Values[i].ToString();
}
}
// Show the tooltip.
toolTipController1.ShowHint(argument + "\n" + values, "SeriesPoint Data");
}
else {
// Hide the tooltip.
toolTipController1.HideHint();
}
}
Visual Basic
C opy C ode
(Form1.vb)
Imports System
Imports System.Windows.Forms
Imports Microsoft.VisualBasic
Imports DevExpress.Utils
Imports DevExpress.XtraCharts
' ...
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) _
Handles MyBase.Load
chartControl1.CrosshairEnabled = DefaultBoolean.False
2013 DevExpress Inc.
792
Examples
793
chartControl1.RuntimeHitTesting = True
End Sub
Private Sub chartControl1_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) _
Handles chartControl1.MouseMove
' Obtain hit information under the test point.
Dim hi As ChartHitInfo = chartControl1.CalcHitInfo(e.X, e.Y)
' Obtain the series point under the test point.
Dim point As SeriesPoint = hi.SeriesPoint
' Check whether the series point was clicked or not.
If point IsNot Nothing Then
' Obtain the series point argument.
Dim argument As String = "Argument: " & point.Argument.ToString()
' Obtain series point values.
Dim values As String = "Value(s): " & point.Values(0).ToString()
If point.Values.Length > 1 Then
For i As Integer = 1 To point.Values.Length - 1
values = values & ", " & point.Values(i).ToString()
Next i
End If
' Show the tooltip.
toolTipController1.ShowHint(argument & Constants.vbLf & values, "SeriesPoint Data")
Else
' Hide the tooltip.
toolTipController1.HideHint()
End If
End Sub
The ChartControl.HitTest method cannot be used for that purpose since it returns the ChartElement clicked by the
mouse. The SeriesPoint object is not a chart element, w hile the Series, XYDiagram, ChartControl are.
The result is show n in the following image.
See Also
ChartControl.CalcHitInfo
ChartHitInfo.HitTest
HotTrackEventArgs.HitInfo
How to: Show Series Labels Only for Hot-tracked Points
793
Examples
794
C opy C ode
using System;
using System.Data;
using System.Windows.Forms;
using DevExpress.XtraCharts;
using DevExpress.Utils;
// ...
private void chartControl1_ObjectHotTracked(object sender, HotTrackEventArgs e) {
SeriesPoint point = e.AdditionalObject as SeriesPoint;
if (point != null) {
DataRowView rowView = (DataRowView)point.Tag;
string s = "Unit price = " + rowView["UnitPrice"].ToString() +
"\r\nUnits in stock = " + rowView["UnitsInStock"].ToString() +
"\r\nQuantity per unit = " + rowView["QuantityPerUnit"].ToString();
toolTipController1.ShowHint(s);
}
else
toolTipController1.HideHint();
}
Visual Basic
C opy C ode
Imports Microsoft.VisualBasic
Imports System
Imports System.Data
Imports System.Windows.Forms
Imports DevExpress.XtraCharts
Imports DevExpress.Utils
' ...
Private Sub chartControl1_ObjectHotTracked(ByVal sender As Object, ByVal e As HotTrackEventArgs) _
Handles chartControl1.ObjectHotTracked
Dim point As SeriesPoint = TryCast(e.AdditionalObject, SeriesPoint)
If Not point Is Nothing Then
Dim rowView As DataRowView = CType(point.Tag, DataRowView)
Dim s As String = "Unit price = " & rowView("UnitPrice").ToString() & Constants.vbCrLf & _
"Units in stock = " & rowView("UnitsInStock").ToString() & Constants.vbCrLf & _
"Quantity per unit = " & rowView("QuantityPerUnit").ToString()
toolTipController1.ShowHint(s)
Else
toolTipController1.HideHint()
End If
End Sub
794
Examples
795
The result of executing this code is shown in the follow ing image.
Show Me
The complete sample project is available in the DevExpress Code Central database at http://w ww .devexpress.com/
example=E126. Depending on the target platform type (ASP.NET, WinForms, etc), you can either run this example
online or dow nload an auto-executable sample.
See Also
How to:
How to:
How to:
How to:
795
Examples
796
C opy C ode
(Form1.cs)
using System;
using System.Windows.Forms;
using DevExpress.XtraCharts;
// ...
SeriesPoint m_HotTrackedPoint;
void chartControl1_ObjectHotTracked(object sender, HotTrackEventArgs e) {
SeriesPoint point = e.AdditionalObject as SeriesPoint;
if (!Object.ReferenceEquals(point, m_HotTrackedPoint)) {
m_HotTrackedPoint = point;
chartControl1.Refresh();
}
}
void chartControl1_CustomDrawSeriesPoint(object sender, CustomDrawSeriesPointEventArgs e) {
e.LabelText = "";
if (e.SeriesPoint == m_HotTrackedPoint) {
e.LabelText = e.SeriesPoint.Values[0].ToString();
}
}
Visual Basic
C opy C ode
(Form1.vb)
Imports System
Imports System.Windows.Forms
Imports DevExpress.XtraCharts
' ...
Private m_HotTrackedPoint As SeriesPoint
Private Sub chartControl1_ObjectHotTracked(ByVal sender As Object, _
ByVal e As HotTrackEventArgs) Handles chartControl1.ObjectHotTracked
Dim point As SeriesPoint = TryCast(e.AdditionalObject, SeriesPoint)
If (Not Object.ReferenceEquals(point, m_HotTrackedPoint)) Then
m_HotTrackedPoint = point
chartControl1.Refresh()
End If
End Sub
Private Sub chartControl1_CustomDrawSeriesPoint(ByVal sender As Object, _
ByVal e As CustomDrawSeriesPointEventArgs) Handles chartControl1.CustomDrawSeriesPoint
e.LabelText = ""
If e.SeriesPoint Is m_HotTrackedPoint Then
e.LabelText = e.SeriesPoint.Values(0).ToString()
End If
End Sub
The result is show n in the following image.
796
Examples
See Also
How to:
How to:
How to:
How to:
797
797
Examples
798
C opy C ode
using DevExpress.XtraCharts;
// ...
private void chartControl1_ObjectHotTracked(object sender, HotTrackEventArgs e) {
// Prevent the chart's diagram from being hot-tracked.
if (e.Object is Diagram)
e.Cancel = true;
}
private void chartControl1_ObjectSelected(object sender, HotTrackEventArgs e) {
// Prevent the chart's Diagram from being selected.
if (e.Object is Diagram)
e.Cancel = true;
}
Visual Basic
C opy C ode
Imports DevExpress.XtraCharts
' ...
Private Sub OnObjectHotTracked(sender As Object, e As HotTrackEventArgs) _
Handles ChartControl1.ObjectHotTracked
' Prevent the chart's Diagram from being hot-tracked.
If TypeOf e.Object Is Diagram Then
e.Cancel = True
End If
End Sub
Private Sub OnObjectSelected(sender As Object, e As HotTrackEventArgs) _
Handles ChartControl1.ObjectSelected
' Prevent the chart's Diagram from being selected.
If TypeOf e.Object Is Diagram Then
e.Cancel = True
End If
End Sub
See Also
How to: Show Series Labels Only for Hot-tracked Points
How to: Determine w hich Series Point Is Located Under the Test Point
How to: Determine w hich Chart Element Is Hovered by the Mouse Pointer
798
Examples
799
C opy C ode
(Form1.cs)
using System;
using System.Windows.Forms;
using DevExpress.XtraCharts;
// ...
private void chartControl1_QueryCursor(object sender, QueryCursorEventArgs e) {
if (e.CursorType == CursorType.Hand || e.CursorType == CursorType.Grab) {
e.Cursor = Cursors.Default;
}
}
Visual Basic
C opy C ode
(Form1.vb)
Imports System
Imports System.Windows.Forms
Imports DevExpress.XtraCharts
' ...
Private Sub chartControl1_QueryCursor(ByVal sender As Object, _
ByVal e As QueryCursorEventArgs) Handles chartControl1.QueryCursor
If e.CursorType = CursorType.Hand OrElse e.CursorType = CursorType.Grab Then
e.Cursor = Cursors.Default
End If
End Sub
The follow ing images demonstrate how this works.
Default Cursor
Custom Cursor
799
Examples
800
C opy C ode
using System.Windows.Forms;
using DevExpress.XtraCharts;
// ...
static int lastY = -1;
static bool isPressed = false;
static SeriesPoint selectedPoint = null;
private void chartControl1_ObjectHotTracked(object sender, HotTrackEventArgs e) {
if(e.HitInfo.SeriesPoint != null)
selectedPoint = e.HitInfo.SeriesPoint;
if(selectedPoint != null && isPressed) {
DiagramCoordinates point =
((XYDiagram)(sender as ChartControl).Diagram).PointToDiagram(e.HitInfo.HitPoint);
if(lastY != -1) {
AxisRange range = ((XYDiagram)(sender as ChartControl).Diagram).AxisY.Range;
double delta = ((double)range.MaxValue - (double)range.MinValue) / 8;
if(selectedPoint.Values[0] >= (double)range.MaxValue - delta)
range.MaxValue = selectedPoint.Values[0] + delta;
selectedPoint.Values[0] = point.NumericalValue;
if(point.QualitativeArgument != "")
selectedPoint.Argument = point.QualitativeArgument;
}
((ChartControl)sender).RefreshData();
lastY = e.HitInfo.HitPoint.Y;
return;
}
lastY = -1;
}
private void chartControl1_MouseDown(object sender, MouseEventArgs e) {
isPressed = true;
}
private void chartControl1_MouseUp(object sender, MouseEventArgs e) {
isPressed = false;
}
private void chartControl1_MouseLeave(object sender, EventArgs e) {
isPressed = false;
}
Visual Basic
C opy C ode
Imports System.Windows.Forms
Imports DevExpress.XtraCharts
' ...
Private Shared lastY As Integer = -1
Private Shared isPressed As Boolean = False
Private Shared selectedPoint As SeriesPoint = Nothing
Private Sub chartControl1_ObjectHotTracked(ByVal sender As Object, _
ByVal e As HotTrackEventArgs) Handles chartControl1.ObjectHotTracked
If e.HitInfo.SeriesPoint IsNot Nothing Then
selectedPoint = e.HitInfo.SeriesPoint
End If
If selectedPoint IsNot Nothing AndAlso isPressed Then
Dim point As DiagramCoordinates = _
(CType((TryCast(sender, ChartControl)).Diagram, _
800
Examples
801
XYDiagram)).PointToDiagram(e.HitInfo.HitPoint)
If lastY <> -1 Then
Dim range As AxisRange = _
(CType((TryCast(sender, ChartControl)).Diagram, XYDiagram)).AxisY.Range
Dim delta As Double = (CDbl(range.MaxValue) - CDbl(range.MinValue)) / 8
If selectedPoint.Values(0) >= CDbl(range.MaxValue) - delta Then
range.MaxValue = selectedPoint.Values(0) + delta
End If
selectedPoint.Values(0) = point.NumericalValue
If point.QualitativeArgument <> "" Then
selectedPoint.Argument = point.QualitativeArgument
End If
End If
CType(sender, ChartControl).RefreshData()
lastY = e.HitInfo.HitPoint.Y
Return
End If
lastY = -1
End Sub
Private Sub chartControl1_MouseDown(ByVal sender As Object, _
ByVal e As MouseEventArgs) Handles chartControl1.MouseDown
isPressed = True
End Sub
Private Sub chartControl1_MouseUp(ByVal sender As Object, _
ByVal e As MouseEventArgs) Handles chartControl1.MouseUp
isPressed = False
End Sub
Private Sub chartControl1_MouseLeave(ByVal sender As Object, _
ByVal e As MouseEventArgs) Handles chartControl1.MouseLeave
isPressed = False
End Sub
Show Me
The complete sample project is available in the DevExpress Code Central database at http://w ww .devexpress.com/
example=E294. Depending on the target platform type (ASP.NET, WinForms, etc), you can either run this example
online or dow nload an auto-executable sample.
See Also
How to: Determine w hich Series Point Is Located Under the Test Point
How to: Provide Interactive Editing for a Constant Line
How to: Show Series Labels Only for Hot-tracked Points
801
Examples
802
C opy C ode
using System;
using System.Drawing;
using System.Windows.Forms;
using DevExpress.XtraCharts;
// ...
Cursor defCursor;
bool dragging = false;
ChartControl chart;
XYDiagram diagram;
ConstantLine line;
private void Form1_Load(object sender, EventArgs e) {
this.chart = this.chartControl1;
this.diagram = (XYDiagram)this.chart.Diagram;
this.line = this.diagram.AxisX.ConstantLines.GetConstantLineByName("ConstantLine1");
}
private void chartControl1_MouseDown(object sender, MouseEventArgs e) {
if(diagram == null)
return;
// Get the information about the clicked point.
DiagramCoordinates coords = diagram.PointToDiagram(e.Location);
// If the point is within the diagram and in the constant line ...
if(!coords.IsEmpty && line.AxisValue is DateTime &&
coords.DateTimeArgument.Equals((DateTime)line.AxisValue)) {
// Allow dragging, catch the mouse and change the cursor.
dragging = true;
chart.Capture = true;
SetCursor();
}
}
private void chartControl1_MouseUp(object sender, MouseEventArgs e) {
dragging = false;
chart.Capture = false;
}
private void chartControl1_MouseMove(object sender, MouseEventArgs e) {
if(diagram == null)
return;
if(dragging && (e.Button & MouseButtons.Left) == 0) {
dragging = false;
chart.Capture = false;
}
DiagramCoordinates coords = diagram.PointToDiagram(e.Location);
if(coords.IsEmpty)
RestoreCursor();
else {
if(dragging)
line.AxisValue = coords.DateTimeArgument;
if(line.AxisValue is DateTime && coords.DateTimeArgument.Equals((DateTime)line.AxisValue))
SetCursor();
else
RestoreCursor();
}
}
void SetCursor() {
802
Examples
803
if(defCursor == null)
defCursor = Cursor.Current;
Cursor.Current = Cursors.VSplit;
}
void RestoreCursor() {
if(defCursor != null) {
Cursor.Current = defCursor;
defCursor = null;
}
}
Visual Basic
C opy C ode
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports DevExpress.XtraCharts
' ...
Private defCursor As Cursor
Private dragging As Boolean = False
Private chart As ChartControl
Private diagram As XYDiagram
Private line As ConstantLine
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
Me.chart = Me.chartControl1
Me.diagram = CType(Me.chart.Diagram, XYDiagram)
Me.line = Me.diagram.AxisX.ConstantLines.GetConstantLineByName("ConstantLine1")
End Sub
Private Sub chartControl1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) _
Handles chartControl1.MouseDown
If diagram Is Nothing Then
Return
End If
' Get the information about the clicked point.
Dim coords As DiagramCoordinates = diagram.PointToDiagram(e.Location)
' If the point is within the diagram and in the constant line ...
If (Not coords.IsEmpty) AndAlso TypeOf line.AxisValue Is DateTime _
AndAlso coords.DateTimeArgument.Equals(CDate(line.AxisValue)) Then
' Allow dragging, catch the mouse and change the cursor.
dragging = True
chart.Capture = True
SetCursor()
End If
End Sub
Private Sub chartControl1_MouseUp(ByVal sender As Object, ByVal e As MouseEventArgs) _
Handles chartControl1.MouseUp
dragging = False
chart.Capture = False
End Sub
Private Sub chartControl1_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) _
Handles chartControl1.MouseMove
If diagram Is Nothing Then
Return
End If
If dragging AndAlso (e.Button And MouseButtons.Left) = 0 Then
dragging = False
chart.Capture = False
End If
Dim coords As DiagramCoordinates = diagram.PointToDiagram(e.Location)
If coords.IsEmpty Then
RestoreCursor()
Else
2013 DevExpress Inc.
803
Examples
804
If dragging Then
line.AxisValue = coords.DateTimeArgument
End If
If TypeOf line.AxisValue Is DateTime _
AndAlso coords.DateTimeArgument.Equals(CDate(line.AxisValue)) Then
SetCursor()
Else
RestoreCursor()
End If
End If
End Sub
Private Sub SetCursor()
If defCursor Is Nothing Then
defCursor = Cursor.Current
End If
Cursor.Current = Cursors.VSplit
End Sub
Private Sub RestoreCursor()
If defCursor IsNot Nothing Then
Cursor.Current = defCursor
defCursor = Nothing
End If
End Sub
Show Me
The complete sample project is available in the DevExpress Code Central database at http://w ww .devexpress.com/
example=E1003. Depending on the target platform type (ASP.NET, W inForms, etc), you can either run this example
online or dow nload an auto-executable sample.
See Also
Constant Lines
How to: Add a Constant Line to an Axis
How to: Provide Interactive Editing for Series Points
How to: Show Series Labels Only for Hot-tracked Points
804
Examples
805
In this dialog, click Add..., to create the first series of the Pie view type.
Switch to the dialog's Properties tab, and for this series, set the Series.DataSource property to
salesPersonBindingSource, SeriesBase.ArgumentDataMember property to SalesPerson, and the
SeriesBase.SummaryFunction to SUM([Extended Price]).
5.Now , add the second series - of the Bar view type. You'll see the red notification informing you that this
view is incompatible with the first visible series in the collection. So, leave the SeriesBase.Visible
property of this series disabled - we'll replace both series later in code.
The same as for the first series, set its Series.DataSource property to salesPersonBindingSource,
SeriesBase.ArgumentDataMember property to CategoryName, and SeriesBase.SummaryFunction - to
2013 DevExpress Inc.
805
Examples
806
SUM([Extended Price]).
In addition, via the SeriesBase.DataFilters property of the Bar series, specify a data filter, whose
DataFilter.ColumnName property is set to SalesPerson.
C opy C ode
using System;
using System.Drawing;
using System.Windows.Forms;
using DevExpress.XtraCharts;
// ...
private void chartControl1_MouseClick(object sender, MouseEventArgs e) {
// Obtain the object being clicked.
ChartHitInfo hi = chartControl1.CalcHitInfo(e.X, e.Y);
// Check whether it was a series point, and if so // obtain its argument, and pass it to the detail series.
SeriesPoint point = hi.SeriesPoint;
if (point != null) {
string argument = point.Argument.ToString();
// Flip the series.
if (chartControl1.Series[0].Visible == true) {
chartControl1.Series[0].Visible = false;
chartControl1.Series[1].Name = argument;
chartControl1.Series[1].Visible = true;
// Since the new series determines another diagram's type,
// you should re-define the axes properties.
XYDiagram diagram = (XYDiagram)chartControl1.Diagram;
diagram.AxisX.Label.Angle = -25;
diagram.AxisY.NumericOptions.Format = NumericFormat.Currency;
diagram.AxisY.NumericOptions.Precision = 0;
chartControl1.Series[1].DataFilters[0].Value = argument;
chartControl1.Titles[0].Visible = true;
chartControl1.Titles[1].Text = "Personal Sales by Categories";
}
}
// Obtain the title under the test point.
ChartTitle link = hi.ChartTitle;
// Check whether the link was clicked, and if so // restore the main series.
if (link != null && link.Text.StartsWith("Back")) {
chartControl1.Series[0].Visible = true;
chartControl1.Series[1].Visible = false;
link.Visible = false;
chartControl1.Titles[1].Text = "Sales by Person";
}
}
806
Examples
Visual Basic
807
C opy C ode
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports DevExpress.XtraCharts
' ...
Private Sub chartControl1_MouseClick(ByVal sender As Object, _
ByVal e As MouseEventArgs) Handles chartControl1.MouseClick
' Obtain the object being clicked.
Dim hi As ChartHitInfo = chartControl1.CalcHitInfo(e.X, e.Y)
' Check whether it was a series point, and if so ' obtain its argument, and pass it to the detail series.
Dim point As SeriesPoint = hi.SeriesPoint
If point IsNot Nothing Then
Dim argument As String = point.Argument.ToString()
' Flip the series.
If chartControl1.Series(0).Visible = True Then
chartControl1.Series(0).Visible = False
chartControl1.Series(1).Name = argument
chartControl1.Series(1).Visible = True
' Since the new series determines another diagram's type,
' you should re-define axes properties.
Dim diagram As XYDiagram = CType(chartControl1.Diagram, XYDiagram)
diagram.AxisX.Label.Angle = -25
diagram.AxisY.NumericOptions.Format = NumericFormat.Currency
diagram.AxisY.NumericOptions.Precision = 0
chartControl1.Series(1).DataFilters(0).Value = argument
chartControl1.Titles(0).Visible = True
chartControl1.Titles(1).Text = "Personal Sales by Categories"
End If
End If
' Obtain the title under the test point.
Dim link As ChartTitle = hi.ChartTitle
' Check whether the link was clicked, and if so ' restore the main series.
If link IsNot Nothing AndAlso link.Text.StartsWith("Back") Then
chartControl1.Series(0).Visible = True
chartControl1.Series(1).Visible = False
link.Visible = False
chartControl1.Titles(1).Text = "Sales by Person"
End If
End Sub
Get the Result
The result is show n in the following image.
807
Examples
808
See Also
How to: Determine w hich Series Point Is Located Under the Test Point
808
Examples
809
How to: Make a Diagram Scrollable and Limit the Scrolling Range of Its
Axis
Charting > Examples > How to: Make a Diagram Scrollable and Limit the Scrolling Range of Its Axis
This tutorial demonstrates how the axis visible and scrolling ranges can be limited, so that a user can access only
a part of a chart's underlying data.
Show Me
The complete sample project is available in the DevExpress Code Central database at http://w ww .devexpress.com/
example=E1383. Depending on the target platform type (ASP.NET, W inForms, etc), you can either run this example
online or dow nload an auto-executable sample.
To specify both the
and
1.Create a new chart, or open an existing one. For this example, w e'll use a simple XY-chart shown in the
following image.
2.Select the X-axis of your chart's diagram, and in the Properties w indow, expand its AxisBase.Range
property.
Limit the visible range of the X-axis by its two outermost values, via the AxisRange.MinValue and
AxisRange.MaxValue properties. Note that w hen changing either of these properties, the AxisRange.
Auto property is automatically set to false.
Where the qualitative, or date-time axis scale type is used, it's more convenient to limit the axis range
using the internal float representation of axis values, via the AxisRange.MinValueInternal and
AxisRange.MaxValueInternal properties. The same applies when it's required to limit the visible range of
an axis not strictly by its values, but betw een them.
809
Examples
810
To define the space remaining after the axis' ultimate value, you can use the AxisRange.
SideMarginsEnabled property. Note that enabling this option restricts the precision of the AxisRange.
MinValueInternal and AxisRange.MaxValueInternal properties, since there is an uncertainty in the axis
span which is occupied by the side-margins.
3.Now , we can allow end users to scroll the diagram along the limited X-axis, to access the series points
that are out of view. To do this, enable the XYDiagram2D.EnableAxisXScrolling property. After this, if the
XYDiagramPaneBase.EnableAxisXScrolling property of the corresponding pane is also enabled (or, set to
the default value), a scroll bar appears along the X-axis.
4.Finally, you can also restrict the scrolling range, making the points out of this range completely
inaccessible by an end user.
To do this, select the X-axis, and in the Properties w indow, expand the AxisBase.Range property. In it,
also expand the AxisRange.ScrollingRange property. You will see a set of properties identical to the set
of the axis visible range options.
So, to limit the scrolling range, specify the ScrollingRange.MinValue and ScrollingRange.MaxValue (or,
ScrollingRange.MinValueInternal and ScrollingRange.MaxValueInternal) properties. Again, after you
define any of these properties, the ScrollingRange.Auto property is automatically disabled.
810
Examples
811
811
Examples
812
C opy C ode
using System.Windows.Forms;
using DevExpress.Utils;
using DevExpress.XtraCharts;
// ...
private void Form1_Load(object sender, EventArgs e) {
// Cast the chart's diagram to the XYDiagram type, to access its axes.
XYDiagram diagram = (XYDiagram)chartControl1.Diagram;
// Define the visible range for the axes.
diagram.AxisY.Range.Auto = false;
diagram.AxisY.Range.SetInternalMinMaxValues(2, 6);
diagram.AxisX.Range.Auto = false;
diagram.AxisX.Range.SetInternalMinMaxValues(2, 4);
diagram.SecondaryAxesX[0].Range.Auto = false;
diagram.SecondaryAxesX[0].Range.SetInternalMinMaxValues(2, 4);
// Specify the axes scrolling at the diagram's level.
diagram.EnableAxisXScrolling = true;
diagram.EnableAxisYScrolling = false;
// Individually specify the axes scrolling for the panes.
diagram.DefaultPane.EnableAxisXScrolling = DefaultBoolean.Default;
diagram.Panes[0].EnableAxisXScrolling = DefaultBoolean.False;
// Adjust how the scrolling can be performed.
diagram.ScrollingOptions.UseKeyboard = false;
diagram.ScrollingOptions.UseMouse = false;
diagram.ScrollingOptions.UseScrollBars = true;
}
Visual Basic
C opy C ode
Imports System.Windows.Forms
Imports DevExpress.Utils
Imports DevExpress.XtraCharts
' ...
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As EventArgs) Handles MyBase.Load
' Cast the chart's diagram to the XYDiagram type, to access its axes.
Dim diagram As XYDiagram = CType(chartControl1.Diagram, XYDiagram)
' Define the visible range for the axes.
diagram.AxisY.Range.Auto = False
diagram.AxisY.Range.SetInternalMinMaxValues(2, 6)
diagram.AxisX.Range.Auto = False
diagram.AxisX.Range.SetInternalMinMaxValues(2, 4)
diagram.SecondaryAxesX(0).Range.Auto = False
diagram.SecondaryAxesX(0).Range.SetInternalMinMaxValues(2, 4)
' Specify the axes scrolling at the diagram's level.
diagram.EnableAxisXScrolling = True
diagram.EnableAxisYScrolling = False
' Individually specify the axes scrolling for the panes.
diagram.DefaultPane.EnableAxisXScrolling = DefaultBoolean.Default
diagram.Panes(0).EnableAxisXScrolling = DefaultBoolean.False
' Adjust how the scrolling can be performed.
diagram.ScrollingOptions.UseKeyboard = False
diagram.ScrollingOptions.UseMouse = False
diagram.ScrollingOptions.UseScrollBars = True
End Sub
812
Examples
813
See Also
How to: Make a Diagram Scrollable and Limit the Scrolling Range of Its Axis
How to: Individually Adjust Axes Zooming (Runtime Sample)
How to: Customize the Appearance of a Pane's Scroll Bar (Runtime Sample)
813
Examples
814
C opy C ode
using System.Windows.Forms;
using DevExpress.Utils;
using DevExpress.XtraCharts;
// ...
private void Form1_Load(object sender, EventArgs e) {
// Cast the chart's diagram to the XYDiagram type, to access its panes.
XYDiagram diagram = (XYDiagram)chartControl1.Diagram;
// Enable the X-axis zooming at the diagram's level.
diagram.EnableAxisXZooming = true;
// Individually enable zooming for panes.
diagram.DefaultPane.EnableAxisXZooming = DefaultBoolean.True;
diagram.Panes[0].EnableAxisXZooming = DefaultBoolean.False;
// Specify how zooming is performed.
diagram.ZoomingOptions.UseKeyboard = false;
diagram.ZoomingOptions.UseKeyboardWithMouse = true;
diagram.ZoomingOptions.UseMouseWheel = true;
}
Visual Basic
C opy C ode
Imports System.Windows.Forms
Imports DevExpress.Utils
Imports DevExpress.XtraCharts
' ...
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As EventArgs) Handles MyBase.Load
' Cast the chart's diagram to the XYDiagram type, to access its panes.
Dim diagram As XYDiagram = CType(chartControl1.Diagram, XYDiagram)
' Enable the X-axis zooming at the diagram's level.
diagram.EnableAxisXZooming = True
' Individually enable zooming for panes.
diagram.DefaultPane.EnableAxisXZooming = DefaultBoolean.True
diagram.Panes(0).EnableAxisXZooming = DefaultBoolean.False
' Specify how zooming is performed.
diagram.ZoomingOptions.UseKeyboard = False
diagram.ZoomingOptions.UseKeyboardWithMouse = True
diagram.ZoomingOptions.UseMouseWheel = True
End Sub
See Also
How to: Individually Adjust Axes Scrolling (Runtime Sample)
814
Examples
815
C opy C ode
using System.Windows.Forms;
using DevExpress.XtraCharts;
using DevExpress.XtraCharts.Wizard;
// ...
// Create a chart.
ChartControl chart = new ChartControl();
// Set its data source.
// You can set any other specific options for the chart here.
chart.DataSource = dataSet11;
// Create a ChartWizard for a new ChartControl
ChartWizard wiz = new ChartWizard(chart);
// Invoke the chart's wizard.
wiz.ShowDialog();
// Create a form, add the chart to it, and display the form.
Form form = new Form();
form.Controls.Add(chart);
form.Show();
Visual Basic
C opy C ode
Imports System.Windows.Forms
Imports DevExpress.XtraCharts
Imports DevExpress.XtraCharts.Wizard
' ...
' Create a chart
Dim chart As ChartControl = New ChartControl
' Set its data source.
' You can set any other specific options for the chart here.
chart.DataSource = dataSet11
' Create a ChartWizard for a new ChartControl
Dim wiz As ChartWizard = New ChartWizard(chart)
' Invoke the chart's wizard.
wiz.ShowDialog
' Create a form, add the chart to it, and display the form.
Dim form As Form = New Form
form.Controls.Add(chart)
form.Show
See Also
Chart W izard
How to: Change the Page Order in a Wizard
How to: Add a New Page to a W izard
How to: Hide Certain Tabs on a Wizard's Page
815
Examples
816
C opy C ode
using System.Collections.Generic;
using DevExpress.XtraCharts.Wizard;
// ...
ChartWizard wizard = new ChartWizard(this.chartControl1);
// Create a typed list for a manipulation with Wizard pages.
List<WizardPage> pages = new List<WizardPage>(wizard.Groups[0].Pages);
// Remove the first page.
WizardPage appearancePage = pages[1];
pages.Remove(appearancePage);
// Append it to the list to become the last page.
pages.Add(appearancePage);
// Order the pages.
wizard.Groups[0].Pages = pages.ToArray();
wizard.ShowDialog();
Visual Basic
C opy C ode
Imports System.Collections.Generic
Imports DevExpress.XtraCharts.Wizard
' ...
Dim wizard As ChartWizard = New ChartWizard(Me.chartControl1)
' Create a typed list for a manipulation with Wizard pages.
Dim pages As List = New List(wizard.Groups(0).Pages)
' Remove the first page.
Dim appearancePage As WizardPage = pages(1)
pages.Remove(appearancePage)
' Append it to the list to become the last page.
pages.Add(appearancePage)
' Order the pages.
wizard.Groups(0).Pages = pages.ToArray
wizard.ShowDialog
See Also
Chart W izard
How to: Invoke the Chart W izard at Runtime
How to: Add a New Page to a W izard
How to: Hide Certain Tabs on a Wizard's Page
816
Examples
817
C opy C ode
using DevExpress.XtraCharts.Wizard;
//...
private void ShowNewWizard() {
// Create a Wizard instance.
ChartWizard wiz = new ChartWizard(this.chartControl1);
// Create a new group.
WizardGroup MyWizardGroup = wiz.RegisterGroup("NewGroup");
// Create a new page with a "MyPage" name, "MyHeader" as a caption, "MyDesription"
// as a description, without image. It contains the UserControl1.
WizardPage MyWizardPage = MyWizardGroup.RegisterPage(typeof(UserControl1),
"MyPage", "MyHeader", "MyDesription", null);
// Subscribe to the InitializePage event.
MyWizardPage.InitializePage += new InitializePageEventHandler (MyWizardPage_InitializePage);
// Invoke the Wizard.
wiz.ShowDialog();
}
void MyWizardPage_InitializePage(object sender, InitializePageEventArgs e) {
e.Chart = ((UserControl1)e.Control).chartControl1;
}
Visual Basic
C opy C ode
Imports DevExpress.XtraCharts.Wizard
' ...
Private Sub ShowNewWizard()
' Create a Wizard instance.
Dim wiz As New ChartWizard(Me.chartControl1)
' Create a new group.
Dim MyWizardGroup As WizardGroup = wiz.RegisterGroup("NewGroup")
' Create a new page with a "MyPage" name, "MyHeader" as a caption,
' "MyDesription" as a description, without image. It contains the UserControl1.
Dim MyWizardPage As WizardPage = MyWizardGroup.RegisterPage(GetType(UserControl1), _
"MyPage", "MyHeader", "MyDesription", Nothing)
' Subscribe to the InitializePage event.
AddHandler MyWizardPage.InitializePage, AddressOf MyWizardPage_InitializePage
' Invoke the Wizard.
wiz.ShowDialog()
End Sub
Private Sub MyWizardPage_InitializePage(ByVal sender As Object, ByVal e As InitializePageEventArgs)
e.Chart = DirectCast(e.Control, UserControl1).chartControl1
End Sub
See Also
Chart W izard
How to: Invoke the Chart W izard at Runtime
How to: Change the Page Order in a Wizard
How to: Hide Certain Tabs on a Wizard's Page
817
Examples
818
C opy C ode
using DevExpress.XtraCharts.Wizard;
// ...
private void button1_Click(object sender, EventArgs e) {
// Create a new Wizard.
ChartWizard wizard = new ChartWizard(this.chartControl1);
// Obtain a Data page.
WizardDataPage page = wizard.DataPage;
// Hide the tabs related to a data source on the Data page.
page.HiddenPageTabs.Add(DataPageTab.AutoCreatedSeries);
page.HiddenPageTabs.Add(DataPageTab.SeriesBinding);
// Invoke the Wizard window.
wizard.ShowDialog();
}
Visual Basic
C opy C ode
Imports DevExpress.XtraCharts.Wizard;
' ...
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) _
Handles button1.Click
' Create a new Wizard.
Dim wizard As New ChartWizard(Me.chartControl1)
' Obtain a Data page.
Dim page As WizardDataPage = wizard.DataPage
' Hide the tabs related to a data source on the Data page.
page.HiddenPageTabs.Add(DataPageTab.AutoCreatedSeries)
page.HiddenPageTabs.Add(DataPageTab.SeriesBinding)
' Invoke the Wizard window.
wizard.ShowDialog()
End Sub
Show Me
The complete sample project is available in the DevExpress Code Central database at http://w ww .devexpress.com/
example=E212. Depending on the target platform type (ASP.NET, WinForms, etc), you can either run this example
online or dow nload an auto-executable sample.
See Also
Chart W izard
How to: Invoke the Chart W izard at Runtime
How to: Change the Page Order in a Wizard
How to: Add a New Page to a W izard
818
Examples
819
C opy C ode
(Form1.cs)
using System;
using System.Windows.Forms;
using DevExpress.XtraCharts;
namespace FormatCrosshairLabels
{
public partial class Form1 : Form
{
public Form1()
{
this.Load += new System.EventHandler(this.Form1_Load);
}
private void Form1_Load(object sender, EventArgs e)
{
// Create an empty chart.
ChartControl chartControl1 = new ChartControl();
// Create a first line series and add points to it.
Series series1 = new Series("Europe", ViewType.Line);
series1.Points.Add(new SeriesPoint(1950, 546));
series1.Points.Add(new SeriesPoint(1960, 605));
series1.Points.Add(new SeriesPoint(1970, 656));
series1.Points.Add(new SeriesPoint(1980, 694));
series1.Points.Add(new SeriesPoint(1990, 721));
series1.Points.Add(new SeriesPoint(2000, 730));
series1.Points.Add(new SeriesPoint(2010, 728));
// Create a second line series and add points to it.
Series series2 = new Series("Americas", ViewType.Line);
series2.Points.Add(new SeriesPoint(1950, 332));
series2.Points.Add(new SeriesPoint(1960, 417));
series2.Points.Add(new SeriesPoint(1970, 513));
series2.Points.Add(new SeriesPoint(1980, 614));
series2.Points.Add(new SeriesPoint(1990, 721));
series2.Points.Add(new SeriesPoint(2000, 836));
series2.Points.Add(new SeriesPoint(2010, 935));
// Add the series to the chart.
chartControl1.Series.Add(series1);
chartControl1.Series.Add(series2);
// Hide the legend (if necessary).
chartControl1.Legend.Visible = false;
//Show crosshair axis lines and crosshair axis labels to see format values of crosshair lab
chartControl1.CrosshairOptions.ShowArgumentLabels = true;
chartControl1.CrosshairOptions.ShowValueLabels = true;
2013 DevExpress Inc.
819
Examples
820
chartControl1.CrosshairOptions.ShowValueLine = true;
chartControl1.CrosshairOptions.ShowArgumentLine = true;
// Specify the crosshair label pattern for both series.
series1.CrosshairLabelPattern = "{S} population: {V}";
series2.CrosshairLabelPattern = "{S} population: {V}";
// Specify the crosshair group header pattern.
chartControl1.CrosshairOptions.GroupHeaderPattern = "Year: {A}";
// Cast the chart's diagram to the XYDiagram type, to access its axes.
XYDiagram diagram = (XYDiagram)chartControl1.Diagram;
// Specify the crosshair axis labels pattern for X-axis.
diagram.AxisX.CrosshairAxisLabelOptions.Pattern = "Year: {A:F0}";
// Add the chart to the form.
chartControl1.Dock = DockStyle.Fill;
this.Controls.Add(chartControl1);
}
}
}
Visual Basic
C opy C ode
(Form1.vb)
Imports Microsoft.VisualBasic
Imports System
Imports System.Windows.Forms
Imports DevExpress.XtraCharts
Namespace FormatCrosshairLabels
Partial Public Class Form1
Inherits Form
Public Sub New()
AddHandler Load, AddressOf Form1_Load
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
' Create an empty chart.
Dim chartControl1 As New ChartControl()
' Create a first line series and add points to it.
Dim series1 As New Series("Europe", ViewType.Line)
series1.Points.Add(New SeriesPoint(1950, 546))
series1.Points.Add(New SeriesPoint(1960, 605))
series1.Points.Add(New SeriesPoint(1970, 656))
series1.Points.Add(New SeriesPoint(1980, 694))
series1.Points.Add(New SeriesPoint(1990, 721))
series1.Points.Add(New SeriesPoint(2000, 730))
series1.Points.Add(New SeriesPoint(2010, 728))
' Create a second line series and add points to it.
Dim series2 As New Series("Americas", ViewType.Line)
series2.Points.Add(New SeriesPoint(1950, 332))
series2.Points.Add(New SeriesPoint(1960, 417))
series2.Points.Add(New SeriesPoint(1970, 513))
series2.Points.Add(New SeriesPoint(1980, 614))
series2.Points.Add(New SeriesPoint(1990, 721))
series2.Points.Add(New SeriesPoint(2000, 836))
series2.Points.Add(New SeriesPoint(2010, 935))
' Add the series to the chart.
chartControl1.Series.Add(series1)
chartControl1.Series.Add(series2)
' Hide the legend (if necessary).
chartControl1.Legend.Visible = False
'Show crosshair axis lines and axis labels to see format values of crosshair labers
chartControl1.CrosshairOptions.ShowArgumentLabels = True
chartControl1.CrosshairOptions.ShowValueLabels = True
chartControl1.CrosshairOptions.ShowValueLine = True
chartControl1.CrosshairOptions.ShowArgumentLine = True
2013 DevExpress Inc.
820
Examples
821
821
Examples
822
Producing Output
How to: Save and Restore a Layout
Charting > Examples > How to: Save and Restore a Layout
The follow ing example demonstrates how to save a chart to a memory stream, and then restore it.
C#
C opy C ode
using System.IO;
// ...
Stream stream = new MemoryStream();
// ...
// Save the chart.
stream.Seek(0, System.IO.SeekOrigin.Begin);
chartControl1.SaveToStream(stream);
// Load the chart.
stream.Seek(0, System.IO.SeekOrigin.Begin);
chartControl1.LoadFromStream(stream);
Visual Basic
C opy C ode
Imports System.IO
' ...
Dim stream As System.IO.Stream
stream = New System.IO.MemoryStream()
' ...
' Save the chart.
stream.Seek(0, System.IO.SeekOrigin.Begin)
ChartControl1.SaveToStream(stream)
' Load the chart.
stream.Seek(0, System.IO.SeekOrigin.Begin)
ChartControl1.LoadFromStream(stream)
822
Examples
823
C#
C opy C ode
using DevExpress.XtraCharts;
// ...
private void ShowChartPreview(ChartControl chart) {
// Check whether the ChartControl can be previewed.
if (!chart.IsPrintingAvailable) {
MessageBox.Show("The 'DevExpress.XtraPrinting.v7.2.dll' is not found", "Error");
return;
}
// Open the Preview window.
chart.ShowPrintPreview();
}
private void PrintChart(ChartControl chart) {
// Check whether the ChartControl can be printed.
if (!chart.IsPrintingAvailable) {
MessageBox.Show("The 'DevExpress.XtraPrinting.v7.2.dll' is not found", "Error");
return;
}
// Print.
chart.Print();
}
Visual Basic
C opy C ode
Imports DevExpress.XtraCharts
' ...
Sub ShowChartPreview(ByVal chart As ChartControl)
' Check whether the ChartControl can be previewed.
If Not chart.IsPrintingAvailable Then
MessageBox.Show("The 'DevExpress.XtraPrinting.v7.2.dll' is not found", "Error")
Return
End If
' Opens the Preview window.
chart.ShowPrintPreview()
End Sub
Sub PrintChart(ByVal chart As ChartControl)
' Check whether the ChartControl can be printed.
If Not chart.IsPrintingAvailable Then
MessageBox.Show("The 'DevExpress.XtraPrinting.v7.2.dll' is not found", "Error")
Return
End If
' Print.
chart.Print()
End Sub
The image below show s the print preview of a ChartControl.
823
Examples
824
Note
If you want to be able to customize different printing options when printing a chart, you need to print it via the
PrintableComponentLink component. For more information on using this component, refer to the How to: Use the
PrintableComponentLink to Print DevExpress Controls tutorial.
824
Examples
825
C opy C ode
using System.IO;
// ...
if (chartControl1.IsPrintingAvailable){
// Exports to a PDF file.
chartControl1.ExportToPdf("Output.pdf");
// Exports to a stream as PDF.
FileStream pdfStream = new FileStream("Output.pdf", FileMode.Create);
chartControl1.ExportToPdf(pdfStream);
// ...
pdfStream.Close();
}
Visual Basic
C opy C ode
Imports System.IO
' ...
If ChartControl1.IsPrintingAvailable Then
' Exports to a PDF file.
ChartControl1.ExportToPdf("Output.pdf")
' Exports to a stream as PDF.
Dim pdfStream As New FileStream("Output.pdf", FileMode.Create)
ChartControl1.ExportToPdf(pdfStream)
' ...
pdfStream.Close()
End If
825
Examples
826
C opy C ode
using System.IO;
using DevExpress.XtraCharts;
using DevExpress.XtraPrinting;
// ...
private void ExportChartToHTML(ChartControl chart) {
if (chart.IsPrintingAvailable) {
// Create an object containing HTML export options.
HtmlExportOptions htmlOptions = new HtmlExportOptions();
// Set HTML-specific export options.
htmlOptions.CharacterSet = "utf-8";
htmlOptions.RemoveSecondarySymbols = false;
htmlOptions.Title = "Unicode UTF-8 Example";
// Export a chart to an HTML file.
chart.ExportToHtml("OutputUnicode.html", htmlOptions);
// Export a chart to a stream as HTML.
FileStream htmlStream = new FileStream("OutputDefault.html", FileMode.Create);
chart.ExportToHtml(htmlStream, htmlOptions);
}
}
private void ExportChartToMHT(ChartControl chart) {
if (chart.IsPrintingAvailable) {
// Create an object containing MHT export options.
MhtExportOptions mhtOptions = new MhtExportOptions();
// Set MHT-specific export options.
mhtOptions.CharacterSet = "iso-8859-1";
mhtOptions.Title = "Unicode UTF-8 Example";
// Export a chart to an MHT file.
chart.ExportToMht("OutputUnicode.mht", mhtOptions);
// Export a chart to a stream as MHT.
FileStream mhtStream = new FileStream("OutputDefault.mht", FileMode.Create);
chart.ExportToMht(mhtStream, mhtOptions);
}
}
Visual Basic
C opy C ode
Imports System.IO
Imports DevExpress.XtraCharts
Imports DevExpress.XtraPrinting
' ...
Private Sub ExportChartToHTML(ByRef Chart As ChartControl)
If (Chart.IsPrintingAvailable) Then
' Create an object containing HTML export options.
Dim HtmlOptions As New HtmlExportOptions()
' Set HTML-specific export options.
HtmlOptions.CharacterSet = "utf-8"
HtmlOptions.RemoveSecondarySymbols = False
HtmlOptions.Title = "Unicode UTF-8 Example"
' Export a chart to an HTML file.
Chart.ExportToHtml("OutputUnicode.html", HtmlOptions)
' Export a chart to a stream as HTML.
Dim HtmlStream As New FileStream("OutputDefault.html", FileMode.Create)
Chart.ExportToHtml(HtmlStream, HtmlOptions)
End If
826
Examples
827
End Sub
Private Sub ExportChartToMHT(ByRef Chart As ChartControl)
If (Chart.IsPrintingAvailable) Then
' Create an object containing MHT export options.
Dim MhtOptions As New MhtExportOptions()
' Set MHT-specific export options.
MhtOptions.CharacterSet = "iso-8859-1"
MhtOptions.Title = "Unicode UTF-8 Example"
' Export a chart to an MHT file.
Chart.ExportToMht("OutputUnicode.mht", MhtOptions)
' Export a chart to a stream as MHT.
Dim MhtStream As New FileStream("OutputDefault.mht", FileMode.Create)
Chart.ExportToMht(MhtStream, MhtOptions)
End If
End Sub
827
Examples
828
C opy C ode
using System.IO;
// ...
if (chartControl1.IsPrintingAvailable){
// Exports to an XLS file.
chartControl1.ExportToXls("Output.xls");
// Exports to a stream as XLS.
FileStream xlsStream = new FileStream("Output.xls", FileMode.Create);
chartControl1.ExportToXls(xlsStream);
// ...
xlsStream.Close();
}
Visual Basic
C opy C ode
Imports System.IO
' ...
If chartControl1.IsPrintingAvailable Then
' Exports to an XLS file.
chartControl1.ExportToXls("Output.xls")
' Exports to a stream as XLS.
Dim xlsStream As FileStream = New FileStream("Output.xls", FileMode.Create)
chartControl1.ExportToXls(xlsStream)
' ...
xlsStream.Close
End If
828
Examples
829
C opy C ode
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
using DevExpress.XtraCharts;
// ...
private Image GetChartImage(ChartControl chart, ImageFormat format) {
// Create an image.
Image image = null;
// Create an image of the chart.
using(MemoryStream s = new MemoryStream()) {
chart.ExportToImage(s, Format);
image = Image.FromStream(s);
}
// Return the image.
return image;
}
private void SaveChartImageToFile(ChartControl chart, ImageFormat format, String fileName) {
// Create an image in the specified format from the chart
// and save it to the specified path.
chart.ExportToImage(fileName, format);
}
Visual Basic
C opy C ode
Imports System.IO
Imports System.Drawing
Imports System.Drawing.Imaging
Imports DevExpress.XtraCharts
' ...
Private Function GetChartImage(Chart As ChartControl, Format As ImageFormat) As Image
' Create an image.
Dim Image As Image = Nothing
' Create an image of the chart.
Dim s As New MemoryStream()
Try
Chart.ExportToImage(s, format)
Image = Image.FromStream(s)
Finally
s.Dispose()
End Try
' Return the image.
Return Image
End Function
Private Sub SaveChartImageToFile(Chart As ChartControl, Format As ImageFormat, FileName As String)
' Create an image in the specified format from the chart
' and save it to the specified path.
Chart.ExportToImage(FileName, Format)
End Sub
829