Scatter-WithLine1.zip (34.7 KB)
Could you please help me write a code snippet to draw chart on ppt provided in the zip file.
If possible I need a code snippet with cells to plot chart in Excel. For same example
Scatter-WithLine1.zip (34.7 KB)
Could you please help me write a code snippet to draw chart on ppt provided in the zip file.
If possible I need a code snippet with cells to plot chart in Excel. For same example
@VaradS,
Thank you for the sample chart. Unfortunately, I was unable to write a code example to create the chart you provided.
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): SLIDESJAVA-39532
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
@VaradS,
Please use the following code example:
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);
}
The result:
ScatterWithSmoothLinesAndMarkers.zip (30.5 KB)
More examples:
Create or Update PowerPoint Presentation Charts in Java|Aspose.Slides Documentation
Thanks for the code example, could you help me with setting following configs to series for the chart in Excel. Using Cells library.
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);
}
@VaradS,
Please contact my colleagues on the Aspose.Cells forum. They will be happy to help you with this.
Hi @andrey.potapov and team,
Could you please let me know how to change color of series here?
currently we have green color for euSeries I want dark blue shade instead.
@VaradS,
Thank you for your patience. To change the color of the series, you can use the ILineFormat interface as below:
Color euSeriesColor = new Color(0, 0, 200);
ILineFormat lineFillFormat = euSeries.getFormat().getLine();
lineFillFormat.getFillFormat().setFillType(FillType.Solid);
lineFillFormat.getFillFormat().getSolidFillColor().setColor(euSeriesColor);
More examples: Chart Series|Aspose.Slides Documentation
Thanks for your reply, whenever I’m applying color using these lines. I’m not getting the lines itself.
If we see the series configs in ppt for line I can see the solid line is selected. Do you think any extra setting I’m doing which can cause this issue?
image.png (6.5 KB)
image.png (15.9 KB)
@VaradS,
We need more details to investigate the case. Could you please share the simplest code example to reproduce the problem?
@VaradS,
We are glad that the issue has been resolved on your end. Thank you for using Aspose.Slides.