ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Android 优秀图标库MPAndroidChart之柱状图(适应百分之八十项目需求)

2021-12-26 12:31:12  阅读:231  来源: 互联网

标签:getFormattedValue return 图标库 float MPAndroidChart value 柱状图 param import


  • DO NOT USE, only for backwards compatibility and will be removed in future versions.

  • @param value the value to be formatted

  • @param entry the entry the value belongs to - in e.g. BarChart, this is of class BarEntry

  • @param dataSetIndex the index of the DataSet the entry in focus belongs to

  • @param viewPortHandler provides information about the current chart state (scale, translation, …)

  • @return formatted string label

*/

@Override

@Deprecated

public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {

return getFormattedValue(value);

}

/**

  • Called when drawing any label, used to change numbers into formatted strings.

  • @param value float to be formatted

  • @return formatted string label

*/

public String getFormattedValue(float value) {

return String.valueOf(value);

}

/**

  • Used to draw axis labels, calls {@link #getFormattedValue(float)} by default.

  • @param value float to be formatted

  • @param axis axis being labeled

  • @return formatted string label

*/

public String getAxisLabel(float value, AxisBase axis) {

return getFormattedValue(value);

}

/**

  • Used to draw bar labels, calls {@link #getFormattedValue(float)} by default.

  • @param barEntry bar being labeled

  • @return formatted string label

*/

public String getBarLabel(BarEntry barEntry) {

return getFormattedValue(barEntry.getY());

}

/**

  • Used to draw stacked bar labels, calls {@link #getFormattedValue(float)} by default.

  • @param value current value to be formatted

  • @param stackedEntry stacked entry being labeled, contains all Y values

  • @return formatted string label

*/

public String getBarStackedLabel(float value, BarEntry stackedEntry) {

return getFormattedValue(value);

}

/**

  • Used to draw line and scatter labels, calls {@link #getFormattedValue(float)} by default.

  • @param entry point being labeled, contains X value

  • @return formatted string label

*/

public String getPointLabel(Entry entry) {

return getFormattedValue(entry.getY());

}

/**

  • Used to draw pie value labels, calls {@link #getFormattedValue(float)} by default.

  • @param value float to be formatted, may have been converted to percentage

  • @param pieEntry slice being labeled, contains original, non-percentage Y value

  • @return formatted string label

*/

public String getPieLabel(float value, PieEntry pieEntry) {

return getFormattedValue(value);

}

/**

  • Used to draw radar value labels, calls {@link #getFormattedValue(float)} by default.

  • @param radarEntry entry being labeled

  • @return formatted string label

*/

public String getRadarLabel(RadarEntry radarEntry) {

return getFormattedValue(radarEntry.getY());

}

/**

  • Used to draw bubble size labels, calls {@link #getFormattedValue(float)} by default.

  • @param bubbleEntry bubble being labeled, also contains X and Y values

  • @return formatted string label

*/

public String getBubbleLabel(BubbleEntry bubbleEntry) {

return getFormattedValue(bubbleEntry.getSize());

}

/**

  • Used to draw high labels, calls {@link #getFormattedValue(float)} by default.

  • @param candleEntry candlestick being labeled

  • @return formatted string label

*/

public String getCandleLabel(CandleEntry candleEntry) {

return getFormattedValue(candleEntry.getHigh());

}

}

复制代码

第四步:MyValueFormatter

public class MyValueFormatter extends ValueFormatter{

private final DecimalFormat mFormat;

private String suffix;

public MyValueFormatter(String suffix) {

mFormat = new DecimalFormat(“0000”);

this.suffix = suffix;

}

@Override

public String getFormattedValue(float value) {

return mFormat.format(value) + suffix;

}

@Override

public String getAxisLabel(float value, AxisBase axis) {

if (axis instanceof XAxis) {

return mFormat.format(value);

} else if (value > 0) {

return mFormat.format(value) + suffix;

} else {

return mFormat.format(value);

}

}

}

复制代码

第五步:MainAcyivity

package detongs.hbqianze.him.linechart;

import android.os.Bundle;

import android.util.Log;

import android.view.WindowManager;

import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.github.mikephil.charting.charts.BarChart;

import com.github.mikephil.charting.components.XAxis;

import com.github.mikephil.charting.components.YAxis;

import com.github.mikephil.charting.data.BarData;

import com.github.mikephil.charting.data.BarDataSet;

import com.github.mikephil.charti

《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》

【docs.qq.com/doc/DSkNLaERkbnFoS0ZF】 完整内容开源分享

ng.data.BarEntry;

import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;

import com.github.mikephil.charting.interfaces.datasets.IDataSet;

import com.github.mikephil.charting.utils.ColorTemplate;

import java.util.ArrayList;

import detongs.hbqianze.him.linechart.chart.MyValueFormatter;

import detongs.hbqianze.him.linechart.chart.ValueFormatter;

public class MainActivity extends AppCompatActivity {

private BarChart chart;

private TextView te_cache;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,

WindowManager.LayoutParams.FLAG_FULLSCREEN);

setContentView(R.layout.activity_main);

chart = findViewById(R.id.chart1);

te_cache = findViewById(R.id.te_cache);

chart.getDescription().setEnabled(false);

//设置最大值条目,超出之后不会有值

chart.setMaxVisibleValueCount(60);

//分别在x轴和y轴上进行缩放

chart.setPinchZoom(true);

//设置剩余统计图的阴影

chart.setDrawBarShadow(false);

//设置网格布局

chart.setDrawGridBackground(true);

//通过自定义一个x轴标签来实现2,015 有分割符符bug

ValueFormatter custom = new MyValueFormatter(" ");

//获取x轴线

XAxis xAxis = chart.getXAxis();

//设置x轴的显示位置

xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);

//设置网格布局

xAxis.setDrawGridLines(true);

//图表将避免第一个和最后一个标签条目被减掉在图表或屏幕的边缘

xAxis.setAvoidFirstLastClipping(false);

//绘制标签 指x轴上的对应数值 默认true

xAxis.setDrawLabels(true);

xAxis.setValueFormatter(custom);

//缩放后x 轴数据重叠问题

xAxis.setGranularityEnabled(true);

//获取右边y标签

标签:getFormattedValue,return,图标库,float,MPAndroidChart,value,柱状图,param,import
来源: https://blog.csdn.net/m0_64604842/article/details/122153862

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有