Pie Chart
Second Plot Options for Pie of Pie and Bar of Pie Chart
Aspose.Slides for C++ now supports, second plot options for Pie of Pie or Bar of Pie chart. In this topic, we will see with example how to Specify these options using Aspose.Slides. In order to specify the properties. Please follow the steps below:
- Instantiate Presentation class object.
- Add chart on the slide.
- Specify the second plot options of chart.
- Write presentation to disk.
In the example given below, we have set different properties of Pie of Pie chart.
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/SecondPlotOptionsforCharts_out.pptx"; | |
//Instantiate Presentation class that represents PPTX file | |
SharedPtr<Presentation> pres = MakeObject<Presentation>(); | |
//Access first slide | |
SharedPtr<ISlide> slide = pres->get_Slides()->idx_get(0); | |
// Add chart with default data | |
SharedPtr<IChart> chart = slide->get_Shapes()->AddChart(Aspose::Slides::Charts::ChartType::Pie, 0, 0, 500, 500); | |
// Take first chart series | |
SharedPtr<IChartSeries> series = chart->get_ChartData()->get_Series()->idx_get(0); | |
// Set different properties | |
series->get_Labels()->get_DefaultDataLabelFormat()->set_ShowValue(true); | |
series->get_ParentSeriesGroup()->set_SecondPieSize ( 149); | |
series->get_ParentSeriesGroup()->set_PieSplitBy ( Aspose::Slides::Charts::PieSplitType::ByPercentage); | |
series->get_ParentSeriesGroup()->set_PieSplitPosition ( 53); | |
// Write the presentation file to disk | |
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx); | |
Set Automatic Pie Chart Slice Colors
Aspose.Slides for C++ provides a simple API for setting automatic pie chart slide colors. The sample code applies setting the above said properties.
- Create an instance of the Presentation class.
- Access first slide.
- Add chart with default data.
- Set chart Title.
- Set first series to Show Values.
- Set the index of chart data sheet.
- Getting the chart data worksheet.
- Delete default generated series and categories.
- Add new categories.
- Add new series.
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/AutomicPieChartSliceColors_out.pptx"; | |
//Instantiate Presentation class that represents PPTX file | |
SharedPtr<Presentation> pres = MakeObject<Presentation>(); | |
//Access first slide | |
SharedPtr<ISlide> slide = pres->get_Slides()->idx_get(0); | |
// Add chart with default data | |
SharedPtr<IChart> chart = slide->get_Shapes()->AddChart(Aspose::Slides::Charts::ChartType::Pie, 0, 0, 500, 500); | |
// Setting chart Title | |
chart->get_ChartTitle()->AddTextFrameForOverriding(u"Sample Title"); | |
chart->get_ChartTitle()->get_TextFrameForOverriding()->get_TextFrameFormat()->set_CenterText(NullableBool::True); | |
chart->get_ChartTitle()->set_Height(20); | |
chart->set_HasTitle(true); | |
// Delete default generated series and categories | |
chart->get_ChartData()->get_Series()->Clear(); | |
chart->get_ChartData()->get_Categories()->Clear(); | |
// Setting the index of chart data sheet | |
int defaultWorksheetIndex = 0; | |
// Getting the chart data worksheet | |
SharedPtr<IChartDataWorkbook> fact = chart->get_ChartData()->get_ChartDataWorkbook(); | |
// Add Catrgories | |
chart->get_ChartData()->get_Categories()->Add(fact->GetCell(defaultWorksheetIndex, 1, 0, ObjectExt::Box<System::String>(u"First Qtr"))); | |
chart->get_ChartData()->get_Categories()->Add(fact->GetCell(defaultWorksheetIndex, 2, 0, ObjectExt::Box<System::String>(u"2nd Qtr"))); | |
chart->get_ChartData()->get_Categories()->Add(fact->GetCell(defaultWorksheetIndex, 3, 0, ObjectExt::Box<System::String>(u"3ed Qtr"))); | |
// Now, Adding a new series | |
chart->get_ChartData()->get_Series()->Add(fact->GetCell(defaultWorksheetIndex, 0, 1, ObjectExt::Box<System::String>(u"Series 1")), chart->get_Type()); | |
// Take first chart series | |
SharedPtr<IChartSeries> series = chart->get_ChartData()->get_Series()->idx_get(0); | |
// Now populating series data | |
series->get_DataPoints()->AddDataPointForPieSeries(fact->GetCell(defaultWorksheetIndex, 1, 1, ObjectExt::Box<double>(20))); | |
series->get_DataPoints()->AddDataPointForPieSeries(fact->GetCell(defaultWorksheetIndex, 2, 1, ObjectExt::Box<double>(50))); | |
series->get_DataPoints()->AddDataPointForPieSeries(fact->GetCell(defaultWorksheetIndex, 3, 1, ObjectExt::Box<double>(30))); | |
chart->get_ChartData()->get_SeriesGroups()->idx_get(0)->set_IsColorVaried(true); | |
// Write the presentation file to disk | |
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx); | |