Point2D.Double[] usData = {
new Point2D.Double(-54.1, 0.8),
new Point2D.Double(-57.9, 4.7),
new Point2D.Double(-54.5, 4.3),
new Point2D.Double(-55.5, 1.9)
};
Point2D.Double[] caData = {
new Point2D.Double(-37.0, -1.6),
new Point2D.Double(-30.6, 4.7),
new Point2D.Double(-38.1, 4.3),
new Point2D.Double(-31.7, 7.3)
};
Point2D.Double[] euData = {
new Point2D.Double(-73.2, 0.8),
new Point2D.Double(-71.9, 6.6),
new Point2D.Double(-69.1, 5.5),
new Point2D.Double(-73.9, 3.0)
};
Presentation presentation = new Presentation();
presentation.getSlideSize().setSize(SlideSizeType.Widescreen, SlideSizeScaleType.DoNotScale);
ISlide slide = presentation.getSlides().get_Item(0);
IChart chart = slide.getShapes().addChart(
ChartType.ScatterWithSmoothLinesAndMarkers, 28.5f, 101, 902.5f, 355);
IChartDataWorkbook workbook = chart.getChartData().getChartDataWorkbook();
int worksheetIndex = 0;
chart.getChartData().getSeries().clear();
chart.getChartData().getCategories().clear();
workbook.clear(0);
chart.getLegend().setPosition(LegendPositionType.Bottom);
chart.getLegend().getTextFormat().getPortionFormat().setFontHeight(10);
chart.getPlotArea().getFormat().getLine().getFillFormat().setFillType(FillType.Solid);
chart.getPlotArea().getFormat().getLine().getFillFormat().getSolidFillColor().setColor(Color.BLACK);
chart.getPlotArea().getFormat().getLine().setDashStyle(LineDashStyle.Dot);
chart.getPlotArea().getFormat().getLine().setWidth(0.75f);
IChartSeries usSeries = chart.getChartData().getSeries().add("US", chart.getType());
usSeries.getDataPoints().addDataPointForScatterSeries(workbook.getCell(worksheetIndex, 2, 1, usData[0].x),
workbook.getCell(worksheetIndex, 2, 2, usData[0].y));
usSeries.getDataPoints().addDataPointForScatterSeries(workbook.getCell(worksheetIndex, 3, 1, usData[1].x),
workbook.getCell(worksheetIndex, 3, 2, usData[1].y));
usSeries.getDataPoints().addDataPointForScatterSeries(workbook.getCell(worksheetIndex, 4, 1, usData[2].x),
workbook.getCell(worksheetIndex, 4, 2, usData[2].y));
usSeries.getDataPoints().addDataPointForScatterSeries(workbook.getCell(worksheetIndex, 5, 1, usData[3].x),
workbook.getCell(worksheetIndex, 5, 2, usData[3].y));
setArrowheadStyles(usSeries);
IChartSeries caSeries = chart.getChartData().getSeries().add("CA", chart.getType());
caSeries.getDataPoints().addDataPointForScatterSeries(workbook.getCell(worksheetIndex, 2, 3, caData[0].x),
workbook.getCell(worksheetIndex, 2, 4, caData[0].y));
caSeries.getDataPoints().addDataPointForScatterSeries(workbook.getCell(worksheetIndex, 3, 3, caData[1].x),
workbook.getCell(worksheetIndex, 3, 4, caData[1].y));
caSeries.getDataPoints().addDataPointForScatterSeries(workbook.getCell(worksheetIndex, 4, 3, caData[2].x),
workbook.getCell(worksheetIndex, 4, 4, caData[2].y));
caSeries.getDataPoints().addDataPointForScatterSeries(workbook.getCell(worksheetIndex, 5, 3, caData[3].x),
workbook.getCell(worksheetIndex, 5, 4, caData[3].y));
setArrowheadStyles(caSeries);
IChartSeries euSeries = chart.getChartData().getSeries().add("EU", chart.getType());
euSeries.getDataPoints().addDataPointForScatterSeries(workbook.getCell(worksheetIndex, 2, 5, euData[0].x),
workbook.getCell(worksheetIndex, 2, 6, euData[0].y));
euSeries.getDataPoints().addDataPointForScatterSeries(workbook.getCell(worksheetIndex, 3, 5, euData[1].x),
workbook.getCell(worksheetIndex, 3, 6, euData[1].y));
euSeries.getDataPoints().addDataPointForScatterSeries(workbook.getCell(worksheetIndex, 4, 5, euData[2].x),
workbook.getCell(worksheetIndex, 4, 6, euData[2].y));
euSeries.getDataPoints().addDataPointForScatterSeries(workbook.getCell(worksheetIndex, 5, 5, euData[3].x),
workbook.getCell(worksheetIndex, 5, 6, euData[3].y));
setArrowheadStyles(euSeries);
chart.getAxes().getHorizontalAxis().setCrossType(CrossesType.Custom);
chart.getAxes().getHorizontalAxis().setCrossAt(-0.5f);
chart.getAxes().getHorizontalAxis().setNumberFormat("# ##0.0\\%");
chart.getAxes().getHorizontalAxis().getTitle().addTextFrameForOverriding("Volume");
setAxisStyle(chart.getAxes().getHorizontalAxis());
chart.getAxes().getVerticalAxis().setNumberFormat("# ##0.00\\%");
chart.getAxes().getVerticalAxis().getTitle().addTextFrameForOverriding("Price");
setAxisStyle(chart.getAxes().getVerticalAxis());
presentation.save("ScatterWithSmoothLinesAndMarkers.pptx", SaveFormat.Pptx);
static void setArrowheadStyles(IChartSeries series)
{
series.getMarker().setSymbol(MarkerStyleType.None);
series.getFormat().getLine().setBeginArrowheadStyle(LineArrowheadStyle.Diamond);
series.getFormat().getLine().setBeginArrowheadWidth(LineArrowheadWidth.Wide);
series.getFormat().getLine().setBeginArrowheadLength(LineArrowheadLength.Long);
series.getFormat().getLine().setEndArrowheadStyle(LineArrowheadStyle.Oval);
series.getFormat().getLine().setEndArrowheadWidth(LineArrowheadWidth.Wide);
series.getFormat().getLine().setEndArrowheadLength(LineArrowheadLength.Long);
}
static void setAxisStyle(IAxis axis)
{
final IFontData font = new FontData("Arial");
final int fontSize = 10;
axis.getMajorGridLinesFormat().getLine().getFillFormat().setFillType(FillType.NoFill);
axis.getFormat().getLine().setWidth(2.0);
axis.getFormat().getLine().getFillFormat().setFillType(FillType.Solid);
axis.setTickLabelPosition(TickLabelPositionType.Low);
axis.setMajorTickMark(TickMarkType.None);
axis.getTextFormat().getPortionFormat().setFontHeight(fontSize);
axis.getTextFormat().getPortionFormat().setLatinFont(font);
axis.setNumberFormatLinkedToSource(false);
axis.setTitle(true);
axis.getTitle().setOverlay(false);
IParagraphFormat titlePortion = axis.getTitle().getTextFrameForOverriding().getParagraphs().get_Item(0).getParagraphFormat();
titlePortion.getDefaultPortionFormat().setFontHeight(fontSize);
titlePortion.getDefaultPortionFormat().setLatinFont(font);
titlePortion.getDefaultPortionFormat().setFontBold(NullableBool.False);
}