CodeCentralShow Me

在 DevExpress Code Central 数据库中可以找到完整的示例项目,网址是 http://www.devexpress.com/example=E2664。 取决于目标平台类型 (ASP.NET、WinForms 等),可以在线运行本示例,或者下载自动可执行的示例。

这个示例展示了在运行时刻如何通过 ChartControl.AppearanceNameChartControl.PaletteNameChartControl.PaletteBaseColorNumber 属性来定制图表的外观。

注意,可以通过 ChartControl.IndicatorsPaletteName 属性,为绘制图表中所有可用的指标线而指定单独的调色板。

C#CopyCode image复制代码
 (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 BasicCopyCode image复制代码
 (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)
    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.
    Dim myLine As New RegressionLine(ValueLevel.Value)
    CType(series1.View, SideBySideBarSeriesView).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
    Me.Controls.Add(barChart)
End Sub

在下面的插图中显示了结果。

CodeCentralShow Me

在 DevExpress Code Central 数据库中可以找到完整的示例项目,网址是 http://www.devexpress.com/example=E1179。 取决于目标平台类型 (ASP.NET、WinForms 等),可以在线运行本示例,或者下载自动可执行的示例。