Search in sources :

Example 6 with PlotGrid

use of org.xclcharts.renderer.plot.PlotGrid in project XCL-Charts by xcltapestry.

the class SplineChart04View method chartRender.

private void chartRender() {
    try {
        //设置绘图区默认缩进px值,留置空间显示Axis,Axistitle....		
        int[] ltrb = getBarLnDefaultSpadding();
        chart.setPadding(ltrb[0] + DensityUtil.dip2px(this.getContext(), 10), ltrb[1], ltrb[2] + DensityUtil.dip2px(this.getContext(), 20), ltrb[3]);
        //标题
        chart.setTitle("New GitHub repositories");
        chart.addSubtitle("(XCL-Charts Demo)");
        chart.getAxisTitle().setLeftTitle("Percentage (annual)");
        chart.getAxisTitle().getLeftTitlePaint().setColor(Color.BLACK);
        //显示边框
        chart.showRoundBorder();
        //数据源	
        chart.setCategories(labels);
        chart.setDataSource(chartData);
        chart.setCustomLines(mCustomLineDataset);
        //坐标系
        //数据轴最大值
        chart.getDataAxis().setAxisMax(20);
        //chart.getDataAxis().setAxisMin(0);
        //数据轴刻度间隔
        chart.getDataAxis().setAxisSteps(5);
        //标签轴最大值
        chart.setCategoryAxisMax(6);
        //标签轴最小值
        chart.setCategoryAxisMin(0);
        //背景网格
        PlotGrid plot = chart.getPlotGrid();
        plot.hideHorizontalLines();
        plot.hideVerticalLines();
        chart.getDataAxis().getAxisPaint().setColor(Color.rgb(127, 204, 204));
        chart.getCategoryAxis().getAxisPaint().setColor(Color.rgb(127, 204, 204));
        chart.getDataAxis().getTickMarksPaint().setColor(Color.rgb(127, 204, 204));
        chart.getCategoryAxis().getTickMarksPaint().setColor(Color.rgb(127, 204, 204));
        //定义数据轴标签显示格式
        chart.getDataAxis().setLabelFormatter(new IFormatterTextCallBack() {

            @Override
            public String textFormatter(String value) {
                // TODO Auto-generated method stub		
                Double tmp = Double.parseDouble(value);
                DecimalFormat df = new DecimalFormat("#0");
                String label = df.format(tmp).toString();
                return (label);
            }
        });
        //不使用精确计算,忽略Java计算误差,提高性能
        chart.disableHighPrecision();
        chart.disablePanMode();
        chart.hideBorder();
        chart.getPlotLegend().hide();
    //chart.getCategoryAxis().setLabelLineFeed(XEnum.LabelLineFeed.ODD_EVEN);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        Log.e(TAG, e.toString());
    }
}
Also used : IFormatterTextCallBack(org.xclcharts.common.IFormatterTextCallBack) DecimalFormat(java.text.DecimalFormat) PlotGrid(org.xclcharts.renderer.plot.PlotGrid)

Aggregations

PlotGrid (org.xclcharts.renderer.plot.PlotGrid)6 IFormatterTextCallBack (org.xclcharts.common.IFormatterTextCallBack)3 DecimalFormat (java.text.DecimalFormat)1 ArrayList (java.util.ArrayList)1 AnchorDataPoint (org.xclcharts.renderer.info.AnchorDataPoint)1