MPAndroidChart的相关图表设置


//是否启用网格背景
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);
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值