误差线
Contents
[
Hide
]
添加误差线
Aspose.Slides for C++ 提供了一个简单的 API 来管理误差线值。示例代码适用于使用自定义值类型的情况。要指定一个值,请使用 ErrorBarCustomValues 属性在系列的 DataPoints 集合中特定数据点上:
- 创建一个 Presentation 类的实例。
- 在所需的幻灯片上添加一个气泡图表。
- 访问第一个图表系列并设置误差线 X 格式。
- 访问第一个图表系列并设置误差线 Y 格式。
- 设置误差线值和格式。
- 将修改后的演示文稿写入 PPTX 文件。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
For complete examples and data files, please go to https://github.com/aspose-slides/Aspose.Slides-for-C | |
// The path to the documents directory. | |
const String outPath = u"../out/ErrorBars_out.pptx"; | |
//Instantiate Presentation class that represents PPTX file | |
SharedPtr<Presentation> pres = MakeObject<Presentation>(); | |
//Access first slide | |
SharedPtr<ISlide> sld = pres->get_Slides()->idx_get(0); | |
// Add chart with default data | |
SharedPtr<IChart> chart = sld->get_Shapes()->AddChart(Aspose::Slides::Charts::ChartType::Bubble, 0, 0, 500, 500, true); | |
// Adding custom Error chart and setting its format | |
SharedPtr<IChartSeries> series = chart->get_ChartData()->get_Series()->idx_get(0); | |
SharedPtr<IErrorBarsFormat> errBarX = series->get_ErrorBarsXFormat(); | |
SharedPtr<IErrorBarsFormat> errBarY = series->get_ErrorBarsYFormat(); | |
errBarX->set_IsVisible(true); | |
errBarY->set_IsVisible(true); | |
errBarX->set_ValueType(ErrorBarValueType::Fixed); | |
errBarX->set_Value( 0.1f); | |
errBarY->set_ValueType(ErrorBarValueType::Percentage); | |
errBarX->set_Value(5); | |
errBarX->set_Type (ErrorBarType::Plus); | |
errBarY->get_Format()->get_Line()->set_Width(2); | |
errBarX->set_HasEndCap ( true); | |
// Saving presentation | |
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx); |
添加自定义误差线
Aspose.Slides for C++ 提供了一个简单的 API 来管理自定义误差线值。示例代码适用于 IErrorBarsFormat.ValueType 属性等于 Custom 的情况。要指定一个值,请使用 ErrorBarCustomValues 属性在系列的 DataPoints 集合中特定数据点上:
- 创建一个 Presentation 类的实例。
- 在所需的幻灯片上添加一个气泡图表。
- 访问第一个图表系列并设置误差线 X 格式。
- 访问第一个图表系列并设置误差线 Y 格式。
- 访问图表系列的单个数据点并为单个系列数据点设置误差线值。
- 设置误差线值和格式。
- 将修改后的演示文稿写入 PPTX 文件。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
For complete examples and data files, please go to https://github.com/aspose-slides/Aspose.Slides-for-C | |
// The path to the documents directory. | |
const String outPath = u"../out/ErrorBarsCustomValues_out.pptx"; | |
//Instantiate Presentation class that represents PPTX file | |
SharedPtr<Presentation> pres = MakeObject<Presentation>(); | |
//Access first slide | |
SharedPtr<ISlide> sld = pres->get_Slides()->idx_get(0); | |
// Add chart with default data | |
SharedPtr<IChart> chart = sld->get_Shapes()->AddChart(Aspose::Slides::Charts::ChartType::Bubble, 0, 0, 500, 500,true); | |
// Adding custom Error chart and setting its format | |
SharedPtr<IChartSeries> series = chart->get_ChartData()->get_Series()->idx_get(0); | |
SharedPtr<IErrorBarsFormat> errBarX = series->get_ErrorBarsXFormat(); | |
SharedPtr<IErrorBarsFormat> errBarY = series->get_ErrorBarsYFormat(); | |
errBarX->set_IsVisible(true); | |
errBarY->set_IsVisible(true); | |
errBarX->set_ValueType(ErrorBarValueType::Custom); | |
errBarY->set_ValueType(ErrorBarValueType::Custom); | |
// Accessing chart series data point and setting error bars values for individual point | |
SharedPtr<IChartDataPointCollection> points = series->get_DataPoints(); | |
points->get_DataSourceTypeForErrorBarsCustomValues()->set_DataSourceTypeForXPlusValues(DataSourceType::DoubleLiterals); | |
points->get_DataSourceTypeForErrorBarsCustomValues()->set_DataSourceTypeForXMinusValues(DataSourceType::DoubleLiterals); | |
points->get_DataSourceTypeForErrorBarsCustomValues()->set_DataSourceTypeForYPlusValues (DataSourceType::DoubleLiterals); | |
points->get_DataSourceTypeForErrorBarsCustomValues()->set_DataSourceTypeForYMinusValues(DataSourceType::DoubleLiterals); | |
// Setting error bars for chart series points | |
for (int i = 0; i < points->get_Count(); i++) | |
{ | |
points->idx_get(i)->get_ErrorBarsCustomValues()->get_XMinus()->set_AsLiteralDouble(i + 1); | |
points->idx_get(i)->get_ErrorBarsCustomValues()->get_XPlus()->set_AsLiteralDouble (i + 1); | |
points->idx_get(i)->get_ErrorBarsCustomValues()->get_YMinus()->set_AsLiteralDouble( i + 1); | |
points->idx_get(i)->get_ErrorBarsCustomValues()->get_YPlus()->set_AsLiteralDouble ( i + 1); | |
} | |
// Saving presentation | |
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx); |