最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android LineChart繪制多條曲線的方法

 更新時(shí)間:2019年05月24日 11:48:43   作者:Vivinia_Vivinia  
這篇文章主要為大家詳細(xì)介紹了Android LineChart繪制多條曲線的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Android LineChart繪制多條曲線的具體代碼,供大家參考,具體內(nèi)容如下

目標(biāo)效果:

1.新建custom_marker_view.xml頁面作為點(diǎn)擊彈出框的頁面:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="wrap_content"
 android:layout_height="40dp"
 android:background="@drawable/marker2" >
 
 <TextView
 android:id="@+id/tvContent"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_centerHorizontal="true"
 android:layout_marginTop="7dp"
 android:layout_marginLeft="5dp"
 android:layout_marginRight="5dp"
 android:text=""
 android:textSize="12dp"
 android:textColor="@android:color/white"
 android:ellipsize="end"
 android:singleLine="true"
 android:textAppearance="?android:attr/textAppearanceSmall" />
 
</RelativeLayout>

2.activity_main.xml頁面:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:paddingBottom="10dp"
 android:paddingLeft="10dp"
 android:paddingRight="10dp"
 android:paddingTop="10dp"
 tools:context=".MainActivity" >
 
 <com.github.mikephil.charting.charts.LineChart
 android:id="@+id/chartTall"
 android:layout_width="match_parent"
 android:layout_height="400dp"
 android:layout_marginTop="20dp" />
 
 
</RelativeLayout>

3.新建MyMarkerView.java重寫MarkView控件:

package com.example.weixu.drawline;
 
import android.content.Context;
import android.widget.TextView;
 
import com.github.mikephil.charting.data.CandleEntry;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.utils.MarkerView;
import com.github.mikephil.charting.utils.Utils;
 
public class MyMarkerView extends MarkerView {
 
 private TextView tvContent;
 
 public MyMarkerView(Context context, int layoutResource) {
 super(context, layoutResource);
 
 tvContent = (TextView) findViewById(R.id.tvContent);
 }
 
 @Override
 public void refreshContent(Entry e, int dataSetIndex) {
 
 if (e instanceof CandleEntry) {
 CandleEntry ce = (CandleEntry) e;
 tvContent.setText("" + Utils.formatNumber(ce.getHigh(), 0, true));
 } else {
 tvContent.setText("" +e.getVal());
 }
 }
}

4.MainActivity.java頁面:

package com.example.weixu.drawline;
 
import java.util.ArrayList;
 
import android.app.Activity;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.WindowManager;
 
import com.github.mikephil.charting.charts.BarLineChartBase;
import com.github.mikephil.charting.charts.BarLineChartBase.BorderPosition;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.utils.Legend;
import com.github.mikephil.charting.utils.Legend.LegendForm;
import com.github.mikephil.charting.utils.XLabels;
import com.github.mikephil.charting.utils.XLabels.XLabelPosition;
import com.github.mikephil.charting.utils.YLabels;
 
public class MainActivity extends Activity {
 
 private LineChart chartTall;
 
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
 WindowManager.LayoutParams.FLAG_FULLSCREEN);
 setContentView(R.layout.activity_main);
 
 chartTall = (LineChart) findViewById(R.id.chartTall);
 
 setType();
 
 // 刷新圖表
 chartTall.invalidate();
 }
 
 private void setType() {
 // 設(shè)置在Y軸上是否是從0開始顯示
 chartTall.setStartAtZero(true);
 //是否在Y軸顯示數(shù)據(jù),就是曲線上的數(shù)據(jù)
 chartTall.setDrawYValues(true);
 //設(shè)置網(wǎng)格
 chartTall.setDrawBorder(true);
 chartTall.setBorderPositions(new BarLineChartBase.BorderPosition[] {
 BorderPosition.BOTTOM});
 //在chart上的右下角加描述
 chartTall.setDescription("身高曲線圖");
 //設(shè)置Y軸上的單位
 chartTall.setUnit("cm");
 //設(shè)置透明度
 chartTall.setAlpha(0.8f);
 //設(shè)置網(wǎng)格底下的那條線的顏色
 chartTall.setBorderColor(Color.rgb(213, 216, 214));
 //設(shè)置Y軸前后倒置
 chartTall.setInvertYAxisEnabled(false);
 //設(shè)置高亮顯示
 chartTall.setHighlightEnabled(true);
 //設(shè)置是否可以觸摸,如為false,則不能拖動,縮放等
 chartTall.setTouchEnabled(true);
 //設(shè)置是否可以拖拽,縮放
 chartTall.setDragEnabled(true);
 chartTall.setScaleEnabled(true);
 //設(shè)置是否能擴(kuò)大擴(kuò)小
 chartTall.setPinchZoom(true);
 //設(shè)置點(diǎn)擊chart圖對應(yīng)的數(shù)據(jù)彈出標(biāo)注
 MyMarkerView mv = new MyMarkerView(this, R.layout.custom_marker_view);
 mv.setOffsets(-mv.getMeasuredWidth() / 2, -mv.getMeasuredHeight());
 chartTall.setMarkerView(mv);
 chartTall.setHighlightIndicatorEnabled(false);
 //設(shè)置字體格式,如正楷
 Typeface tf = Typeface.createFromAsset(getAssets(),
 "OpenSans-Regular.ttf");
 chartTall.setValueTypeface(tf);
 
 XLabels xl = chartTall.getXLabels();
 xl.setPosition(XLabelPosition.BOTTOM); // 設(shè)置X軸的數(shù)據(jù)在底部顯示
 xl.setTypeface(tf); // 設(shè)置字體
 xl.setTextSize(10f); // 設(shè)置字體大小
 xl.setSpaceBetweenLabels(3); // 設(shè)置數(shù)據(jù)之間的間距
 
 YLabels yl = chartTall.getYLabels();
 yl.setTypeface(tf); // 設(shè)置字體
 yl.setTextSize(10f); // s設(shè)置字體大小
 yl.setLabelCount(5); // 設(shè)置Y軸最多顯示的數(shù)據(jù)個(gè)數(shù)
 // 加載數(shù)據(jù)
 setData();
 //從X軸進(jìn)入的動畫
 chartTall.animateX(4000);
 chartTall.animateY(3000); //從Y軸進(jìn)入的動畫
 chartTall.animateXY(3000, 3000); //從XY軸一起進(jìn)入的動畫
 
 //設(shè)置最小的縮放
 chartTall.setScaleMinima(0.5f, 1f);
 
 }
 
 private void setData() {
 String[] babAge = {"0","1","2","3","4","5","6"}; //連線的x軸數(shù)據(jù)
 String[] babyTall = {"50","60","90","110","130","135","140"};
 String[] usuaTall = {"55","65","95","115","125","135","145"};//連線的y軸數(shù)據(jù)
 
 LineData data=new LineData(babAge,setLine(babAge,babyTall,1,"寶寶身高")); //創(chuàng)建LineData實(shí)體類并添加第一條曲線
 data.addDataSet(setLine(babAge,usuaTall,2,"正常身高")); //添加第二條曲線
 chartTall.setData(data);
 }
 
 //畫線
 private LineDataSet setLine(String[] babAge, String[] Tall,int flag,String name) {
 ArrayList<String> xValsAge = new ArrayList<String>();
 for (int i = 0; i < babAge.length; i++) {
 xValsAge.add(babAge[i]);
 }
 ArrayList<Entry> yValsBabyTall = new ArrayList<Entry>();
 for (int i = 0; i < Tall.length; i++) {
 yValsBabyTall.add(new Entry(Float.parseFloat(Tall[i]), i));
 }
 //設(shè)置baby的成長曲線
 LineDataSet setData = new LineDataSet(yValsBabyTall,name);
 setData.setDrawCubic(true); //設(shè)置曲線為圓滑的線
 setData.setCubicIntensity(0.2f);
 setData.setDrawFilled(false); //設(shè)置包括的范圍區(qū)域填充顏色
 setData.setDrawCircles(true); //設(shè)置有圓點(diǎn)
 setData.setLineWidth(2f); //設(shè)置線的寬度
 setData.setCircleSize(5f); //設(shè)置小圓的大小
 setData.setHighLightColor(Color.rgb(244, 117, 117));
 //設(shè)置曲線顏色
 if(flag==1)
 setData.setColor(Color.rgb(104, 241, 175)); //寶寶身高曲線顏色
 else if(flag==2)
 setData.setColor(Color.rgb(255, 0, 0)); //普通身高曲線顏色
 return setData; //返回曲線
 }
}

源碼:點(diǎn)擊打開鏈接

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 淺談Android面向切面編程(AOP)

    淺談Android面向切面編程(AOP)

    這篇文章主要介紹了淺談Android面向切面編程(AOP),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-11-11
  • Android 大文件切割與合并的實(shí)現(xiàn)代碼

    Android 大文件切割與合并的實(shí)現(xiàn)代碼

    這篇文章主要介紹了Android 大文件切割與合并,實(shí)現(xiàn)了很多發(fā)文件和視頻的切割,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-11-11
  • 完美解決Android Studio集成crashlytics后無法編譯的問題

    完美解決Android Studio集成crashlytics后無法編譯的問題

    下面小編就為大家?guī)硪黄昝澜鉀QAndroid Studio集成crashlytics后無法編譯的問題。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-05-05
  • 詳細(xì)分析Android-Zygote的啟動過程

    詳細(xì)分析Android-Zygote的啟動過程

    在Android系統(tǒng)中,所有的應(yīng)用程序進(jìn)程以及系統(tǒng)服務(wù)進(jìn)程SystemServer都是由Zygote進(jìn)程孕育(fork)出來的,這也許就是為什么要把它稱為Zygote(受精卵)的原因吧。由于Zygote進(jìn)程在Android系統(tǒng)中有著如此重要的地位,本文將詳細(xì)分析它的啟動過程
    2021-06-06
  • android自定義imageview實(shí)現(xiàn)圓角圖片

    android自定義imageview實(shí)現(xiàn)圓角圖片

    這篇文章主要為大家詳細(xì)介紹了android自定義imageview實(shí)現(xiàn)圓角圖片,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-02-02
  • android開發(fā)PathEffect問題處理

    android開發(fā)PathEffect問題處理

    本文主要整理了關(guān)于android中PathEffect的問題匯總以及處理方式,以及給大家做了關(guān)于PathEffect類的詳細(xì)解釋。
    2017-11-11
  • Android package屬性、package name和Application ID三者的聯(lián)系及區(qū)別

    Android package屬性、package name和Application ID三者的聯(lián)系及區(qū)別

    這篇文章主要介紹了Android package屬性、package name和Application ID三者的聯(lián)系及區(qū)別的相關(guān)資料,需要的朋友可以參考下
    2016-12-12
  • android端使用openCV實(shí)現(xiàn)車牌檢測

    android端使用openCV實(shí)現(xiàn)車牌檢測

    這篇文章主要為大家詳細(xì)介紹了android端使用openCV實(shí)現(xiàn)車牌檢測,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-12-12
  • Android保存App異常信息到本地

    Android保存App異常信息到本地

    這篇文章主要為大家詳細(xì)介紹了Android保存App異常信息到本地,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-08-08
  • Android實(shí)現(xiàn)圖像灰度化、線性灰度變化和二值化處理方法

    Android實(shí)現(xiàn)圖像灰度化、線性灰度變化和二值化處理方法

    這篇文章主要介紹了Android實(shí)現(xiàn)圖像灰度化、線性灰度變化和二值化處理方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-10-10

最新評論

仁化县| 三明市| 库车县| 军事| 台湾省| 清徐县| 汤原县| 中江县| 丹巴县| 镇平县| 宽甸| 瓮安县| 电白县| 泾川县| 景德镇市| 平遥县| 龙州县| 澄迈县| 莫力| 丁青县| 东方市| 思南县| 建宁县| 嘉黎县| 大同县| 班玛县| 葵青区| 和顺县| 德昌县| 荃湾区| 永平县| 仪征市| 文登市| 休宁县| 田东县| 加查县| 彩票| 赣榆县| 石泉县| 宜黄县| 兴海县|