LoginSignup
0
0

More than 3 years have passed since last update.

Java PowerPointでグラフに傾向線を追加

Posted at

PowerPointでいろいろなグラフを作成することができます。今日はSpire.Presentation for Javaを使ってトレンドグラフを作る方法を紹介します。グラフに傾向線を追加すると、視覚的なデータの傾向を示すことができますね。

下準備

1.E-iceblueの公式サイトからFree Spire. Presentation for Java無料版をダウンロードしてください。

f:id:lendoris:20210317120248p:plain

2. IDEを起動して新規プロジェクトを作成してから、インストールされたファイルにあった相応しいSpire. Presentation.jarを参照に追加してください。

 f:id:lendoris:20210317120303p:plain

import com.spire.presentation.FileFormat;
import com.spire.presentation.ISlide;
import com.spire.presentation.Presentation;
import com.spire.presentation.charts.IChart;
import com.spire.presentation.charts.ITrendlines;
import com.spire.presentation.charts.TrendlineSimpleType;

public class AddTrendlineToChart {
    public static void main(String[] args) throws Exception {
        //Presentation objectを作成します。
        Presentation ppt = new Presentation();

        //PowerPointファイルをロードします。
        ppt.loadFromFile("Chart.pptx");

        //スライドを取得します。
        ISlide slide = ppt.getSlides().get(0);
        //スライドのチャートを取得します。
        IChart chart = (IChart)slide.getShapes().get(0);

        //チャートに傾向線を追加します。
        ITrendlines trendLine = chart.getSeries().get(0).addTrendLine(TrendlineSimpleType.LINEAR);
        //公式を非表示にします。
        //trendLine.setdisplayEquation(false);
        //Rの平方值を非表示にします。
        //trendLine.setdisplayRSquaredValue(false);

        //保存します。
        ppt.saveToFile("AddTrendline.pptx", FileFormat.PPTX_2013);
    }
}

実行結果

f:id:lendoris:20210317120349p:plain

 

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0