Hello,
Need help in creating a stock chart similar to that attached Excel using Aspose.Cells for Java API.
Attaching a sample Excel file with the manually created chart.
sample-stock-excel.zip (12.6 KB)
Thanks in Advance
Hello,
Need help in creating a stock chart similar to that attached Excel using Aspose.Cells for Java API.
Attaching a sample Excel file with the manually created chart.
sample-stock-excel.zip (12.6 KB)
Thanks in Advance
Thanks for the template file.
I have created a sample code to create your desired chart. Please refer to the code segment and write/update according to your needs. I have used the source data in your provided file and created the chart with your design chart:
e.g.
Sample code:
Workbook workbook = new Workbook("f:\\files\\sample-stock-excel.xlsx");
Worksheet worksheet = workbook.getWorksheets().get(0);
int i = worksheet.getCharts().add(ChartType.STOCK_VOLUME_HIGH_LOW_CLOSE,20, 6, 38, 21);
Chart chart = worksheet.getCharts().get(i);
chart.setShowLegend(true);
chart.getTitle().setText("Chart Title");
chart.getTitle().setVisible(true);
chart.getLegend().setPosition(LegendPositionType.BOTTOM);
chart.setChartDataRange("A1:E12",true);
chart.getNSeries().setCategoryData("A2:A12");
for(int j = 0;j<chart.getNSeries().getCount();j++)
{
switch (j) {
case 1:
chart.getNSeries().get(j).getMarker().setMarkerStyle(ChartMarkerType.CIRCLE);
chart.getNSeries().get(j).getMarker().setMarkerSize(15);
chart.getNSeries().get(j).getMarker().getArea().setFormatting(FormattingType.CUSTOM);
chart.getNSeries().get(j).getMarker().getArea().setForegroundColor(com.aspose.cells.Color.getPink());
chart.getNSeries().get(j).getBorder().setVisible(false);
break;
case 2:
chart.getNSeries().get(j).getMarker().setMarkerStyle(ChartMarkerType.DASH);
chart.getNSeries().get(j).getMarker().setMarkerSize(15);
chart.getNSeries().get(j).getMarker().getArea().setFormatting(FormattingType.CUSTOM);
chart.getNSeries().get(j).getMarker().getArea().setForegroundColor(com.aspose.cells.Color.getOrange());
chart.getNSeries().get(j).getBorder().setVisible(false);
break;
case 3:
chart.getNSeries().get(j).getMarker().setMarkerStyle(ChartMarkerType.SQUARE);
chart.getNSeries().get(j).getMarker().setMarkerSize(15);
chart.getNSeries().get(j).getMarker().getArea().setFormatting(FormattingType.CUSTOM);
chart.getNSeries().get(j).getMarker().getArea().setForegroundColor(com.aspose.cells.Color.getLightBlue());
chart.getNSeries().get(j).getBorder().setVisible(false);
break;
}
}
chart.getPlotArea().getArea().setFormatting(FormattingType.NONE);
workbook.save("f:\\files\\out1.xlsx");
Hope, this helps a bit.