Error Bar
Add Error Bar
Aspose.Slides for C++ provides a simple API for managing error bar values. The sample code applies when using a custom value type. To specify a value, use the ErrorBarCustomValues property of a specific data point in the DataPoints collection of series:
- Create an instance of the Presentation class.
- Add a bubble chart on the desired slide.
- Access the first chart series and set the error bar X format.
- Access the first chart series and set the error bar Y format.
- Setting bars values and format.
- Write the modified presentation to a PPTX file.
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); |
Add Custom Error Bar
Aspose.Slides for C++ provides a simple API for managing custom error bar values. The sample code applies when IErrorBarsFormat.ValueType property is equal to Custom. To specify a value, use the ErrorBarCustomValues property of a specific data point in the DataPoints collection of series:
- Create an instance of the Presentation class.
- Add a bubble chart on the desired slide.
- Access the first chart series and set the error bar X format.
- Access the first chart series and set the error bar Y format.
- Access the chart series individual data points and setting the Error Bar values for an individual series data point.
- Setting bars values and format.
- Write the modified presentation to a PPTX file.
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); |