简要说明
K 线图 是由 CandleStickSeriesView 对象来表示的,此对象属于 财务系列视图 (也称为 开盘-盘高-盘低-收盘 系列)。
这种视图被用于显示股价在一天中的变化。 每个数据点都由一个矩形 (实体部分,底部和上部的取值对应于 开盘价 和 收盘价) 组成,以及一条垂直线 (影线、蜡烛芯 或 尾线,底部和上部的取值对应于 最低价 和 最高价)。 如果收盘价高于开盘价,那么实体部分是空白的。 如果收盘价低于开盘价,那么实体部分是填充的。
对于 K 线图,可以选择某种价格水平 (最低价、最高价、开盘价或收盘价) 来启用 FinancialSeriesViewBase.ReductionOptions,意思是如果指定的价格低于前一点的取值,那么后续点就被绘制为红色 (或任何其他颜色)。
在下面的插图中显示了一个 K 线图。 注意,这种图表类型基于 XYDiagram,因此可以被旋转,从而垂直地或水平地显示图表。
要学习如何从轴刻度中去除周末和节假日,请参阅 日期时间数据呈现。
要获得更多信息,请参阅 财务图表。
图表类型特征
下表列出了这种图表类型的主要特征。
特征 |
取值 |
---|---|
系列视图类型 | CandleStickSeriesView |
图象类型 | 2D- XYDiagram |
每个数据点的参数个数 | 1 |
每个数据点的取值个数 | 4 (最低价、最高价、开盘价、收盘价) |
注意 |
---|
要获得关于哪些图表类型可以与 K 线图 组合使用的信息,请参阅 组合使用不同的系列视图 文档。 |
示例
Show Me |
---|
在 DevExpress Code Central 数据库中可以找到完整的示例项目,网址是 http://www.devexpress.com/example=E1217。 取决于目标平台类型 (ASP.NET、WinForms 等),可以在线运行本示例,或者下载自动可执行的示例。 |
下面的示例演示了在运行时刻如何创建 ChartControl (拥有一个 CandleStickSeriesView 类型的系列),并把图表添加到窗体中。 在继续本示例之前,首先要在 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 candlestickChart = new ChartControl(); // Create a candlestick series. Series series1 = new Series("Stock Prices", ViewType.CandleStick); // 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. candlestickChart.Series.Add(series1); // Access the view-type-specific options of the series. CandleStickSeriesView myView = (CandleStickSeriesView)series1.View; myView.LineThickness = 2; myView.LevelLineLength = 0.25; // Specify the series reduction options. myView.ReductionOptions.Level = StockLevel.Open; myView.ReductionOptions.Visible = true; // Access the chart's diagram. XYDiagram diagram = ((XYDiagram)candlestickChart.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). candlestickChart.Legend.Visible = false; series1.Label.Visible = false; // Add a title to the chart (if necessary). candlestickChart.Titles.Add(new ChartTitle()); candlestickChart.Titles[0].Text = "A Candlestick Chart"; // Add the chart to the form. candlestickChart.Dock = DockStyle.Fill; this.Controls.Add(candlestickChart); } |
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 candlestickChart As New ChartControl() ' Create a candlestick series. Dim series1 As New Series("Stock Prices", ViewType.CandleStick) ' 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. candlestickChart.Series.Add(series1) ' Access the view-type-specific options of the series. Dim myView As CandleStickSeriesView = CType(series1.View, CandleStickSeriesView) myView.LineThickness = 2 myView.LevelLineLength = 0.25 ' Specify the series reduction options. myView.ReductionOptions.Level = StockLevel.Open myView.ReductionOptions.Visible = True ' Access the chart's diagram. Dim diagram As XYDiagram = (CType(candlestickChart.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). candlestickChart.Legend.Visible = False series1.Label.Visible = False ' Add a title to the chart (if necessary). candlestickChart.Titles.Add(New ChartTitle()) candlestickChart.Titles(0).Text = "A Candlestick Chart" ' Add the chart to the form. candlestickChart.Dock = DockStyle.Fill Me.Controls.Add(candlestickChart) End Sub |