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

Android圖表庫(kù)HelloCharts的實(shí)例詳解

 更新時(shí)間:2022年01月06日 15:27:56   作者:曲幽  
這篇文章主要介紹了Android中的圖標(biāo)庫(kù)HelloCharts的一些簡(jiǎn)單使用實(shí)例,文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí)有一定的參考價(jià)值,需要的可以參考一下

概述

效果圖,數(shù)據(jù)可平移查看歷史

build.gradle

implementation 'com.github.lecho:hellocharts-library:1.5.8@aar'

layout

直接在布局中加入相應(yīng)的圖表控件

<lecho.lib.hellocharts.view.LineChartView
    android:id="@+id/ChartLine"
    android:layout_width="0dp"
    android:layout_height="300dp"
    android:padding="6dp"/>

常用圖表類型

LineChartView

PointValue

圖表上每一點(diǎn)的數(shù)據(jù) PointValue(float x, float y)

第一個(gè)參數(shù)表示點(diǎn)的位置,第二個(gè)參數(shù)表示點(diǎn)上的數(shù)據(jù)。如果是多條折線,則需要為每一條拆線相同位置定義不同的PointValue

PointValue point1 = new PointValue(0, 1000);
PointValue point2 = new PointValue(1, 1500);
PointValue point1 = new PointValue(0, 1200);
PointValue point2 = new PointValue(1, 1600);

setLabel() 可以為數(shù)據(jù)點(diǎn)定義顯示文本

point1.setLabel("202101");

實(shí)例

List<PointValue> valuesR = new ArrayList<>();
List<PointValue> valuesS = new ArrayList<>();
for (int i = 0; i < dataEntities.size(); i++) {
    DataEntity dataEntity = dataEntities.get(i);
    if (dataEntity.getDataR() < 3000 || dataEntity.getDataS() < 3000)
        continue;
    valuesR.add(new PointValue(i, dataEntity.getDataR()).setLabel(String.valueOf(dataEntity.getDataR())));
    valuesS .add(new PointValue(i, dataEntity.getDataS()).setLabel(String.valueOf(dataEntity.getDataS())));
}

如果數(shù)據(jù)太小,則跳過(guò)。數(shù)據(jù)不加載入數(shù)據(jù)點(diǎn)集合,但 i 索引會(huì)增加,折線上會(huì)出現(xiàn)大的間隔。如果不想出現(xiàn)此情況,可更換 for 循環(huán)為 foreach 循環(huán),然后手動(dòng)控制 i 的增長(zhǎng)。

Line

定義線條上的數(shù)據(jù)和顏色等

構(gòu)造函數(shù)傳入包含PointValue的列表,有幾條折線就創(chuàng)建幾條并綁定不同的點(diǎn)數(shù)據(jù)列表

List<Line> lines = new ArrayList<>();
lines.add(new Line(valuesR).setColor(Color.RED).setCubic(false).setHasLabelsOnlyForSelected(true));
lines.add(new Line(valuesS).setColor(Color.BLUE).setCubic(false).setHasLabelsOnlyForSelected(true));

常用屬性方法

  • setColor() # 設(shè)置折線顏色
  • setCubic(true) # 折線是否平滑,即是曲線還是折線
  • setShape() # 折線上數(shù)據(jù)點(diǎn)的形狀,有三種 :ValueShape.SQUARE(方) ValueShape.CIRCLE(圓) ValueShape.DIAMOND(菱)
  • setFilled(false) # 是否填充曲線的面積
  • setHasLabels(true) # 曲線的數(shù)據(jù)坐標(biāo)是否加上備注
  • setHasLabelsOnlyForSelected(true) # 同上,但是只有點(diǎn)擊數(shù)據(jù)坐標(biāo)提示數(shù)據(jù),但設(shè)置了這個(gè)屬性,上面的屬性即失效
  • setHasLines(true) # 是否顯示線,為false則只顯示點(diǎn)
  • setHasPoints(true) # 是否顯示圓點(diǎn),如果為false則每個(gè)數(shù)據(jù)點(diǎn)都是個(gè)大的圓點(diǎn)

Axis

X軸

List<AxisValue> xValue = new ArrayList<>();
for(int i = 0; i < dataEntities.size(); i++){
    DataEntity dataEntity = dataEntities.get(i);
    xValue.add(new AxisValue(i).setLabel(dataEntity .getDate()));
}
Axis axisX = new Axis();
axisX.setHasTiltedLabels(true);
axisX.setTextColor(Color.GRAY);
axisX.setValues(xValue);

Y軸

List<AxisValue> yValue = new ArrayList<>();
for(int i = 0; i < 8000; i = i + 1000){
    yValue.add(new AxisValue(i).setLabel(String.valueOf(i)));
}
Axis axisY  = new Axis();
axisY.setTextColor(Color.GRAY);
axisY.setValues(yValue);
axisY.setHasLines(true);
LineChartData data = new LineChartData();
data.setLines(lines);
data.setAxisXBottom(axisX);
data.setAxisYLeft(axisY);

AxisValue

創(chuàng)建實(shí)例

AxisValue v = new AxisValue(i).setLabel(String.valueOf(i));

常用屬性方法

  • setHasTiltedLabels(true) # 坐標(biāo)軸字體是否顯示斜體
  • setValues() # 填充數(shù)據(jù)列表
  • setHasLines(true) # 是否顯示參考線

LineChartData

將以上包含了點(diǎn)數(shù)據(jù)列表的折線添加到 LineChartData 中并綁定給圖表控件

Chart

//設(shè)置是否允許平移以及平移的方向
bindingView.chartLine.setContainerScrollEnabled(true, ContainerScrollType.HORIZONTAL);
//填充數(shù)據(jù)
bindingView.chartLine.setLineChartData(data);

實(shí)現(xiàn)平移必須設(shè)置視圖大小

//實(shí)例化一個(gè)新的ViewPort 構(gòu)造函數(shù)中傳入填充數(shù)據(jù)后的默認(rèn)最大視圖
Viewport viewport = new Viewport(bindingView.chartLine.getMaximumViewport()); 
//設(shè)置y軸的顯示
viewport.top = MyApplication.getSharedPreferences().getInt("max", 8000);
viewport.bottom = MyApplication.getSharedPreferences().getInt("min", 3000);
//一定要先設(shè)置最大視圖范圍
bindingView.chartLine.setMaximumViewport(viewport); //圖表最大視圖
//設(shè)置x軸的顯示
viewport.right = MyApplication.getSharedPreferences().getInt("chart_right", 7);
viewport.left = 0;
//最后設(shè)置當(dāng)前顯示的視圖范圍
bindingView.chartLine.setCurrentViewport(viewport); //圖表當(dāng)前視圖

完整代碼

private void initChart(List<DataEntity> dataEntities) {
    List<PointValue> valuesR = new ArrayList<>();
    List<PointValue> valuesS = new ArrayList<>();
    List<AxisValue> xValue = new ArrayList<>();
    List<AxisValue> yValue = new ArrayList<>();
    for (int i = 0; i < dataEntities.size(); i++) {
        DataEntity dataEntity = dataEntities.get(i);
        if (dataEntity.getDataR() < MyApplication.getSharedPreferences().getInt("min", 3000) || dataEntity.getDataS() < MyApplication.getSharedPreferences().getInt("min", 3000))
            continue;
        valuesR.add(new PointValue(i, dataEntity .getDataR()).setLabel(String.valueOf(dataEntity .getDataR())));
        valuesS.add(new PointValue(i, dataEntity .getDataS()).setLabel(String.valueOf(dataEntity .getDataS())));
        xValue.add(new AxisValue(i).setLabel(dataEntity .getDate()));
    }
    for (int i = 0; i < MyApplication.getSharedPreferences().getInt("salary_max", 8000); i = i + 500) {
        yValue.add(new AxisValue(i).setLabel(String.valueOf(i)));
    }
    List<Line> lines = new ArrayList<>();
    lines.add(new Line(valuesR).setColor(Color.RED).setCubic(false).setHasLabelsOnlyForSelected(true));
    lines.add(new Line(valuesS).setColor(Color.BLUE).setCubic(false).setHasLabelsOnlyForSelected(true));
    Axis axisX = new Axis();
    axisX.setHasTiltedLabels(true);
    axisX.setTextColor(Color.GRAY);
    axisX.setValues(xValue);
    Axis axisY = new Axis();
    axisY.setTextColor(Color.GRAY);
    axisY.setValues(yValue);
    axisY.setHasLines(true);


    LineChartData data = new LineChartData();
    data.setLines(lines);
    data.setAxisXBottom(axisX);
    data.setAxisYLeft(axisY);
    bindingView.chartLine.setContainerScrollEnabled(true, ContainerScrollType.HORIZONTAL);
    bindingView.chartLine.setLineChartData(data);
    //設(shè)置圖表顯示的大小
    Viewport viewport = new Viewport(bindingView.chartLine.getMaximumViewport()); //填充數(shù)據(jù)后的默認(rèn)最大視圖
    viewport.top = MyApplication.getSharedPreferences().getInt("max", 8000);
    viewport.bottom = MyApplication.getSharedPreferences().getInt("min", 3000);
    bindingView.chartLine.setMaximumViewport(viewport); //圖表最大視圖
    viewport.right = MyApplication.getSharedPreferences().getInt("chart_right", 7);
    viewport.left = 0;
    bindingView.chartLine.setCurrentViewport(viewport); //圖表當(dāng)前視圖
}

以上就是Android圖表庫(kù)HelloCharts的實(shí)例詳解的詳細(xì)內(nèi)容,更多關(guān)于Android圖表庫(kù)HelloCharts的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • android調(diào)用C語(yǔ)言實(shí)現(xiàn)內(nèi)存的讀取與修改的方法示例

    android調(diào)用C語(yǔ)言實(shí)現(xiàn)內(nèi)存的讀取與修改的方法示例

    這篇文章主要介紹了android調(diào)用C語(yǔ)言實(shí)現(xiàn)內(nèi)存的讀取與修改的方法示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-03-03
  • Listview加載的性能優(yōu)化是如何實(shí)現(xiàn)的

    Listview加載的性能優(yōu)化是如何實(shí)現(xiàn)的

    在android開(kāi)發(fā)中Listview是一個(gè)很重要的組件,它以列表的形式根據(jù)數(shù)據(jù)的長(zhǎng)自適應(yīng)展示具體內(nèi)容,用戶可以自由的定義listview每一列的布局,接下來(lái)通過(guò)本文給大家介紹Listview加載的性能優(yōu)化是如何實(shí)現(xiàn)的,對(duì)listview性能優(yōu)化相關(guān)知識(shí)感興趣的朋友一起學(xué)習(xí)吧
    2016-01-01
  • Android中庫(kù)項(xiàng)目的使用方法圖文介紹

    Android中庫(kù)項(xiàng)目的使用方法圖文介紹

    類似開(kāi)發(fā)其他Java應(yīng)用一樣,我們可以將可復(fù)用的代碼,打成一個(gè)jar包,供所有需要的項(xiàng)目使用。這樣,可以解決很大一部分代碼復(fù)用的問(wèn)題,本文將詳細(xì)介紹,需要了解的朋友可以參考下
    2012-12-12
  • android studio集成ijkplayer的示例代碼

    android studio集成ijkplayer的示例代碼

    本篇文章主要介紹了android studio集成ijkplayer的示例代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-09-09
  • Android實(shí)現(xiàn)自定義驗(yàn)證碼輸入框效果(實(shí)例代碼)

    Android實(shí)現(xiàn)自定義驗(yàn)證碼輸入框效果(實(shí)例代碼)

    這篇文章主要介紹了Android實(shí)現(xiàn)自定義驗(yàn)證碼輸入框效果,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-01-01
  • Android實(shí)現(xiàn)簡(jiǎn)易秒表功能

    Android實(shí)現(xiàn)簡(jiǎn)易秒表功能

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)簡(jiǎn)易秒表功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-09-09
  • Android混合開(kāi)發(fā)教程之WebView的使用方法總結(jié)

    Android混合開(kāi)發(fā)教程之WebView的使用方法總結(jié)

    WebView是一個(gè)基于webkit引擎、展現(xiàn)web頁(yè)面的控件,下面這篇文章主要給大家介紹了關(guān)于Android混合開(kāi)發(fā)教程之WebView的使用方法,文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面來(lái)一起看看吧
    2018-05-05
  • android 照相功能的簡(jiǎn)單實(shí)例

    android 照相功能的簡(jiǎn)單實(shí)例

    android 照相功能的簡(jiǎn)單實(shí)例,需要的朋友可以參考一下
    2013-06-06
  • Android RecycleView 實(shí)現(xiàn)左滑上下分層示例代碼(自定義功能)

    Android RecycleView 實(shí)現(xiàn)左滑上下分層示例代碼(自定義功能)

    這篇文章主要介紹了Android RecycleView 實(shí)現(xiàn)左滑上下分層示例代碼(自定義功能),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。
    2017-03-03
  • Android編程實(shí)現(xiàn)抽屜效果的方法詳解

    Android編程實(shí)現(xiàn)抽屜效果的方法詳解

    這篇文章主要介紹了Android編程實(shí)現(xiàn)抽屜效果的方法,結(jié)合具體實(shí)例形式分析了Android實(shí)現(xiàn)抽屜效果的具體步驟與相關(guān)操作技巧,需要的朋友可以參考下
    2017-05-05

最新評(píng)論

江源县| 安庆市| 正阳县| 广丰县| 尼勒克县| 新安县| 郴州市| 灵川县| 黄骅市| 望城县| 景德镇市| 张家口市| 宝清县| 浮山县| 长武县| 拉孜县| 洞口县| 石台县| 定州市| 兴业县| 泸州市| 城固县| 浮梁县| 抚松县| 鸡泽县| 武穴市| 乌苏市| 晋宁县| 青冈县| 天全县| 翁源县| 太白县| 临漳县| 瓦房店市| 黄平县| 屏山县| 琼中| 通州市| 滁州市| 定边县| 宜良县|