创建高低收(HLC)股票图表

可能的使用场景

高低收(HLC)股票图表使用四列数据。第一列通常是类别,通常是日期,但也可以使用股票名称。接下来的三列分别表示最高、最低和收盘价格。每个类别价格范围通过垂直线来表示,收盘价格则使用延伸至该线右侧的刻度线显示。

todo:image_alt_text

图表的可见性改进

有时,为了使图表看起来更直观,我们可以修改标记(收盘价)的外观,或者在辅助轴上显示它。

todo:image_alt_text

示例代码

以下示例代码加载示例Excel文件并生成输出Excel文件

// Create an instance of Workbook
Workbook workbook = new Workbook("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.StockHighLowClose, 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 = "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:D9", true);
// Set category data
chart.NSeries.CategoryData = "A2:A9";
// Set the marker with the built-in data
chart.NSeries[2].Marker.MarkerStyle = ChartMarkerType.Dash;
chart.NSeries[2].Marker.MarkerSize = 20;
chart.NSeries[2].Marker.Area.Formatting = FormattingType.Custom;
chart.NSeries[2].Marker.Area.ForegroundColor = Color.Maroon;
// Fill the PlotArea area with nothing
chart.PlotArea.Area.FillFormat.FillType = FillType.None;
// Save the Excel file
workbook.Save("out.xlsx");