Робота з ChartSeries
Aspose.Words дозволяє користувачам працювати з ChartSeriesCollection кількома способами.
Робота з ChartSeriesCollection діаграми
Давайте заглянемо в колекцію ChartSeries. Усі серії діаграм доступні через ChartSeriesCollection:
For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C | |
// Get chart series collection. | |
System::SharedPtr<ChartSeriesCollection> seriesColl = chart->get_Series(); | |
// Check series count. | |
std::cout << seriesColl->get_Count() << std::endl; |
Робота з одним класом ChartSeries
Ось як працювати з конкретною серією:
For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C | |
// Get first series. | |
System::SharedPtr<ChartSeries> series0 = shape->get_Chart()->get_Series()->idx_get(0); | |
// Get second series. | |
System::SharedPtr<ChartSeries> series1 = shape->get_Chart()->get_Series()->idx_get(1); | |
// Change first series name. | |
series0->set_Name(u"My Name1"); | |
// Change second series name. | |
series1->set_Name(u"My Name2"); | |
// You can also specify whether the line connecting the points on the chart shall be smoothed using Catmull-Rom splines. | |
series0->set_Smooth(true); | |
series1->set_Smooth(true); |
Будь ласка, ознайомтеся з результатом нижче:
Усі окремі ChartSeries мають параметри за замовчуванням ChartDataPoint, Будь ласка, спробуйте змінити їх за допомогою наступного коду:
For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C | |
// Specifies whether by default the parent element shall inverts its colors if the value is negative. | |
series0->set_InvertIfNegative(true); | |
// Set default marker symbol and size. | |
series0->get_Marker()->set_Symbol(MarkerSymbol::Circle); | |
series0->get_Marker()->set_Size(15); | |
series1->get_Marker()->set_Symbol(MarkerSymbol::Star); | |
series1->get_Marker()->set_Size(10); |
Як працювати з одним ChartDataPoint з ChartSeries
Використовуючи ChartDataPoint, ви можете налаштувати форматування окремої точки даних у ряді діаграм:
For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C | |
// The path to the documents directory. | |
System::String outputDataDir = GetOutputDataDir_WorkingWithCharts(); | |
System::SharedPtr<Document> doc = System::MakeObject<Document>(); | |
System::SharedPtr<DocumentBuilder> builder = System::MakeObject<DocumentBuilder>(doc); | |
System::SharedPtr<Shape> shape = builder->InsertChart(ChartType::Line, 432, 252); | |
System::SharedPtr<Chart> chart = shape->get_Chart(); | |
// Get first series. | |
System::SharedPtr<ChartSeries> series0 = shape->get_Chart()->get_Series()->idx_get(0); | |
// Get second series. | |
System::SharedPtr<ChartSeries> series1 = shape->get_Chart()->get_Series()->idx_get(1); | |
System::SharedPtr<ChartDataPointCollection> dataPointCollection = series0->get_DataPoints(); | |
// Set explosion. | |
dataPointCollection->idx_get(0)->set_Explosion(50); | |
// Set marker symbol and size. | |
dataPointCollection->idx_get(0)->get_Marker()->set_Symbol(MarkerSymbol::Circle); | |
dataPointCollection->idx_get(0)->get_Marker()->set_Size(15); | |
dataPointCollection->idx_get(1)->get_Marker()->set_Symbol(MarkerSymbol::Diamond); | |
dataPointCollection->idx_get(1)->get_Marker()->set_Size(20); | |
// Add data point to the third point of the second series. | |
series1->get_DataPoints()->idx_get(2)->set_InvertIfNegative(true); | |
series1->get_DataPoints()->idx_get(2)->get_Marker()->set_Symbol(MarkerSymbol::Star); | |
series1->get_DataPoints()->idx_get(2)->get_Marker()->set_Size(20); | |
System::String outputPath = outputDataDir + u"WorkWithSingleChartDataPoint.docx"; | |
doc->Save(outputPath); |
Будь ласка, ознайомтеся з результатом нижче: