Android로 차트 만들기

2685 단어 Android

입력



결실



인출 방법


다음 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();
    
  • 감정이 서리다

    좋은 웹페이지 즐겨찾기