Java를 사용하여 PowerPoint에 퍼즐을 만드는 방법

산포도는 이름과 같이 산포점으로 구성된 도표로 이 점들이 놓인 위치는 X값과 Y값에 의해 결정된다.그래서 XY 산포도라고도 불린다.본고는 자바 코드 예시를 사용하여 PowerPoint 슬라이드에 퍼즐을 만드는 방법을 소개한다.
차트를 생성하기 전에
PowerPoint를 조작하기 위해서jar 패키지Free Spire.Presentation for Java를 자바 프로그램에 가져와야 합니다.가져오려면 다음 방법을 참조하십시오.
jar 패키지를 수동으로 가져옵니다.로컬에서jar 패키지를 다운로드하고 압축을 풀고lib 폴더에서jar 파일을 찾아야 합니다.다음은 다음 순서에 따라 가져옵니다.



차트를 만들 때
슬라이드에서 지정한 좌표에 도표를 삽입할 데이터 원본을 지정합니다.Jar 패키지는 슬라이드의 ShapeCollection에 특정 유형의 차트를 추가하기 위한 것입니다.appeendChart(ChartType type, Rectangle2 Dreactangle,boolean init) 방법을 제공합니다.ChartType은 산포도, 기둥형, 떡그림을 포함하여 미리 정의된 73개의 도표 유형을 열거합니다.그래프 등
이번 산포도는 주로 다음과 같은 순서에 따라 제작된다.
Procentation 클래스의 인스턴스를 생성합니다.
ShapeCollection.appeendChart () 방법을 사용하여 배포도를 특정 슬라이드에 추가합니다.
ChartData.get().setValue() 방법을 사용하여 차트 데이터를 설정합니다.
IChart 인터페이스에서 제공하는 방법을 사용하여 도표 제목, 축 제목, 시리즈 라벨 등을 설정합니다.
격자 스타일과 데이터 점의 선 스타일을 설정합니다.
Presentation.saveToFile() 방법을 사용하여 지정된 경로에 문서를 저장합니다.
Java 코드 일람표
import com.spire.presentation.FileFormat;
import com.spire.presentation.Presentation;
import com.spire.presentation.SlideSizeType;
import com.spire.presentation.TextLineStyle;
import com.spire.presentation.charts.ChartType;
import com.spire.presentation.charts.IChart;
import com.spire.presentation.charts.entity.ChartDataLabel;
import com.spire.presentation.drawing.FillFormatType;

import java.awt.*;
import java.awt.geom.Rectangle2D;

public class ScatterChart {
    public static void main(String[] args) throws Exception{
        //Presentationクラスのインスタンスを作成する
        Presentation presentation = new Presentation();
        presentation.getSlideSize().setType(SlideSizeType.SCREEN_16_X_9);

        //最初のスライドに散布図を追加する
        IChart chart = presentation.getSlides().get(0).getShapes().appendChart(ChartType.SCATTER_MARKERS,new Rectangle2D.Float(180, 80, 550, 320),false);

        //チャートタイトルを設定する
        chart.getChartTitle().getTextProperties().setText("散布図");
        chart.getChartTitle().getTextProperties().isCentered(true);
        chart.getChartTitle().setHeight(20f);
        chart.hasTitle(true);

        //グラフのデータソースを設定する
        Double[] xData = new Double[] { 1.0, 2.4, 5.0, 8.9 };
        Double[] yData = new Double[] { 5.3, 15.2, 6.7, 8.0 };
        chart.getChartData().get(0,0).setText("X-值");
        chart.getChartData().get(0,1).setText("Y-值");
        for (int i = 0; i < xData.length; i++) {
            chart.getChartData().get(i+1,0).setValue(xData[i]);
            chart.getChartData().get(i+1,1).setValue(yData[i]);
        }

        //シリーズラベルを設定する
        chart.getSeries().setSeriesLabel(chart.getChartData().get("B1","B1"));

        //X軸とY軸の値を設定する
        chart.getSeries().get(0).setXValues(chart.getChartData().get("A2","A5"));
        chart.getSeries().get(0).setYValues(chart.getChartData().get("B2","B5"));

        //データラベルを追加する
        for (int i = 0; i < 4; i++)
        {
            ChartDataLabel dataLabel = chart.getSeries().get(0).getDataLabels().add();
            dataLabel.setLabelValueVisible(true);
        }

        //一次軸と二次軸のタイトルを設定する
        chart.getPrimaryValueAxis().hasTitle(true);
        chart.getPrimaryValueAxis().getTitle().getTextProperties().setText("X轴 タイトル");
        chart.getSecondaryValueAxis().hasTitle(true);
        chart.getSecondaryValueAxis().getTitle().getTextProperties().setText("Y轴 タイトル");

        //グリッド線を設定する
        chart.getSecondaryValueAxis().getMajorGridTextLines().setFillType(FillFormatType.SOLID);
        chart.getSecondaryValueAxis().getMajorGridTextLines().setStyle(TextLineStyle.THIN_THIN);
        chart.getSecondaryValueAxis().getMajorGridTextLines().getSolidFillColor().setColor(Color.GRAY);
        chart.getPrimaryValueAxis().getMajorGridTextLines().setFillType(FillFormatType.NONE);

        //データポイントラインを設定する
        chart.getSeries().get(0).getLine().setFillType(FillFormatType.SOLID);
        chart.getSeries().get(0).getLine().setWidth(0.1f);
        chart.getSeries().get(0).getLine().getSolidFillColor().setColor(Color.BLUE);

        //ドキュメントを保存する
        presentation.saveToFile("ScatterChart.pptx", FileFormat.PPTX_2013);
        presentation.dispose();
    }
}

결어
지금까지 PowerPoint에서 퍼즐을 만드는 방법입니다. 끝까지 읽어주셔서 감사합니다.

좋은 웹페이지 즐겨찾기