您的位置:首页 > 移动开发 > Android开发

MPAndroidChart的相关图表设置

2016-11-24 15:53 507 查看
//是否启用网格背景

mChart.setDrawGridBackground(false);

//是否设置Y轴坐标

mChart.setDrawYLabels(false);

//设置网格竖线是否显示

mChart.setDrawVerticalGrid(false);

// 设置在Y轴上是否是从0开始显示

mChart.setStartAtZero(false);

//是否在Y轴显示数据,就是曲线上的数据

mChart.setDrawYValues(true);

//设置网格

mChart.setDrawBorder(false);

mChart.setBorderPositions(new BarLineChartBase.BorderPosition[]{

BarLineChartBase.BorderPosition.BOTTOM});

//在chart上的右下角加描述

//mChart.setDescription("曲线图");

//设置Y轴上的单位

mChart.setUnit("");

//设置透明度

mChart.setAlpha(0.8f);

//设置网格底下的那条线的颜色

mChart.setBorderColor(Color.rgb(213, 216, 214));

//设置Y轴前后倒置

mChart.setInvertYAxisEnabled(false);

//设置高亮显示

mChart.setHighlightEnabled(true);

//设置是否可以触摸,如为false,则不能拖动,缩放等

mChart.setTouchEnabled(true);

//设置是否可以拖拽,缩放

mChart.setDragEnabled(true);

mChart.setScaleEnabled(true);

//设置是否能扩大扩小

mChart.setPinchZoom(true);

// 设置背景颜色

mChart.setBackgroundResource(R.mipmap.mpandroidchart_bc);

//设置点击chart图对应的数据弹出标注

//MyMarkerView mv = new MyMarkerView(this, R.layout.custom_marker_view);

// define an offset to change the original position of the marker

// (optional)

//定义一个偏移量来改变标记的原始位置

//mv.setOffsets(-mv.getMeasuredWidth() / 2, -mv.getMeasuredHeight());

// set the marker to the chart

//设置标记图

//mChart.setMarkerView(mv);

// enable/disable highlight indicators (the lines that indicate the

// highlighted Entry)

//启用/禁用突出指标(表明行突出显示的条目)

mChart.setHighlightIndicatorEnabled(false);
XLabels xl = mChart.getXLabels();


// xl.setAvoidFirstLastClipping(true);

// xl.setAdjustXLabels(true);

xl.setPosition(XLabels.XLabelPosition.BOTTOM); // 设置X轴的数据在底部显示

xl.setTextSize(10f); // 设置字体大小

xl.setSpaceBetweenLabels(3); // 设置数据之间的间距
YLabels yl = mChart.getYLabels();
// yl.setPosition(YLabelPosition.LEFT_INSIDE); // set the position
yl.setTextSize(10f); // s设置字体大小
yl.setLabelCount(5); // 设置Y轴最多显示的数据个数
// 加载数据
setData();

//从X轴进入的动画
mChart.animateX(2000);
mChart.animateY(2000);   //从Y轴进入的动画
mChart.animateXY(2000, 2000);    //从XY轴一起进入的动画

//设置最小的缩放
mChart.setScaleMinima(0.5f, 1f);
//设置视口
// mChart.centerViewPort(10, 50);

// get the legend (only possible after setting data)
//后得到图例(唯一可能设置数据)
Legend l = mChart.getLegend();
l.setForm(Legend.LegendForm.LINE);  //设置图最下面显示的类型
l.setTextSize(15);
l.setTextColor(Color.rgb(104, 241, 175));
l.setFormSize(30f); // set the size of the legend forms/shapes 图例形式/形状的大小

// 刷新图表
mChart.invalidate();

set1.setDrawCubic(true);  //设置曲线为圆滑的线
set1.setCubicIntensity(0.2f);
set1.setDrawFilled(false);  //设置包括的范围区域填充颜色
set1.setDrawCircles(true);  //设置有圆点
set1.setLineWidth(2f);    //设置线的宽度
set1.setCircleSize(5f);   //设置小圆的大小
set1.setHighLightColor(Color.rgb(244, 117, 117));
set1.setColor(Color.rgb(104, 241, 175));    //设置曲线的颜色
// create a data object with the datasets
LineData data = new LineData(xVals, set1);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  android