MPAndroidChart 柱状图最左边是赤右边报的半边只显示半边是怎么回事

请问MPAndroidCharts 怎么设置y轴的网格线不显示?
[问题点数:40分]
请问MPAndroidCharts 怎么设置y轴的网格线不显示?
[问题点数:40分]
不显示删除回复
显示所有回复
显示星级回复
显示得分回复
只显示楼主
匿名用户不能发表回复!|
每天回帖即可获得10分可用分!小技巧:
你还可以输入10000个字符
(Ctrl+Enter)
请遵守CSDN,不得违反国家法律法规。
转载文章请注明出自“CSDN(www.csdn.net)”。如是商业用途请联系原作者。MPAndroidChart - 推酷
MPAndroidChart
最近一个项目需要用到表格进行统计显示,本来用的是的achartengine,后来发现一个更加强大的开源框架MPAndroidChart。
下面简单介绍下MPAndroidChart,MPAndroidChart的效果还是蛮好的,提供各种动画,这个也是我使用MPAndroidChart,而且放弃achartengine的原因。
Github地址连接,后面是youtube上面演示MPAndroidChart的视频,MPAndroidChart由于提供了动画效果,为了兼容低版本的Android系统,MPAndroidChart需要添加nineoldandroids-2.4.0-2.jar作为依赖库,所以如果项目中使用这个表格库,需要同时导入这个两个jar,当然如果使用libproject的方式,就不用了。
支持x,y轴缩放
支持手指滑动
支持高亮显示
支持保存图表到文件中
支持从文件(txt)中读取数据
预先定义颜色模板
自动生成标注
支持自定义x,y轴的显示标签
支持x,y轴动画
支持x,y轴设置最大值和附加信息
支持自定义字体,颜色,背景,手势,虚线等
显示的图表类型:
LineChart (with legend, simple design) (线性图)
LineChart (with legend, simple design) (线性图)
LineChart (cubic lines) (线性图)
LineChart (single DataSet) (线性图)
BarChart2D (with legend, simple design) (柱状图)
BarChart2D (grouped DataSets) (柱状图)
BarChart2D
PieChart (with selection, ...) (饼状图)
ScatterChart &(with squares, triangles, circles, ... and more)(散列图)
CandleStickChart &(for financial data)
RadarChart &(spider web chart)(螂蛛网图)
1、直接使用jar方式,需要导入mpchartlib.jar,nineoldandroidsjar。
2、使用libproject的方式,作为项目依赖。
如果使用 LineChart, BarChart, ScatterChart, CandleStickChart or PieChart& , 可以直接在xml中定义。
&com.github.mikephil.charting.charts.LineChart
android:id=&@+id/chart&
android:layout_width=&match_parent&
android:layout_height=&match_parent& /&
LineChart chart = (LineChart) findViewById(R.id.chart);
或则直接在代码中声明和实例化。
LineChart chart = new LineChart(Context);
主要的Api方法:
setDescription(String desc) : 设置表格的描述
setDescriptionTypeface(Typeface t) :自定义表格中显示的字体
setDrawYValues(boolean enabled) : 设置是否显示y轴的值的数据
setValuePaintColor(int color)
:设置表格中y轴的值的颜色,但是必须设置
setDrawYValues(true)
setValueTypeface(Typeface t):设置字体
setValueFormatter(DecimalFormat format) : 设置显示的格式
setPaint(Paint p, int which) : 自定义笔刷
public ChartData getDataCurrent() :返回ChartData对象当前显示的图表。它包含了所有信息的显示值最小和最大值等
public float getYChartMin() : 返回当前最小值
public float getYChartMax() : 返回当前最大值
public float getAverage() : 返回所有值的平均值。
public float getAverage(int type) : 返回平均值
public PointF getCenter() : 返回中间点
public Paint getPaint(int which) : 得到笔刷
setTouchEnabled(boolean enabled) : 设置是否可以触摸,如为false,则不能拖动,缩放等
setDragScaleEnabled(boolean enabled) : 设置是否可以拖拽,缩放
setOnChartValueSelectedListener(OnChartValueSelectedListener l) : 设置表格上的点,被点击的时候,的回调函数
setHighlightEnabled(boolean enabled) : 设置点击value的时候,是否高亮显示
public void highlightValues(Highlight[] highs) : 设置高亮显示
saveToGallery(String title) : 保存图表到图库中
saveToPath(String title, String pathOnSD) : 保存.
setScaleMinima(float x, float y) : 设置最小的缩放
centerViewPort(int xIndex, float val) : 设置视口
fitScreen() : 适应屏幕
所有的图表类型都支持下面三种动画,分别是x方向,y方向,xy方向。
animateX(int durationMillis) : x轴方向
animateY(int durationMillis) : y轴方向
animateXY(int xDuration, int yDuration) : xy轴方向
mChart.animateX(3000f); // animate horizontal 3000 milliseconds
mChart.animateY(3000f); // animate vertical 3000 milliseconds
mChart.animateXY(3000f, 3000f); // animate horizontal and vertical 3000 milliseconds
注意:如果调用动画方法后,就没有必要调用 invalidate()方法,来刷新界面了。
添加数据到图表:
下面是MPAndroidChart中的一个demo实例,简单介绍怎么添加数据到图表中,以及动画显示。
package com.xxmassdeveloper.
import android.graphics.C
import android.graphics.T
import android.os.B
import android.view.WindowM
import com.github.mikephil.charting.charts.LineC
import com.github.mikephil.charting.data.E
import com.github.mikephil.charting.data.LineD
import com.github.mikephil.charting.data.LineDataS
import com.github.mikephil.charting.utils.L
import com.github.mikephil.charting.utils.Legend.LegendF
import com.github.mikephil.charting.utils.XL
import com.github.mikephil.charting.utils.YL
import com.xxmassdeveloper.mpchartexample.notimportant.DemoB
import java.util.ArrayL
public class LineChartActivityColored extends DemoBase {
LineChart[] mCharts = new LineChart[4]; // 4条数据
Typeface mTf; // 自定义显示字体
int[] mColors = new int[] { Color.rgb(137, 230, 81), Color.rgb(240, 240, 30),//
Color.rgb(89, 199, 250), Color.rgb(250, 104, 104) }; // 自定义颜色
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_colored_lines);
mCharts[0] = (LineChart) findViewById(R.id.chart1);
mCharts[1] = (LineChart) findViewById(R.id.chart2);
mCharts[2] = (LineChart) findViewById(R.id.chart3);
mCharts[3] = (LineChart) findViewById(R.id.chart4);
// 自定义字体
mTf = Typeface.createFromAsset(getAssets(), &OpenSans-Bold.ttf&);
// 生产数据
LineData data = getData(36, 100);
for (int i = 0; i & mCharts. i++) {
// add some transparency to the color with && 0x90FFFFFF&
setupChart(mCharts[i], data, mColors[i % mColors.length]);
// 设置显示的样式
void setupChart(LineChart chart, LineData data, int color) {
// if enabled, the chart will always start at zero on the y-axis
chart.setStartAtZero(true);
// disable the drawing of values into the chart
chart.setDrawYValues(false);
chart.setDrawBorder(false);
// no description text
chart.setDescription(&&);// 数据描述
// 如果没有数据的时候,会显示这个,类似listview的emtpyview
chart.setNoDataTextDescription(&You need to provide data for the chart.&);
// enable / disable grid lines
chart.setDrawVerticalGrid(false); // 是否显示水平的表格
// mChart.setDrawHorizontalGrid(false);
// enable / disable grid background
chart.setDrawGridBackground(false); // 是否显示表格颜色
chart.setGridColor(Color.WHITE & 0x70FFFFFF); // 表格的的颜色,在这里是是给颜色设置一个透明度
chart.setGridWidth(1.25f);// 表格线的线宽
// enable touch gestures
chart.setTouchEnabled(true); // 设置是否可以触摸
// enable scaling and dragging
chart.setDragEnabled(true);// 是否可以拖拽
chart.setScaleEnabled(true);// 是否可以缩放
// if disabled, scaling can be done on x- and y-axis separately
chart.setPinchZoom(false);//
chart.setBackgroundColor(color);// 设置背景
chart.setValueTypeface(mTf);// 设置字体
// add data
chart.setData(data); // 设置数据
// get the legend (only possible after setting data)
Legend l = chart.getLegend(); // 设置标示,就是那个一组y的value的
// modify the legend ...
// l.setPosition(LegendPosition.LEFT_OF_CHART);
l.setForm(LegendForm.CIRCLE);// 样式
l.setFormSize(6f);// 字体
l.setTextColor(Color.WHITE);// 颜色
l.setTypeface(mTf);// 字体
YLabels y = chart.getYLabels(); // y轴的标示
y.setTextColor(Color.WHITE);
y.setTypeface(mTf);
y.setLabelCount(4); // y轴上的标签的显示的个数
XLabels x = chart.getXLabels(); // x轴显示的标签
x.setTextColor(Color.WHITE);
x.setTypeface(mTf);
// animate calls invalidate()...
chart.animateX(2500); // 立即执行的动画,x轴
// 生成一个数据,
LineData getData(int count, float range) {
ArrayList&String& xVals = new ArrayList&String&();
for (int i = 0; i & i++) {
// x轴显示的数据,这里默认使用数字下标显示
xVals.add(mMonths[i % 12]);
// y轴的数据
ArrayList&Entry& yVals = new ArrayList&Entry&();
for (int i = 0; i & i++) {
float val = (float) (Math.random() * range) + 3;
yVals.add(new Entry(val, i));
// create a dataset and give it a type
// y轴的数据集合
LineDataSet set1 = new LineDataSet(yVals, &DataSet 1&);
// set1.setFillAlpha(110);
// set1.setFillColor(Color.RED);
set1.setLineWidth(1.75f); // 线宽
set1.setCircleSize(3f);// 显示的圆形大小
set1.setColor(Color.WHITE);// 显示颜色
set1.setCircleColor(Color.WHITE);// 圆形的颜色
set1.setHighLightColor(Color.WHITE); // 高亮的线的颜色
ArrayList&LineDataSet& dataSets = new ArrayList&LineDataSet&();
dataSets.add(set1); // add the datasets
// create a data object with the datasets
LineData data = new LineData(xVals, dataSets);
运行效果图如下:
已发表评论数()
请填写推刊名
描述不能大于100个字符!
权限设置: 公开
仅自己可见
正文不准确
标题不准确
排版有问题
主题不准确
没有分页内容
图片无法显示
视频无法显示
与原文不一致FSLineChart 是一个简单的 iOS 线性图表库,很容易调节(大小、颜色、线宽度、标签显示等等),同时还包括非常好的展示动画。
TWRCharts 是一个针对 ChartJS 的 iOS 封装库,可以便捷的结合 Obj-C 原生代码构建出具有动画效果的图表。
使用 ANDLineChartView 可以便捷的在视图类中显示有动画效果的折线图。
EChart是一个拥有高度可扩展性,简单易用的图表,提供了事件处理和动画支持。
TEAChart是一个简单直接的iOS图表库用于 Pomotodo app,提供贡献图、饼图和柱状图。
XYPieChart是一款为iOS开发提供的简单易用的饼状图库,可以呈现动态图表且没有相互影响。所有动效都是DrawRect:方法实现,XYPieChar重写了BTSPieChar,动画都是基于CALayer。插入和删除饼状图块的算法更加简单,对于饼状图块有不同设计,自定义更加方便。
BEMSimpleLineGraph 是一个简单易用的 iOS 图表库,它致力于实现折线图的高度可定制和互动。它采用了与 UITableView 和 UICollectionView 相似的数据源和代理模式,可以轻松地创建出漂亮的折线图。
JBChartView 是一个基于 iOS 的图表库,包含折线图和直方图,使用方便而且可定制性高。
PNChart是一个简单漂亮的动画图表库,Piner 和 CoinsMan 的 iOS 客户端中使用了这个框架。
JTChartView 是一个完全可定制的轻量级图表解决方案,通过绘制曲线并使用渐变色填充曲线下面的空间,然后得到一个漂亮的图表。
ios-charts是一个强大的图表框架,是 MPAndroidChart 在 iOS 上的移植。
按分类快速查找
关于资源导航
伯乐在线资源导航收录优秀的工具资源。内容覆盖开发、设计、产品和管理等IT互联网行业相关的领域。目前已经收录 1355 项工具资源。
关于资源导航
伯乐在线资源导航收录优秀的工具资源。内容覆盖开发、设计、产品和管理等IT互联网行业相关的领域。
新浪微博:
推荐微信号
(加好友请注明来意)
- 好的话题、有启发的回复、值得信赖的圈子
- 分享和发现有价值的内容与观点
- 为IT单身男女服务的征婚传播平台
- 优秀的工具资源导航
- 翻译传播优秀的外文文章
- 国内外的精选博客文章
- UI,网页,交互和用户体验
- 专注iOS技术分享
- 专注Android技术分享
- JavaScript, HTML5, CSS
- 专注Java技术分享
- 专注Python技术分享
& 2016 伯乐在线4693人阅读
最近一个项目需要用到表格进行统计显示,本来用的是的achartengine,后来发现一个更加强大的开源框架MPAndroidChart。
下面简单介绍下MPAndroidChart,MPAndroidChart的效果还是蛮好的,提供各种动画,这个也是我使用MPAndroidChart,而且放弃achartengine的原因。
Github地址连接,后面是youtube上面演示MPAndroidChart的视频,MPAndroidChart由于提供了动画效果,为了兼容低版本的Android系统,MPAndroidChart需要添加nineoldandroids-2.4.0-2.jar作为依赖库,所以如果项目中使用这个表格库,需要同时导入这个两个jar,当然如果使用libproject的方式,就不用了。
支持x,y轴缩放支持拖拽支持手指滑动支持高亮显示支持保存图表到文件中支持从文件(txt)中读取数据预先定义颜色模板自动生成标注支持自定义x,y轴的显示标签支持x,y轴动画支持x,y轴设置最大值和附加信息支持自定义字体,颜色,背景,手势,虚线等
显示的图表类型:
LineChart (with legend, simple design) (线性图) &
LineChart (with legend, simple design) (线性图)
LineChart (cubic lines) (线性图)
LineChart (single DataSet) (线性图)
BarChart2D (with legend, simple design) (柱状图)
BarChart2D (grouped DataSets) (柱状图)
BarChart2D
PieChart (with selection, ...) (饼状图)
ScatterChart &(with squares, triangles, circles, ... and more)(散列图)
CandleStickChart &(for financial data)
RadarChart &(spider web chart)(螂蛛网图)
1、直接使用jar方式,需要导入mpchartlib.jar,nineoldandroidsjar。
2、使用libproject的方式,作为项目依赖。
如果使用 LineChart, BarChart, ScatterChart, CandleStickChart or PieChart, 可以直接在xml中定义。
.github.mikephil.charting.charts.LineChart
android:id=&@+id/chart&
android:layout_width=&match_parent&
android:layout_height=&match_parent& /&
LineChart chart = (LineChart) findViewById(R.id.chart);
或则直接在代码中声明和实例化。
LineChart chart = new LineChart(Context);
主要的Api方法:
setDescription(String desc) : 设置表格的描述 setDescriptionTypeface(Typeface t) :自定义表格中显示的字体setDrawYValues(boolean enabled) : 设置是否显示y轴的值的数据setValuePaintColor(int color) :设置表格中y轴的值的颜色,但是必须设置setDrawYValues(true)
setValueTypeface(Typeface t):设置字体 setValueFormatter(DecimalFormat format) : 设置显示的格式setPaint(Paint p, int which) : 自定义笔刷
public ChartData getDataCurrent() :返回ChartData对象当前显示的图表。它包含了所有信息的显示值最小和最大值等public float getYChartMin() : 返回当前最小值 public float getYChartMax() : 返回当前最大值 public float getAverage() : 返回所有值的平均值。 public float getAverage(int type) : 返回平均值 public PointF getCenter() : 返回中间点 public Paint getPaint(int which) : 得到笔刷
setTouchEnabled(boolean enabled) : 设置是否可以触摸,如为false,则不能拖动,缩放等setDragScaleEnabled(boolean enabled) : 设置是否可以拖拽,缩放setOnChartValueSelectedListener(OnChartValueSelectedListener l) : 设置表格上的点,被点击的时候,的回调函数setHighlightEnabled(boolean enabled) : 设置点击value的时候,是否高亮显示public void highlightValues(Highlight[] highs) : 设置高亮显示
saveToGallery(String title) : 保存图表到图库中 saveToPath(String title, String pathOnSD) : 保存.setScaleMinima(float x, float y) : 设置最小的缩放 centerViewPort(int xIndex, float val) : 设置视口fitScreen() : 适应屏幕
所有的图表类型都支持下面三种动画,分别是x方向,y方向,xy方向。
animateX(int durationMillis) : x轴方向 animateY(int durationMillis) : y轴方向 animateXY(int xDuration, int yDuration) : xy轴方向
mChart.animateX(3000f);
mChart.animateY(3000f);
mChart.animateXY(3000f, 3000f);
注意:如果调用动画方法后,就没有必要调用 invalidate()方法,来刷新界面了。
添加数据到图表:
下面是MPAndroidChart中的一个demo实例,简单介绍怎么添加数据到图表中,以及动画显示。
package com.xxmassdeveloper.
import android.graphics.C
import android.graphics.T
import android.os.B
import android.view.WindowM
import com.github.mikephil.charting.charts.LineC
import com.github.mikephil.charting.data.E
import com.github.mikephil.charting.data.LineD
import com.github.mikephil.charting.data.LineDataS
import com.github.mikephil.charting.utils.L
import com.github.mikephil.charting.utils.Legend.LegendF
import com.github.mikephil.charting.utils.XL
import com.github.mikephil.charting.utils.YL
import com.xxmassdeveloper.mpchartexample.notimportant.DemoB
import java.util.ArrayL
public class LineChartActivityColored extends DemoBase {
LineChart[] mCharts = new LineChart[4];
Typeface mTf;
int[] mColors = new int[] { Color.rgb(137, 230, 81), Color.rgb(240, 240, 30),
Color.rgb(89, 199, 250), Color.rgb(250, 104, 104) };
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_colored_lines);
mCharts[0] = (LineChart) findViewById(R.id.chart1);
mCharts[1] = (LineChart) findViewById(R.id.chart2);
mCharts[2] = (LineChart) findViewById(R.id.chart3);
mCharts[3] = (LineChart) findViewById(R.id.chart4);
mTf = Typeface.createFromAsset(getAssets(), &OpenSans-Bold.ttf&);
LineData data = getData(36, 100);
for (int i = 0; i & mCharts. i++) {
setupChart(mCharts[i], data, mColors[i % mColors.length]);
void setupChart(LineChart chart, LineData data, int color) {
chart.setStartAtZero(true);
chart.setDrawYValues(false);
chart.setDrawBorder(false);
chart.setDescription(&&);
chart.setNoDataTextDescription(&You need to provide data for the chart.&);
chart.setDrawVerticalGrid(false);
chart.setDrawGridBackground(false);
chart.setGridColor(Color.WHITE & 0x70FFFFFF);
chart.setGridWidth(1.25f);
chart.setTouchEnabled(true);
chart.setDragEnabled(true);
chart.setScaleEnabled(true);
chart.setPinchZoom(false);
chart.setBackgroundColor(color);
chart.setValueTypeface(mTf);
chart.setData(data);
Legend l = chart.getLegend();
l.setForm(LegendForm.CIRCLE);
l.setFormSize(6f);
l.setTextColor(Color.WHITE);
l.setTypeface(mTf);
YLabels y = chart.getYLabels();
y.setTextColor(Color.WHITE);
y.setTypeface(mTf);
y.setLabelCount(4);
XLabels x = chart.getXLabels();
x.setTextColor(Color.WHITE);
x.setTypeface(mTf);
chart.animateX(2500);
LineData getData(int count, float range) {
ArrayList&String& xVals = new ArrayList&String&();
for (int i = 0; i & i++) {
xVals.add(mMonths[i % 12]);
ArrayList&Entry& yVals = new ArrayList&Entry&();
for (int i = 0; i & i++) {
float val = (float) (Math.random() * range) + 3;
yVals.add(new Entry(val, i));
LineDataSet set1 = new LineDataSet(yVals, &DataSet 1&);
set1.setLineWidth(1.75f);
set1.setCircleSize(3f);
set1.setColor(Color.WHITE);
set1.setCircleColor(Color.WHITE);
set1.setHighLightColor(Color.WHITE);
ArrayList&LineDataSet& dataSets = new ArrayList&LineDataSet&();
dataSets.add(set1);
LineData data = new LineData(xVals, dataSets);
运行效果图如下:
MPAndroidChart使用方法
这里我们举例绘制一个饼图,步骤如下:
XML布局代码
&com.github.mikephil.charting.charts.PieChart
android:id=”@+id/spread_pie_chart”
android:layout_width=”match_parent”
android:layout_height=”320dip” /&
初始化饼图
ColorTemplate mCt;
mCt = new ColorTemplate();
mCt.addDataSetColors(ColorTemplate.PASTEL_COLORS, this);
mChart = (PieChart) headView.findViewById(R.id.spread_pie_chart);
mChart.setColorTemplate(mCt);
mChart.setDescription(“”);
mChart.setHoleRadius(30f);
mChart.setTransparentCircleRadius(0f);
mChart.setCenterTextSize(18f);
mChart.setDrawXValues(true);
mChart.setUsePercentValues(true);
mChart.setDrawLegend(false);
// space between slices
mChart.setSliceSpace(1f);
mChart.setDrawHoleEnabled(false);
mChart.setTouchEnabled(false);
绑定图表数据
ArrayList yVals = new ArrayList();
ArrayList xVals = new ArrayList();
for (int i = 0; i & listDatas.size(); i++) {
&&&&yVals.add(new Entry((float)listDatas.get(i).getProvinceCount(), i));
&&&&xVals.add(listDatas.get(i).getProvinceName());
DataSet set1 = new DataSet(yVals, &Content&);
ArrayList dataSets = new ArrayList();
dataSets.add(set1);
ChartData data = new ChartData(xVals, dataSets);
mChart.setData(data);
对于简单的Android图表需求,MPAndroidChart可以很好的解决,不妨大家可以试一试。
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:28603次
排名:千里之外
原创:13篇
转载:72篇
译文:25篇
(5)(2)(5)(12)(4)(2)(1)(5)(32)(33)(9)

我要回帖

更多关于 半边脸麻木怎么回事 的文章

 

随机推荐