com.aspose.words

Class AxisDisplayUnit

  • java.lang.Object
    • com.aspose.words.AxisDisplayUnit
  • All Implemented Interfaces:
    java.lang.Cloneable
    public class AxisDisplayUnit 
    extends java.lang.Object

Provides access to the scaling options of the display units for the value axis.

Example:

Shows how to manipulate the tick marks and displayed values of a chart axis.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Insert a scatter chart, which is populated by default values
Shape shape = builder.insertChart(ChartType.SCATTER, 450.0, 250.0);
Chart chart = shape.getChart();

// Set they Y axis to show major ticks every at every 10 units and minor ticks at every 1 units
ChartAxis axis = chart.getAxisY();
axis.setMajorTickMark(AxisTickMark.OUTSIDE);
axis.setMinorTickMark(AxisTickMark.OUTSIDE);

axis.setMajorUnit(10.0);
axis.setMinorUnit(1.0);

// Stretch out the bounds of the axis out to show 3 major ticks and 27 minor ticks
axis.getScaling().setMinimum(new AxisBound(-10));
axis.getScaling().setMaximum(new AxisBound(20.0));

// Do the same for the X-axis
axis = chart.getAxisX();
axis.setMajorTickMark(AxisTickMark.INSIDE);
axis.setMinorTickMark(AxisTickMark.INSIDE);
axis.setMajorUnit(10.0);
axis.getScaling().setMinimum(new AxisBound(-10));
axis.getScaling().setMaximum(new AxisBound(30.0));

// We can also use this attribute to set minor tick spacing
axis.setTickLabelSpacing(2);
// We can define text alignment when axis tick labels are multi-line
// MS Word aligns them to the center by default
axis.setTickLabelAlignment(ParagraphAlignment.RIGHT);

// Get the axis to display values, but in millions
axis.getDisplayUnit().setUnit(AxisBuiltInUnit.MILLIONS);

// Besides the built-in axis units we can choose from,
// we can also set the axis to display values in some custom denomination, using the following attribute
// The statement below is equivalent to the one above
axis.getDisplayUnit().setCustomUnit(1000000.0);

doc.save(getArtifactsDir() + "Charts.ChartAxisDisplayUnit.docx");

Constructor Summary
 
Property Getters/Setters Summary
doublegetCustomUnit()
void
setCustomUnit(doublevalue)
           Gets or sets a user-defined divisor to scale display units on the value axis.
DocumentBasegetDocument()
Returns the Document the title holder belongs.
intgetUnit()
void
setUnit(intvalue)
           Gets or sets the scaling value of the display units as one of the predefined values. The value of the property is AxisBuiltInUnit integer constant.
 

    • Constructor Detail

      • AxisDisplayUnit

        public AxisDisplayUnit()
    • Property Getters/Setters Detail

      • getCustomUnit/setCustomUnit

        public double getCustomUnit() / public void setCustomUnit(double value)
        
        Gets or sets a user-defined divisor to scale display units on the value axis.

        The property is not supported by MS Office 2016 new charts. Default value is 1.

        Setting this property sets the Unit property to AxisBuiltInUnit.CUSTOM.

        Example:

        Shows how to manipulate the tick marks and displayed values of a chart axis.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Insert a scatter chart, which is populated by default values
        Shape shape = builder.insertChart(ChartType.SCATTER, 450.0, 250.0);
        Chart chart = shape.getChart();
        
        // Set they Y axis to show major ticks every at every 10 units and minor ticks at every 1 units
        ChartAxis axis = chart.getAxisY();
        axis.setMajorTickMark(AxisTickMark.OUTSIDE);
        axis.setMinorTickMark(AxisTickMark.OUTSIDE);
        
        axis.setMajorUnit(10.0);
        axis.setMinorUnit(1.0);
        
        // Stretch out the bounds of the axis out to show 3 major ticks and 27 minor ticks
        axis.getScaling().setMinimum(new AxisBound(-10));
        axis.getScaling().setMaximum(new AxisBound(20.0));
        
        // Do the same for the X-axis
        axis = chart.getAxisX();
        axis.setMajorTickMark(AxisTickMark.INSIDE);
        axis.setMinorTickMark(AxisTickMark.INSIDE);
        axis.setMajorUnit(10.0);
        axis.getScaling().setMinimum(new AxisBound(-10));
        axis.getScaling().setMaximum(new AxisBound(30.0));
        
        // We can also use this attribute to set minor tick spacing
        axis.setTickLabelSpacing(2);
        // We can define text alignment when axis tick labels are multi-line
        // MS Word aligns them to the center by default
        axis.setTickLabelAlignment(ParagraphAlignment.RIGHT);
        
        // Get the axis to display values, but in millions
        axis.getDisplayUnit().setUnit(AxisBuiltInUnit.MILLIONS);
        
        // Besides the built-in axis units we can choose from,
        // we can also set the axis to display values in some custom denomination, using the following attribute
        // The statement below is equivalent to the one above
        axis.getDisplayUnit().setCustomUnit(1000000.0);
        
        doc.save(getArtifactsDir() + "Charts.ChartAxisDisplayUnit.docx");
      • getDocument

        public DocumentBase getDocument()
        
        Returns the Document the title holder belongs.
      • getUnit/setUnit

        public int getUnit() / public void setUnit(int value)
        
        Gets or sets the scaling value of the display units as one of the predefined values. The value of the property is AxisBuiltInUnit integer constant. Default value is AxisBuiltInUnit.NONE. The AxisBuiltInUnit.CUSTOM and AxisBuiltInUnit.PERCENTAGE values are not available in some chart types; see AxisBuiltInUnit for more information.

        Example:

        Shows how to manipulate the tick marks and displayed values of a chart axis.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Insert a scatter chart, which is populated by default values
        Shape shape = builder.insertChart(ChartType.SCATTER, 450.0, 250.0);
        Chart chart = shape.getChart();
        
        // Set they Y axis to show major ticks every at every 10 units and minor ticks at every 1 units
        ChartAxis axis = chart.getAxisY();
        axis.setMajorTickMark(AxisTickMark.OUTSIDE);
        axis.setMinorTickMark(AxisTickMark.OUTSIDE);
        
        axis.setMajorUnit(10.0);
        axis.setMinorUnit(1.0);
        
        // Stretch out the bounds of the axis out to show 3 major ticks and 27 minor ticks
        axis.getScaling().setMinimum(new AxisBound(-10));
        axis.getScaling().setMaximum(new AxisBound(20.0));
        
        // Do the same for the X-axis
        axis = chart.getAxisX();
        axis.setMajorTickMark(AxisTickMark.INSIDE);
        axis.setMinorTickMark(AxisTickMark.INSIDE);
        axis.setMajorUnit(10.0);
        axis.getScaling().setMinimum(new AxisBound(-10));
        axis.getScaling().setMaximum(new AxisBound(30.0));
        
        // We can also use this attribute to set minor tick spacing
        axis.setTickLabelSpacing(2);
        // We can define text alignment when axis tick labels are multi-line
        // MS Word aligns them to the center by default
        axis.setTickLabelAlignment(ParagraphAlignment.RIGHT);
        
        // Get the axis to display values, but in millions
        axis.getDisplayUnit().setUnit(AxisBuiltInUnit.MILLIONS);
        
        // Besides the built-in axis units we can choose from,
        // we can also set the axis to display values in some custom denomination, using the following attribute
        // The statement below is equivalent to the one above
        axis.getDisplayUnit().setCustomUnit(1000000.0);
        
        doc.save(getArtifactsDir() + "Charts.ChartAxisDisplayUnit.docx");