Format Presentation Charts in С++
Format Chart Entities
Aspose.Slides for C++ lets developers add custom charts to their slides from scratch. This article explains how to format different chart entities including chart category and value axis.
Aspose.Slides for C++ provides a simple API for managing different chart entities and formatting them using custom values:
- Create an instance of the Presentation class.
- Obtain a slide’s reference by its index.
- Add a chart with default data along with the any of the desired type (in this example we will use ChartType.LineWithMarkers).
- Access the chart Value Axis and set the following properties:
- Setting Line format for Value Axis Major Grid lines
- Setting Line format for Value Axis Minor Grid lines
- Setting Number Format for Value Axis
- Setting Min, Max, Major and Minor units for Value Axis
- Setting Text Properties for Value Axis data
- Setting Title for Value Axis
- Setting Line Format for Value Axis
- Access the chart Category Axis and set the following properties:
- Setting Line format for Category Axis Major Grid lines
- Setting Line format for Category Axis Minor Grid lines
- Setting Text Properties for Category Axis data
- Setting Title for Category Axis
- Setting Label Positioning for Category Axis
- Setting Rotation Angle for Category Axis labels
- Access the chart Legend and set the Text Properties for them
- Set show chart Legends without overlapping chart
- Access the chart Secondary Value Axis and set the following properties:
- Enable the Secondary Value Axis
- Setting Line Format for Secondary Value Axis
- Setting Number Format for Secondary Value Axis
- Setting Min, Max, Major and Minor units for Secondary Value Axis
- Now plot the first chart series on Secondary Value Axis
- Set the chart back wall to fill color
- Set the chart plot area fill color
- Write the modified presentation to a PPTX file
Set Font Properties for a Chart
Aspose.Slides for C++ provides support for setting the font related properties for the chart. Please follow the steps below for setting the font properties for chart.
- Instantiate Presentation class object.
- Add chart on the slide.
- Set font height.
- Save modified presentation.
Below sample example is given.
Set Font Properties for a Chart Data Table
Aspose.Slides for C++ provides support for changing color of categories in a series color.
- Instantiate Presentation class object.
- Add chart on the slide.
- set chart table.
- Set font height.
- Save modified presentation.
Below sample example is given.
Set Chart Area Rounded Borders
Aspose.Slides for C++ provides support for setting chart area. IChart.HasRoundedCorners and Chart.HasRoundedCorners properties have been added in Aspose.Slides.
- Instantiate Presentation class object.
- Add chart on the slide.
- Set fill type and fill color of chart
- Set round corner property True.
- Save modified presentation.
Below sample example is given.
Set the Numeric Format
Aspose.Slides for C++ provides a simple API for managing chart data format:
- Create an instance of the Presentation class.
- Obtain a slide’s reference by its index.
- Add a chart with default data along with the any of desired type (this example uses ChartType.ClusteredColumn).
- Set the preset number format from the possible preset values.
- Traverse through the chart data cell in every chart series and set the chart data number format.
- Save the presentation.
- Set the custom number format.
- Traverse through chart data cell inside every chart series and setting a different chart data number format.
- Save the presentation.
| The possible preset number format values along with their preset index and that can be used are given below: |
|---|
| 0 | General |
|---|---|
| 1 | 0 |
| 2 | 0.00 |
| 3 | #,##0 |
| 4 | #,##0.00 |
| 5 | $#,##0;$-#,##0 |
| 6 | $#,##0;Red$-#,##0 |
| 7 | $#,##0.00;$-#,##0.00 |
| 8 | $#,##0.00;Red$-#,##0.00 |
| 9 | 0% |
| 10 | 0.00% |
| 11 | 0.00E+00 |
| 12 | # ?/? |
| 13 | # / |
| 14 | m/d/yy |
| 15 | d-mmm-yy |
| 16 | d-mmm |
| 17 | mmm-yy |
| 18 | h:mm AM/PM |
| 19 | h:mm:ss AM/PM |
| 20 | h:mm |
| 21 | h:mm:ss |
| 22 | m/d/yy h:mm |
| 37 | #,##0;-#,##0 |
| 38 | #,##0;Red-#,##0 |
| 39 | #,##0.00;-#,##0.00 |
| 40 | #,##0.00;Red-#,##0.00 |
| 41 | _ * #,##0_ ;_ * “_ ;_ @_ |
| 42 | _ $* #,##0_ ;_ $* “_ ;_ @_ |
| 43 | _ * #,##0.00_ ;_ * “??_ ;_ @_ |
| 44 | _ $* #,##0.00_ ;_ $* “??_ ;_ @_ |
| 45 | mm:ss |
| 46 | h :mm:ss |
| 47 | mm:ss.0 |
| 48 | ##0.0E+00 |
| 49 | @ |
FAQ
Can I set semi-transparent fills for columns/areas while keeping the border opaque?
Yes. Fill transparency and the outline are configured separately. This is useful for improving the readability of the grid and data in dense visualizations.
How can I deal with data labels when they overlap?
Reduce the font size, disable nonessential label components (for example, categories), set the label offset/position, show labels only for selected points if necessary, or switch the format to “value + legend”.
Can I apply gradient or pattern fills to series?
Yes. Both solid and gradient/pattern fills are typically available. In practice, use gradients sparingly and avoid combinations that reduce contrast with the grid and text.