0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Androidで(Excel)グラフを作成

Last updated at Posted at 2018-10-28

#入力
s3.JPG

#結果

グラフ効果図.gif

#取り込み方法

###下記のPKGをそのまま取り込む
package com.yanheng.drawgraph.graph

xmlをに追加

※:今回はボタンを押下したら描画開始するイメージです。

<Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="グラフ生成する"
    android:layout_margin="30dp"
    />

<com.yanheng.drawgraph.graph.DrawViewDemo
    android:id="@+id/draw_view"
    android:layout_margin="50dp"
    android:layout_width="300dp"
    android:layout_height="200dp"
    android:background="#2260A8FF"
    />

###ボタン押下後処理

private void setGraph() {
    createSettingData();
    createGraphData();
    DrawViewDemo drawViewDemo = (DrawViewDemo) findViewById(R.id.draw_view);
    drawViewDemo.setGraphSettingData(graphSettingData);
    drawViewDemo.setGraph1(graphMail);
    drawViewDemo.setGraph2(graphFemail);
    drawViewDemo.invalidate();
}
  • X軸、Y軸の設定

      private void createSettingData() {
      graphSettingData = new GraphSettingData();
      graphSettingData.title = "身長グラフ";
      graphSettingData.graphNmae1="男の子";
      graphSettingData.graphNmae2="女の子";
    
      graphSettingData.axisDataX.maxScale = 18f;
      graphSettingData.axisDataX.minScale = 10f;
      graphSettingData.axisDataX.scaleValue = 1f;
      graphSettingData.axisDataX.scaleTitle = "年齢(歳)";
    
      graphSettingData.axisDataY.maxScale = 180f;
      graphSettingData.axisDataY.minScale = 120f;
      graphSettingData.axisDataY.scaleValue = 10f;
      graphSettingData.axisDataY.scaleTitle = "身長(cm)";
      }
    
  • グラフ評価の設定上記データを使用する

      private void createGraphData(){
      graphMail.put(10f, 138.9f);
      graphMail.put(11f, 145f);
      graphMail.put(12f, 152.4f);
      graphMail.put(13f, 159.5f);
      graphMail.put(14f, 165.1f);
      graphMail.put(15f, 168.4f);
      graphMail.put(16f, 169.8f);
      graphMail.put(17f, 170.7f);
    
      graphFemail.put(10f, 140.1f);
      graphFemail.put(11f, 146.7f);
      graphFemail.put(12f, 151.9f);
      graphFemail.put(13f, 155f);
      graphFemail.put(14f, 156.5f);
      graphFemail.put(15f, 157.2f);
      graphFemail.put(16f, 157.6f);
      graphFemail.put(17f, 158f);
      }
    
  • 描画更新

      drawViewDemo.invalidate();
    

#ソースコード いいねも忘れずに

0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?