简要说明
股价图 是由 StockSeriesView 对象来表示的,此对象属于 财务系列视图 (也称为 开盘-盘高-盘低-收盘 系列)。
这种视图被用于显示股价在一天中的变化。 最低价 和 最高价 分别被呈现为在每个数据点上显示的竖线的底部和上部的取值,并且 开盘价 和 收盘价 分别被呈现为竖线左侧和右侧的小横线。
对于股价图,可以选择某种价格水平 (最低价、最高价、开盘价或收盘价) 来启用 FinancialSeriesViewBase.ReductionOptions,意味是如果指定的价格低于前一点的取值,那么后续点就被绘制为红色 (或任何其他颜色)。
在下面的插图中显示了一个股价图。 注意,这种图表类型基于 XYDiagram,因此可以被旋转,从而垂直地或水平地显示图表。
要学习如何从轴刻度中去除周末和节假日,请参阅 日期时间数据呈现。
要获得更多信息,请参阅 财务图表。
图表类型特征
下表列出了这种图表类型的主要特征。
特征 |
取值 |
---|---|
系列视图类型 | StockSeriesView |
图象类型 | 2D- XYDiagram |
每个数据点的参数个数 | 1 |
每个数据点的取值个数 | 4 (最低价、最高价、开盘价、收盘价) |
注意 |
---|
要获得关于哪些图表类型可以与 股价图 组合使用的信息,请参阅 组合使用不同的系列视图 文档。 |
示例
Show Me |
---|
在 DevExpress Code Central 数据库中可以找到完整的示例项目,网址是 http://www.devexpress.com/example=E1215。 取决于目标平台类型 (ASP.NET、WinForms 等),可以在线运行本示例,或者下载自动可执行的示例。 |
下面的示例演示了在运行时刻如何创建 ChartControl (拥有一个 StockSeriesView 类型的系列),并把图表添加到窗体中。 在继续本示例之前,首先要在 Visual Studio 中创建一个 Windows 窗体应用程序,并把所有 必需的程序集 包含到项目的“引用”列表中。
然后,把下列代码添加到 Form.Load 事件处理程序。
注意,可以通过 AxisBase.WorkdaysOnly 和 AxisBase.WorkdaysOptions 属性,从轴范围中去除非工作日 (周末和节假日)。 要学习在 XtraCharts 中有哪些可用的财务分析工具,请参阅 指标线。
C# | 复制代码 |
---|---|
(Form1.cs) using System; using System.Windows.Forms; using DevExpress.XtraCharts; // ... private void Form1_Load(object sender, EventArgs e) { // Create a new chart. ChartControl stockChart = new ChartControl(); // Create a stock series. Series series1 = new Series("Series 1", ViewType.Stock); // Specify the date-time argument scale type for the series, // as it is qualitative, by default. series1.ArgumentScaleType = ScaleType.DateTime; // Add points to it. series1.Points.Add(new SeriesPoint(new DateTime(1994, 3, 1), new object[] { 24.00, 25.00, 25.00, 24.875 })); series1.Points.Add(new SeriesPoint(new DateTime(1994, 3, 2), new object[] { 23.625, 25.125, 24.00, 24.875 })); series1.Points.Add(new SeriesPoint(new DateTime(1994, 3, 3), new object[] { 26.25, 28.25, 26.75, 27.00 })); series1.Points.Add(new SeriesPoint(new DateTime(1994, 3, 4), new object[] { 26.50, 27.875, 26.875, 27.25 })); series1.Points.Add(new SeriesPoint(new DateTime(1994, 3, 7), new object[] { 26.375, 27.50, 27.375, 26.75 })); series1.Points.Add(new SeriesPoint(new DateTime(1994, 3, 8), new object[] { 25.75, 26.875, 26.75, 26.00 })); series1.Points.Add(new SeriesPoint(new DateTime(1994, 3, 9), new object[] { 25.75, 26.75, 26.125, 26.25 })); series1.Points.Add(new SeriesPoint(new DateTime(1994, 3, 10), new object[] { 25.75, 26.375, 26.375, 25.875 })); series1.Points.Add(new SeriesPoint(new DateTime(1994, 3, 11), new object[] { 24.875, 26.125, 26.00, 25.375 })); series1.Points.Add(new SeriesPoint(new DateTime(1994, 3, 14), new object[] { 25.125, 26.00, 25.625, 25.75 })); // Add the series to the chart. stockChart.Series.Add(series1); // Access the view-type-specific options of the series. StockSeriesView myView = (StockSeriesView)series1.View; myView.LineThickness = 2; myView.LevelLineLength = 0.25; // Specify the series reduction options. myView.ReductionOptions.Level = StockLevel.Close; myView.ReductionOptions.Visible = true; // Access the chart's diagram. XYDiagram diagram = ((XYDiagram)stockChart.Diagram); // Access the type-specific options of the diagram. diagram.AxisY.Range.MinValue = 22; // Exclude weekends from the X-axis range, // to avoid gaps in the chart's data. diagram.AxisX.WorkdaysOnly = true; // Hide the legend and series labels (if necessary). stockChart.Legend.Visible = false; series1.Label.Visible = false; // Add a title to the chart (if necessary). stockChart.Titles.Add(new ChartTitle()); stockChart.Titles[0].Text = "A Stock Chart"; // Add the chart to the form. stockChart.Dock = DockStyle.Fill; this.Controls.Add(stockChart); } |
Visual Basic | 复制代码 |
---|---|
(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 a new chart. Dim stockChart As New ChartControl() ' Create a stock series. Dim series1 As New Series("Series 1", ViewType.Stock) ' Specify the date-time argument scale type for the series, ' as it is qualitative, by default. series1.ArgumentScaleType = ScaleType.DateTime ' Add points to it. series1.Points.Add(New SeriesPoint(New DateTime(1994, 3, 1), _ New Object() { 24.00, 25.00, 25.00, 24.875 })) series1.Points.Add(New SeriesPoint(New DateTime(1994, 3, 2), _ New Object() { 23.625, 25.125, 24.00, 24.875 })) series1.Points.Add(New SeriesPoint(New DateTime(1994, 3, 3), _ New Object() { 26.25, 28.25, 26.75, 27.00 })) series1.Points.Add(New SeriesPoint(New DateTime(1994, 3, 4), _ New Object() { 26.50, 27.875, 26.875, 27.25 })) series1.Points.Add(New SeriesPoint(New DateTime(1994, 3, 7), _ New Object() { 26.375, 27.50, 27.375, 26.75 })) series1.Points.Add(New SeriesPoint(New DateTime(1994, 3, 8), _ New Object() { 25.75, 26.875, 26.75, 26.00 })) series1.Points.Add(New SeriesPoint(New DateTime(1994, 3, 9), _ New Object() { 25.75, 26.75, 26.125, 26.25 })) series1.Points.Add(New SeriesPoint(New DateTime(1994, 3, 10), _ New Object() { 25.75, 26.375, 26.375, 25.875 })) series1.Points.Add(New SeriesPoint(New DateTime(1994, 3, 11), _ New Object() { 24.875, 26.125, 26.00, 25.375 })) series1.Points.Add(New SeriesPoint(New DateTime(1994, 3, 14), _ New Object() { 25.125, 26.00, 25.625, 25.75 })) ' Add the series to the chart. stockChart.Series.Add(series1) ' Access the view-type-specific options of the series. Dim myView As StockSeriesView = CType(series1.View, StockSeriesView) myView.LineThickness = 2 myView.LevelLineLength = 0.25 ' Specify the series reduction options. myView.ReductionOptions.Level = StockLevel.Close myView.ReductionOptions.Visible = True ' Access the chart's diagram. Dim diagram As XYDiagram = (CType(stockChart.Diagram, XYDiagram)) ' Access the type-specific options of the diagram. diagram.AxisY.Range.MinValue = 22 ' Exclude weekends from the X-axis range, ' to avoid gaps in the chart's data. diagram.AxisX.WorkdaysOnly = True ' Hide the legend and series labels (if necessary). stockChart.Legend.Visible = False series1.Label.Visible = False ' Add a title to the chart (if necessary). stockChart.Titles.Add(New ChartTitle()) stockChart.Titles(0).Text = "A Stock Chart" ' Add the chart to the form. stockChart.Dock = DockStyle.Fill Me.Controls.Add(stockChart) End Sub |
Show Me |
---|
在 DevExpress Code Central 数据库中可以找到完整的示例项目,网址是 http://www.devexpress.com/example=E1215。 取决于目标平台类型 (ASP.NET、WinForms 等),可以在线运行本示例,或者下载自动可执行的示例。 |