[]
股票图是用来说明数据在时间的波动。它可以代表储量、降雨量或年气温的波动。工作表的数据按列或行可以绘制在股票图。
GcExcel支持以下类型的股票图
图表类型 | 图表快照 | 用例 |
---|---|---|
StockHLC | StockHLC 图 | 一个高-低-收盘价图表显示了数据值的组织顺序:高,低,收盘价,收盘价位于高和低之间。 |
StockOHLC | StockOHLC 图 | 开盘-最高-最低-收盘(Open-High-Low-Close)图表按照开盘价、最高价、最低价和收盘价的顺序来显示数据。 |
StockVHLC | StockVHLC 图 | 一个量-高-低-收盘价图表将数据值按顺序排列:量,高,低和收盘价。 |
StockVOHLC | StockVOHLC 图 | 一个量-开-高-低-收盘价图表显示了数据值的顺序:量,开,高,低和收盘价。 |
参考以下代码添加StockVOHLC图:
private static void StockCharts() {
// Initialize workbook
Workbook workbook = new Workbook();
// Fetch default worksheet
IWorksheet worksheet = workbook.getWorksheets().get(0);
// Prepare data for chart
worksheet.getRange("A1:D17")
.setValue(new Object[][] { { null, "High", "Low", "Close" },
{ new GregorianCalendar(2019, 9, 1), 105.76, 92.38, 100.94 },
{ new GregorianCalendar(2019, 9, 2), 102.45, 90.14, 93.45 },
{ new GregorianCalendar(2019, 9, 3), 102.11, 85.01, 99.89 },
{ new GregorianCalendar(2019, 9, 4), 106.01, 94.04, 99.45 },
{ new GregorianCalendar(2019, 9, 5), 108.23, 98.16, 104.33 },
{ new GregorianCalendar(2019, 9, 8), 107.7, 91.02, 102.17 },
{ new GregorianCalendar(2019, 9, 9), 110.36, 101.62, 110.07 },
{ new GregorianCalendar(2019, 9, 10), 115.97, 106.89, 112.39 },
{ new GregorianCalendar(2019, 9, 11), 120.32, 112.15, 117.52 },
{ new GregorianCalendar(2019, 9, 12), 122.03, 114.67, 114.75 },
{ new GregorianCalendar(2019, 9, 15), 120.46, 106.21, 116.85 },
{ new GregorianCalendar(2019, 9, 16), 118.08, 113.55, 116.69 },
{ new GregorianCalendar(2019, 9, 17), 128.23, 110.91, 117.25 },
{ new GregorianCalendar(2019, 9, 18), 120.55, 108.09, 112.52 },
{ new GregorianCalendar(2019, 9, 19), 112.58, 105.42, 109.12 },
{ new GregorianCalendar(2019, 9, 22), 115.23, 97.25, 101.56 },
});
worksheet.getRange("A:D").getColumns().autoFit();
// Add Stock Chart
IShape stockChartshape = worksheet.getShapes().addChart(ChartType.StockHLC, 350, 20, 360, 230);
// Adding series to SeriesCollection
stockChartshape.getChart().getSeriesCollection().add(worksheet.getRange("A1:D17"), RowCol.Columns);
// Configure Chart Title
stockChartshape.getChart().getChartTitle().setText("Market Data Analysis");
// Configure value axis
IAxis valueAxis = stockChartshape.getChart().getAxes().item(AxisType.Value);
valueAxis.setMinimumScale(80);
valueAxis.setMaximumScale(140);
valueAxis.setMajorUnit(15);
// Configure category axis
IAxis categoryAxis = stockChartshape.getChart().getAxes().item(AxisType.Category);
categoryAxis.setCategoryType(CategoryType.CategoryScale);
categoryAxis.setMajorTickMark(TickMark.Outside);
categoryAxis.setTickLabelSpacingIsAuto(false);
categoryAxis.setTickLabelSpacing(5);
// Configure Close Series Style
ISeries series_close = stockChartshape.getChart().getSeriesCollection().get(2);
series_close.setMarkerStyle(MarkerStyle.Diamond);
series_close.setHas3DEffect(true);
// Saving workbook to Xlsx
workbook.save("23-StockChart.xlsx", SaveFileFormat.Xlsx);