mpchart的属性集合

来源:互联网 发布:淘宝co2oc运动假货 编辑:程序博客网 时间:2024/05/29 23:45
 mChart.setOnChartValueSelectedListener(this);// 设置一个选择监听器将生成的图表或没有选择回调时的值。 回调包含所选值及其指数。
        mChart.setUnit(" ¥");
        mChart.setDrawUnitsInChart(true);// 设置表格上数据显示单元;
        mChart.setStartAtZero(true);// 设置是否重零开始计算;
        mChart.setDrawYValues(true);// 如果设置为true,实际值会点,直接点上有值。
        /**
         * 设置图标跟描述边界线部分
         */
        mChart.setDrawBorder(true);
        mChart.setBorderPositions(new BorderPosition[] { BorderPosition.BOTTOM, BorderPosition.LEFT });// 设置图标边框
        mChart.setBorderColor(Color.BLUE);
        mChart.setBorderWidth(2);
        // no description text
        mChart.setDescription("samy测试数据");// 设置一个描述的文本出现在右下角的图。
        mChart.setNoDataTextDescription("You need to provide data for the chart.");
        // mChart.highlightValues(highs);//突出显示指定的表中的条目
        mChart.setHighlightEnabled(true);// 如果设置为true,高亮显示/选择值是可能的图表。 默认值:真的。
        mChart.setTouchEnabled(true);// 如果设置为真,触控手势(如缩放和拖动)将可能在图表。 注意:如果触控手势被禁用,强调联系是禁用的。 默认值:真的。
        mChart.setDragEnabled(true);// 和setTouchEnabled设置true才有用;
        mChart.setScaleEnabled(true);// 启用/禁用拖动和缩放为图表。
        mChart.setDrawGridBackground(true);// 设置单独表格的背景是否跟整体表格颜色一样;
        mChart.setDrawVerticalGrid(true); // 设置表格竖直有线
        mChart.setDrawHorizontalGrid(true);// 设置表格水平有线
        // if disabled, scaling can be done on x- and y-axis separately
        mChart.setPinchZoom(false);
        mChart.setBackgroundColor(Color.GREEN);// 设置总体背景色
        // mChart.setScaleMinima(scaleXmin, scaleYmin);//集的最小规模因素x和y轴。 如果设置例如3 f,用户将无法完全缩小。
        // mChart.centerViewPort(xIndex, yVal);//这种方法可以目标视图的中心(你可以看到从图)到一个特定的位置在图,描述了该指数x轴和y轴上的价值。 这也很好地结合工作setScaleMinima(...)方法。
        mChart.fitScreen();// 重置所有缩放和拖动,使图表符合具体的界限。
        setData(45, 100);
        mChart.animateX(2500);// 模拟水平轴上的图表值的,也就是说图表将建立在指定的时间内从左到右。
        // mChart.animateY(durationMillis);//:模拟垂直轴上的图表值的,也就是说图表将建立在指定时间从下到上。
        // mChart.animateXY(durationMillisX, durationMillisY);//模拟两个水平和垂直轴的,导致左/右下/上累积。
        mChart.setDrawLegend(true);// 设置为true时,下面部分才有用,会显示出来;
        /**
         * 显示/样式标签和底部描述
         */
        // Typeface tf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");
        XLabels xl = mChart.getXLabels(); // 描述图的值X轴描述
        // xl.setTypeface(tf);
        xl.setTextColor(Color.WHITE);
        xl.setPosition(XLabelPosition.BOTTOM);
        YLabels yl = mChart.getYLabels();// 描述图的值Y轴描述
        // yl.setTypeface(tf);
        yl.setTextColor(Color.WHITE);
        yl.setPosition(YLabelPosition.LEFT);
        // get the legend (only possible after setting data)
        Legend l = mChart.getLegend();// 底部描述表格部分
        l.setPosition(LegendPosition.BELOW_CHART_LEFT);
        l.setForm(LegendForm.SQUARE);// 设置描述为隔子;
        // l.setTypeface(tf);
        l.setTextColor(Color.WHITE);
        // l.setXEntrySpace(5f);
        // l.setFormSize(10f);
    }
    private void setData(int count, float range) {
        ArrayList<String> xVals = new ArrayList<String>();
        for (int i = 0; i < count; i++) {
            xVals.add((i) + "");
        }
        ArrayList<Entry> yVals = new ArrayList<Entry>();
        for (int i = 0; i < count; i++) {
            float mult = (range + 1);
            float val = (float) (Math.random() * mult) + 3;// + (float)((mult * 0.1) / 10);
            yVals.add(new Entry(val, i));
        }
        // mChart.setDrawLegend(true);//设置为true时,下面部分才有用,会显示出来;
        LineDataSet set1 = new LineDataSet(yVals, "拼宝交易快报");
        set1.setColor(ColorTemplate.getHoloBlue());
        set1.setCircleColor(ColorTemplate.getHoloBlue());
        set1.setLineWidth(2f);
        set1.setCircleSize(4f);
        set1.setFillAlpha(65);
        set1.setFillColor(ColorTemplate.getHoloBlue());
        set1.setHighLightColor(Color.rgb(244, 117, 117));
        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);
        // set data
        mChart.setData(data);
    }

MPChart图像表格常用设置配置

0 0
原创粉丝点击