Trend Line
Contents
[
Hide
]
Add Trend Line
Aspose.Slides for Node.js via Java provides a simple API for managing different chart Trend Lines:
- Create an instance of the Presentation class.
- Obtain a slide’s reference by its index.
- Add a chart with default data along with the any of desired type (this example uses ChartType.ClusteredColumn).
- Adding exponential trend line for chart series 1.
- Adding linear trend line for chart series 1.
- Adding logarithmic trend line for chart series 2.
- Adding moving average trend line for chart series 2.
- Adding polynomial trend line for chart series 3.
- Adding power trend line for chart series 3.
- Write the modified presentation to a PPTX file.
The following code is used to create a chart with Trend Lines.
// Create an instance of Presentation class
var pres = new aspose.slides.Presentation();
try {
// Creating a clustered column chart
var chart = pres.getSlides().get_Item(0).getShapes().addChart(aspose.slides.ChartType.ClusteredColumn, 20, 20, 500, 400);
// Adding ponential trend line for chart series 1
var tredLinep = chart.getChartData().getSeries().get_Item(0).getTrendLines().add(aspose.slides.TrendlineType.Exponential);
tredLinep.setDisplayEquation(false);
tredLinep.setDisplayRSquaredValue(false);
// Adding Linear trend line for chart series 1
var tredLineLin = chart.getChartData().getSeries().get_Item(0).getTrendLines().add(aspose.slides.TrendlineType.Linear);
tredLineLin.setTrendlineType(aspose.slides.TrendlineType.Linear);
tredLineLin.getFormat().getLine().getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Solid));
tredLineLin.getFormat().getLine().getFillFormat().getSolidFillColor().setColor(java.getStaticFieldValue("java.awt.Color", "RED"));
// Adding Logarithmic trend line for chart series 2
var tredLineLog = chart.getChartData().getSeries().get_Item(1).getTrendLines().add(aspose.slides.TrendlineType.Logarithmic);
tredLineLog.setTrendlineType(aspose.slides.TrendlineType.Logarithmic);
tredLineLog.addTextFrameForOverriding("New log trend line");
// Adding MovingAverage trend line for chart series 2
var tredLineMovAvg = chart.getChartData().getSeries().get_Item(1).getTrendLines().add(aspose.slides.TrendlineType.MovingAverage);
tredLineMovAvg.setTrendlineType(aspose.slides.TrendlineType.MovingAverage);
tredLineMovAvg.setPeriod(3);
tredLineMovAvg.setTrendlineName("New TrendLine Name");
// Adding Polynomial trend line for chart series 3
var tredLinePol = chart.getChartData().getSeries().get_Item(2).getTrendLines().add(aspose.slides.TrendlineType.Polynomial);
tredLinePol.setTrendlineType(aspose.slides.TrendlineType.Polynomial);
tredLinePol.setForward(1);
tredLinePol.setOrder(3);
// Adding Power trend line for chart series 3
var tredLinePower = chart.getChartData().getSeries().get_Item(1).getTrendLines().add(aspose.slides.TrendlineType.Power);
tredLinePower.setTrendlineType(aspose.slides.TrendlineType.Power);
tredLinePower.setBackward(1);
// Saving presentation
pres.save("ChartTrendLines_out.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
if (pres != null) {
pres.dispose();
}
}
Add Custom Line
Aspose.Slides for Node.js via Java provides a simple API to add custom lines in a chart. To add a simple plain line to a selected slide of the presentation, please follow the steps below:
- Create an instance of Presentation class
- Obtain the reference of a slide by using its Index
- Create a new chart using AddChart method exposed by Shapes object
- Add an AutoShape of Line type using AddAutoShape method exposed by Shapes object
- Set the Color of the shape lines.
- Write the modified presentation as a PPTX file
The following code is used to create a chart with Custom Lines.
// Create an instance of Presentation class
var pres = new aspose.slides.Presentation();
try {
var chart = pres.getSlides().get_Item(0).getShapes().addChart(aspose.slides.ChartType.ClusteredColumn, 100, 100, 500, 400);
var shape = chart.getUserShapes().getShapes().addAutoShape(aspose.slides.ShapeType.Line, 0, chart.getHeight() / 2, chart.getWidth(), 0);
shape.getLineFormat().getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Solid));
shape.getLineFormat().getFillFormat().getSolidFillColor().setColor(java.getStaticFieldValue("java.awt.Color", "RED"));
pres.save("Presentation.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
if (pres != null) {
pres.dispose();
}
}