图表计算

计算图表元素的实际值

Aspose.Slides for PHP via Java 提供了一个简单的API来获取这些属性。IAxis 接口的属性提供有关轴图表元素实际位置的信息(IAxis.getActualMaxValueIAxis.getActualMinValueIAxis.getActualMajorUnitIAxis.getActualMinorUnitIAxis.getActualMajorUnitScaleIAxis.getActualMinorUnitScale)。必须事先调用方法 IChart.validateChartLayout() 以用实际值填充属性。

  $pres = new Presentation();
  try {
    $chart = $pres->getSlides()->get_Item(0)->getShapes()->addChart(ChartType::Area, 100, 100, 500, 350);
    $chart->validateChartLayout();
    $maxValue = $chart->getAxes()->getVerticalAxis()->getActualMaxValue();
    $minValue = $chart->getAxes()->getVerticalAxis()->getActualMinValue();
    $majorUnit = $chart->getAxes()->getHorizontalAxis()->getActualMajorUnit();
    $minorUnit = $chart->getAxes()->getHorizontalAxis()->getActualMinorUnit();
  } finally {
    if (!java_is_null($pres)) {
      $pres->dispose();
    }
  }

计算父图表元素的实际位置

Aspose.Slides for PHP via Java 提供了一个简单的API来获取这些属性。IActualLayout 接口的属性提供有关父图表元素实际位置的信息(IActualLayout.getActualXIActualLayout.getActualYIActualLayout.getActualWidthIActualLayout.getActualHeight)。必须事先调用方法 IChart.validateChartLayout() 以用实际值填充属性。

  $pres = new Presentation();
  try {
    $chart = $pres->getSlides()->get_Item(0)->getShapes()->addChart(ChartType::ClusteredColumn, 100, 100, 500, 350);
    $chart->validateChartLayout();
    $x = $chart->getPlotArea()->getActualX();
    $y = $chart->getPlotArea()->getActualY();
    $w = $chart->getPlotArea()->getActualWidth();
    $h = $chart->getPlotArea()->getActualHeight();
  } finally {
    if (!java_is_null($pres)) {
      $pres->dispose();
    }
  }

从图表中隐藏信息

本主题帮助您理解如何从图表中隐藏信息。使用 Aspose.Slides for PHP via Java,您可以从图表中隐藏 标题、纵轴、横轴网格线。下面的代码示例展示了如何使用这些属性。

  $pres = new Presentation();
  try {
    $slide = $pres->getSlides()->get_Item(0);
    $chart = $slide->getShapes()->addChart(ChartType::LineWithMarkers, 140, 118, 320, 370);
    # 隐藏图表标题
    $chart->setTitle(false);
    # /隐藏值轴
    $chart->getAxes()->getVerticalAxis()->setVisible(false);
    # 类别轴可见性
    $chart->getAxes()->getHorizontalAxis()->setVisible(false);
    # 隐藏图例
    $chart->setLegend(false);
    # 隐藏主网格线
    $chart->getAxes()->getHorizontalAxis()->getMajorGridLinesFormat()->getLine()->getFillFormat()->setFillType(FillType::NoFill);
    for($i = 0; $i < java_values($chart->getChartData()->getSeries()->size()) ; $i++) {
      $chart->getChartData()->getSeries()->removeAt($i);
    }
    $series = $chart->getChartData()->getSeries()->get_Item(0);
    $series->getMarker()->setSymbol(MarkerStyleType::Circle);
    $series->getLabels()->getDefaultDataLabelFormat()->setShowValue(true);
    $series->getLabels()->getDefaultDataLabelFormat()->setPosition(LegendDataLabelPosition->Top);
    $series->getMarker()->setSize(15);
    # 设置系列线颜色
    $series->getFormat()->getLine()->getFillFormat()->setFillType(FillType::Solid);
    $series->getFormat()->getLine()->getFillFormat()->getSolidFillColor()->setColor(java("java.awt.Color")->MAGENTA);
    $series->getFormat()->getLine()->setDashStyle(LineDashStyle->Solid);
    $pres->save("HideInformationFromChart.pptx", SaveFormat::Pptx);
  } finally {
    if (!java_is_null($pres)) {
      $pres->dispose();
    }
  }