// Create a new workbook Workbook workbook = new Workbook(); IWorksheet worksheet = workbook.getWorksheets().get(0); IShape shape = worksheet.getShapes().addChart(ChartType.StockOHLC, 20, 20, 360, 220); worksheet.getRange("A20:E36") .setValue(new Object[][] { { null, "Open", "High", "Low", "Close" }, { new GregorianCalendar(2019, 9, 1), 103.46, 105.76, 92.38, 100.94 }, { new GregorianCalendar(2019, 9, 2), 100.26, 102.45, 90.14, 93.45 }, { new GregorianCalendar(2019, 9, 3), 98.05, 102.11, 85.01, 99.89 }, { new GregorianCalendar(2019, 9, 4), 100.32, 106.01, 94.04, 99.45 }, { new GregorianCalendar(2019, 9, 5), 99.74, 108.23, 98.16, 104.33 }, { new GregorianCalendar(2019, 9, 8), 92.11, 107.7, 91.02, 102.17 }, { new GregorianCalendar(2019, 9, 9), 107.8, 110.36, 101.62, 110.07 }, { new GregorianCalendar(2019, 9, 10), 107.56, 115.97, 106.89, 112.39 }, { new GregorianCalendar(2019, 9, 11), 112.86, 120.32, 112.15, 117.52 }, { new GregorianCalendar(2019, 9, 12), 115.02, 122.03, 114.67, 114.75 }, { new GregorianCalendar(2019, 9, 15), 108.53, 120.46, 106.21, 116.85 }, { new GregorianCalendar(2019, 9, 16), 114.97, 118.08, 113.55, 116.69 }, { new GregorianCalendar(2019, 9, 17), 127.14, 128.23, 110.91, 117.25 }, { new GregorianCalendar(2019, 9, 18), 118.89, 120.55, 108.09, 112.52 }, { new GregorianCalendar(2019, 9, 19), 105.57, 112.58, 105.42, 109.12 }, { new GregorianCalendar(2019, 9, 22), 110.23, 115.23, 97.25, 101.56 } }); shape.getChart().getSeriesCollection().add(worksheet.getRange("A20:E36"), RowCol.Columns); // set chart title shape.getChart().getChartTitle().setText("Open-High-Low-Close Stock Chart"); IAxis valueAxis = shape.getChart().getAxes().item(AxisType.Value); IAxis categoryAxis = shape.getChart().getAxes().item(AxisType.Category); // config value axis valueAxis.setMinimumScale(80); valueAxis.setMaximumScale(140); valueAxis.setMajorUnit(15); // config category axis categoryAxis.setCategoryType(CategoryType.CategoryScale); categoryAxis.setMajorTickMark(TickMark.Outside); categoryAxis.setTickMarkSpacing(5); categoryAxis.setTickLabelSpacing(5); worksheet.getRange("A:A").getEntireColumn() .setColumnWidth(worksheet.getRange("A:A").getEntireColumn().getColumnWidth() * 1.5); // Save to a pdf file workbook.save("StockChartPdf.pdf");