创建开 高 低 收(OHLC)股票图表

可能的使用场景

开-高-低-收(OHLC)图表使用五列数据,分别是类别、开盘、最高、最低和收盘。每个类别的价格范围再次通过垂直线表示,开盘价格和收盘价格之间的范围由一个更宽的浮动条表示;如果该类别的价格上升(收盘价高于开盘价),则该条将填充一种颜色,而如果价格下降,则用另一种颜色填充。这种图表通常被称为蜡烛图。

todo:image_alt_text

todo:image_alt_text

图表的可见性改进

我们经常使用颜色而不是黑白来表示价格的涨跌。在下面的第一组蜡烛图中,红色显示上涨,绿色表示下跌。

todo:image_alt_text

示例代码

以下示例代码加载了【示例Excel文件】(Open-High-Low-Close.xlsx),并生成了【输出Excel文件】(out.xlsx)。

// Create an instance of Workbook
Workbook workbook = new Workbook("Open-High-Low-Close.xlsx");
// Access the first worksheet.
Worksheet worksheet = workbook.Worksheets[0];
//Create High-Low-Close-Stock Chart
int pieIdx = worksheet.Charts.Add(ChartType.StockOpenHighLowClose, 5, 6, 20, 12);
// Retrieve the Chart object
Chart chart = worksheet.Charts[pieIdx];
// Set the legend can be showed
chart.ShowLegend = true;
// Set the chart title name
chart.Title.Text = "OPen-High-Low-Close Stock";
// Set the Legend at the bottom of the chart area
chart.Legend.Position = LegendPositionType.Bottom;
// Set data range
chart.SetChartDataRange("A1:E9", true);
// Set category data
chart.NSeries.CategoryData = "A2:A9";
// Set the DownBars and UpBars with different color
chart.NSeries[0].DownBars.Area.ForegroundColor = Color.Green;
chart.NSeries[0].UpBars.Area.ForegroundColor = Color.Red;
// Fill the PlotArea area with nothing
chart.PlotArea.Area.FillFormat.FillType = FillType.None;
// Save the Excel file
workbook.Save("out.xlsx");