When I try to create a chart in word, I can not find a way to add Trendline on the chart.
I use this code:
public static void WordInsertChart(string wordPath)
{
Document document = new Document(wordPath);
DocumentBuilder builder = new DocumentBuilder(document);
// Add chart with default data. You can specify different chart types and sizes.
Aspose.Words.Drawing.Shape shape = builder.InsertChart(ChartType.Scatter, 432, 252);
// Chart property of Shape contains all chart related options.
Chart chart = shape.Chart;
// Get chart series collection.
ChartSeriesCollection seriesColl = chart.Series;
// Delete default generated series.
seriesColl.Clear();
// Create category names array, in this example we have two categories.
double[] xvalues = new double[] { 1000, 2000, 3000, 4000, 5000 };
double[] yvalues = new double[] { 10.2, 19.7, 29.5, 39.5, 49.2 };
// Adding new series. Please note, data arrays must not be empty and arrays must be the same size.
ChartSeries series = seriesColl.Add("Title", xvalues, yvalues);
series.Format.Stroke.ForeColor = Color.Blue;
series.Format.Stroke.Weight = 2;
series.Marker.Format.Fill.ForeColor = Color.Blue;
series.Marker.Format.Stroke.ForeColor = Color.Blue;
series.Marker.Size = 4;
series.Smooth = true;
//only in Aspose Cells
//Trendline trendLine = chart.NSeries[0].Add;
document.Save(wordPath);
}
In Excel there is a class Trendline, how to add Trendline in Word?
I want this result:
image.png (212.0 KB)
Test.docx (22.2 KB)