Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

怎么更改生成的折线图的线的颜色? #104

Open
wangchunle opened this issue Feb 7, 2024 · 3 comments
Open

怎么更改生成的折线图的线的颜色? #104

wangchunle opened this issue Feb 7, 2024 · 3 comments

Comments

@wangchunle
Copy link

怎么更改生成的折线图的线的颜色?

@AlexNosk
Copy link

AlexNosk commented Feb 7, 2024

@wangchunle 您可以使用Stroke.Color设置折线图中线条的颜色。 例如看下面的代码:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Add chart with default data. You can specify different chart types and sizes.
Shape shape = builder.insertChart(ChartType.LINE, 432, 252);

// Chart property of Shape contains all chart related options.
Chart chart = shape.getChart();

// Get chart series collection.
ChartSeriesCollection seriesColl = chart.getSeries();

// Delete default generated series.
seriesColl.clear();

// Create category names array, in this example we have two categories.
String[] categories = new String[] { "AW Category 1", "AW Category 2" };

// Adding new series. Please note, data arrays must not be empty and arrays must be the same size.
ChartSeries s1 = seriesColl.add("AW Series 1", categories, new double[] { 1, 2 });
ChartSeries s2 = seriesColl.add("AW Series 2", categories, new double[] { 3, 4 });
ChartSeries s3 = seriesColl.add("AW Series 3", categories, new double[] { 5, 6 });
ChartSeries s4 = seriesColl.add("AW Series 4", categories, new double[] { 7, 8 });

// Set color of the lines
s1.getFormat().getStroke().setColor(Color.red);
s2.getFormat().getStroke().setColor(Color.black);
s3.getFormat().getStroke().setColor(Color.blue);
s4.getFormat().getStroke().setColor(Color.yellow);

doc.save("C:\\Temp\\out.docx");

PS: 获得支持的主要场所是 Aspose.Words 支持论坛。
https://forum.aspose.com/c/words/8/

@wangchunle
Copy link
Author

@AlexNosk 谢谢,请问getFormat()这个方法哪个版本才有?我现在项目里用的是19.5版本的,好像没有这个方法。

@AlexNosk
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants