Search in sources :

Example 21 with IFormatterTextCallBack

use of org.xclcharts.common.IFormatterTextCallBack 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)

Example 22 with IFormatterTextCallBack

use of org.xclcharts.common.IFormatterTextCallBack in project XCL-Charts by xcltapestry.

the class StackBarChart01View method chartRender.

private void chartRender() {
    try {
        // 设置绘图区默认缩进px值,留置空间显示Axis,Axistitle....
        int[] ltrb = getBarLnDefaultSpadding();
        chart.setPadding(ltrb[0], ltrb[1], ltrb[2], DensityUtil.dip2px(getContext(), 55));
        // 显示边框
        chart.showRoundBorder();
        chart.setChartDirection(XEnum.Direction.VERTICAL);
        // 数据源
        chart.setCategories(chartLabels);
        chart.setDataSource(BarDataSet);
        // 坐标系
        chart.getDataAxis().setAxisMax(1024);
        chart.getDataAxis().setAxisMin(0);
        chart.getDataAxis().setAxisSteps(64);
        // 指定数据轴标签旋转-45度显示
        chart.getCategoryAxis().setTickLabelRotateAngle(-45f);
        Paint labelPaint = chart.getCategoryAxis().getTickLabelPaint();
        labelPaint.setTextAlign(Align.RIGHT);
        labelPaint.setColor(Color.rgb(0, 75, 106));
        // 标题
        chart.setTitle("文件服务器空间使用情况");
        chart.addSubtitle("(XCL-Charts Demo)");
        chart.setTitleAlign(XEnum.HorizontalAlign.CENTER);
        chart.setTitleVerticalAlign(XEnum.VerticalAlign.MIDDLE);
        // 轴标题
        chart.getAxisTitle().setLeftTitle("单位(TB)");
        // 背景网格
        chart.getPlotGrid().showEvenRowBgColor();
        chart.getPlotGrid().showOddRowBgColor();
        // 定义数据轴标签显示格式
        chart.getDataAxis().setLabelFormatter(new IFormatterTextCallBack() {

            @Override
            public String textFormatter(String value) {
                // TODO Auto-generated method stub
                DecimalFormat df = new DecimalFormat("#0");
                Double tmp = Double.parseDouble(value);
                String label = df.format(tmp).toString();
                return label;
            }
        });
        // 定义标签轴标签显示格式
        chart.getCategoryAxis().setLabelFormatter(new IFormatterTextCallBack() {

            @Override
            public String textFormatter(String value) {
                // TODO Auto-generated method stub
                String label = "IP-[" + value + "]";
                return label;
            }
        });
        // 定义柱形上标签显示格式
        chart.getBar().setItemLabelVisible(true);
        chart.setItemLabelFormatter(new IFormatterDoubleCallBack() {

            @Override
            public String doubleFormatter(Double value) {
                // TODO Auto-generated method stub
                DecimalFormat df = new DecimalFormat("#0.00");
                String label = df.format(value).toString();
                return label;
            }
        });
        // 定义柱形上标签显示颜色
        chart.getBar().getItemLabelPaint().setColor(Color.rgb(77, 184, 73));
        chart.getBar().getItemLabelPaint().setTypeface(Typeface.DEFAULT_BOLD);
        // 激活点击监听
        chart.ActiveListenItemClick();
        chart.showClikedFocus();
        chart.setPlotPanMode(XEnum.PanMode.HORIZONTAL);
        chart.setBarCenterStyle(XEnum.BarCenterStyle.TICKMARKS);
    // chart.disablePanMode();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        Log.e(TAG, e.toString());
    }
}
Also used : IFormatterTextCallBack(org.xclcharts.common.IFormatterTextCallBack) DecimalFormat(java.text.DecimalFormat) IFormatterDoubleCallBack(org.xclcharts.common.IFormatterDoubleCallBack) Paint(android.graphics.Paint)

Example 23 with IFormatterTextCallBack

use of org.xclcharts.common.IFormatterTextCallBack in project XCL-Charts by xcltapestry.

the class QuadrantChart01View method chartRender.

private void chartRender() {
    try {
        // 设置绘图区默认缩进px值,留置空间显示Axis,Axistitle....
        int[] ltrb = getBarLnDefaultSpadding();
        chart.setPadding(10, ltrb[1], 10, ltrb[3]);
        // 显示边框
        // chart.showRoundBorder();
        // 数据源
        chart.setCategories(labels);
        chart.setDataSource(chartData);
        // 坐标系
        // 数据轴最大值
        chart.getDataAxis().setAxisMax(100);
        // 数据轴刻度间隔
        chart.getDataAxis().setAxisSteps(10);
        // 标签轴最大值
        chart.setCategoryAxisMax(100);
        // 标签轴最小值
        chart.setCategoryAxisMin(0);
        // 指定气泡半径的最大大小
        chart.setBubbleMaxSize(200);
        // 指定气泡半径的最小大小
        chart.setBubbleMinSize(10);
        // 指定最大气泡大小的实际数据值
        chart.setBubbleScaleMax(100);
        // 指定最小气泡大小的实际数据值
        chart.setBubbleScaleMin(0);
        chart.getCategoryAxis().hideTickMarks();
        chart.getDataAxis().setHorizontalTickAlign(Align.RIGHT);
        chart.getDataAxis().getTickLabelPaint().setTextAlign(Align.LEFT);
        chart.getDataAxis().getAxisPaint().setStrokeWidth(3);
        chart.getCategoryAxis().getAxisPaint().setStrokeWidth(3);
        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));
        // 定义交叉点标签显示格式,特别备注,因曲线图的特殊性,所以返回格式为:  x值,y值
        // 请自行分析定制
        chart.setDotLabelFormatter(new IFormatterTextCallBack() {

            @Override
            public String textFormatter(String value) {
                // TODO Auto-generated method stub
                String label = "(" + value + ")";
                return (label);
            }
        });
        // 标题
        chart.setTitle("象限图");
        chart.addSubtitle("(XCL-Charts Demo)");
        // 激活点击监听
        chart.ActiveListenItemClick();
        // 为了让触发更灵敏,可以扩大5px的点击监听范围
        chart.extPointClickRange(5);
        chart.showClikedFocus();
        // 图例
        chart.getPlotLegend().setVerticalAlign(XEnum.VerticalAlign.BOTTOM);
        chart.getPlotLegend().setHorizontalAlign(XEnum.HorizontalAlign.RIGHT);
        // 象限设置
        chart.getPlotQuadrant().show(45d, 55d);
        chart.getPlotQuadrant().setBgColor(Color.rgb(106, 79, 193), Color.rgb(34, 174, 215), Color.rgb(82, 187, 197), Color.rgb(217, 78, 69));
        chart.getPlotQuadrant().getHorizontalLinePaint().setColor(Color.rgb(127, 204, 204));
        chart.getPlotQuadrant().getVerticalLinePaint().setColor(Color.rgb(127, 204, 204));
        chart.getPlotQuadrant().getHorizontalLinePaint().setStrokeWidth(8);
        chart.getPlotQuadrant().getVerticalLinePaint().setStrokeWidth(8);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        Log.e(TAG, e.toString());
    }
}
Also used : IFormatterTextCallBack(org.xclcharts.common.IFormatterTextCallBack)

Example 24 with IFormatterTextCallBack

use of org.xclcharts.common.IFormatterTextCallBack in project XCL-Charts by xcltapestry.

the class RangeBarChart01View method chartRender.

private void chartRender() {
    try {
        // 设置绘图区默认缩进px值,留置空间显示Axis,Axistitle....
        int[] ltrb = getBarLnDefaultSpadding();
        chart.setPadding(ltrb[0], ltrb[1], ltrb[2], DensityUtil.dip2px(getContext(), 55));
        // 显示边框
        // chart.showRoundBorder();
        // 数据源
        chart.setCategories(chartLabels);
        chart.setDataSource(BarDataSet);
        // 坐标系
        chart.getDataAxis().setAxisMax(1024);
        chart.getDataAxis().setAxisMin(0);
        chart.getDataAxis().setAxisSteps(64);
        chart.getDataAxis().setDetailModeSteps(4);
        chart.setCategoryAxisMax(100);
        chart.setCategoryAxisMin(0);
        // 指定数据轴标签旋转-45度显示
        chart.getCategoryAxis().setTickLabelRotateAngle(-45f);
        chart.getDataAxis().getAxisPaint().setColor(Color.rgb(79, 200, 100));
        chart.getCategoryAxis().getAxisPaint().setColor(Color.rgb(79, 200, 100));
        chart.getDataAxis().getTickMarksPaint().setColor(Color.rgb(79, 200, 100));
        chart.getCategoryAxis().getTickMarksPaint().setColor(Color.rgb(79, 200, 100));
        chart.getPlotTitle().getTitlePaint().setColor(Color.rgb(79, 200, 100));
        chart.getPlotTitle().getSubtitlePaint().setColor(Color.rgb(79, 200, 100));
        chart.getDataAxis().getTickLabelPaint().setColor(Color.rgb(79, 200, 100));
        chart.getCategoryAxis().getTickLabelPaint().setColor(Color.rgb(79, 200, 100));
        // 标题
        chart.setTitle("范围条形图");
        chart.addSubtitle("(XCL-Charts Demo)");
        chart.setTitleAlign(XEnum.HorizontalAlign.CENTER);
        chart.setTitleVerticalAlign(XEnum.VerticalAlign.MIDDLE);
        // 背景网格
        chart.getPlotGrid().showEvenRowBgColor();
        chart.getPlotGrid().showOddRowBgColor();
        // 定义数据轴标签显示格式
        chart.getDataAxis().setLabelFormatter(new IFormatterTextCallBack() {

            @Override
            public String textFormatter(String value) {
                // TODO Auto-generated method stub
                DecimalFormat df = new DecimalFormat("#0");
                Double tmp = Double.parseDouble(value);
                String label = df.format(tmp).toString();
                return label;
            }
        });
        // 定义标签轴标签显示格式
        chart.getCategoryAxis().setLabelFormatter(new IFormatterTextCallBack() {

            @Override
            public String textFormatter(String value) {
                // TODO Auto-generated method stub
                String label = "***" + value + "***";
                return label;
            }
        });
        // 定义柱形上标签显示格式
        chart.getBar().setItemLabelVisible(true);
        chart.setItemLabelFormatter(new IFormatterDoubleCallBack() {

            @Override
            public String doubleFormatter(Double value) {
                // TODO Auto-generated method stub
                DecimalFormat df = new DecimalFormat("#0");
                String label = df.format(value).toString();
                return label;
            }
        });
        // 定义柱形上标签显示颜色
        chart.getBar().getItemLabelPaint().setColor(Color.rgb(77, 184, 73));
        chart.getBar().getItemLabelPaint().setTypeface(Typeface.DEFAULT_BOLD);
        // 设置柱形颜色
        chart.getBar().getBarPaint().setColor(Color.rgb(79, 200, 100));
        // 设置图例
        chart.setKey("图例");
        // 激活点击监听
        chart.ActiveListenItemClick();
        chart.showClikedFocus();
    // chart.enablePanMode();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        Log.e(TAG, e.toString());
    }
}
Also used : IFormatterTextCallBack(org.xclcharts.common.IFormatterTextCallBack) DecimalFormat(java.text.DecimalFormat) IFormatterDoubleCallBack(org.xclcharts.common.IFormatterDoubleCallBack)

Example 25 with IFormatterTextCallBack

use of org.xclcharts.common.IFormatterTextCallBack in project XCL-Charts by xcltapestry.

the class LineChart02View method chartRender.

private void chartRender() {
    try {
        // 设置绘图区默认缩进px值,留置空间显示Axis,Axistitle....
        int[] ltrb = getBarLnDefaultSpadding();
        chart.setPadding(DensityUtil.dip2px(getContext(), 45), ltrb[1], ltrb[2], ltrb[3]);
        // 设定数据源
        chart.setCategories(labels);
        // chart.setDataSource(chartData);
        // chart.setCustomLines(mCustomLineDataset);
        // 数据轴最大值
        chart.getDataAxis().setAxisMax(3500);
        // 数据轴刻度间隔
        chart.getDataAxis().setAxisSteps(100);
        // 指隔多少个轴刻度(即细刻度)后为主刻度
        chart.getDataAxis().setDetailModeSteps(5);
        // 背景网格
        chart.getPlotGrid().showHorizontalLines();
        // 标题
        chart.setTitle("个人历年租房情况一览");
        chart.addSubtitle("(XCL-Charts Demo)");
        // 隐藏顶轴和右边轴
        // chart.hideTopAxis();
        // chart.hideRightAxis();
        // 设置轴风格
        // chart.getDataAxis().setTickMarksVisible(false);
        chart.getDataAxis().getAxisPaint().setStrokeWidth(2);
        chart.getDataAxis().getTickMarksPaint().setStrokeWidth(2);
        chart.getDataAxis().showAxisLabels();
        chart.getCategoryAxis().getAxisPaint().setStrokeWidth(2);
        chart.getCategoryAxis().hideTickMarks();
        // 定义数据轴标签显示格式
        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);
            }
        });
        // 定义线上交叉点标签显示格式
        chart.setItemLabelFormatter(new IFormatterDoubleCallBack() {

            @Override
            public String doubleFormatter(Double value) {
                // TODO Auto-generated method stub
                DecimalFormat df = new DecimalFormat("#0");
                String label = df.format(value).toString();
                return label;
            }
        });
        // chart.setItemLabelFormatter(callBack)
        // 允许线与轴交叉时,线会断开
        chart.setLineAxisIntersectVisible(false);
        // chart.setDataSource(chartData);
        // 动态线
        chart.showDyLine();
        // 不封闭
        chart.setAxesClosed(false);
        // 扩展绘图区右边分割的范围,让定制线的说明文字能显示出来
        chart.getClipExt().setExtRight(150.f);
        // 设置标签交错换行显示
        chart.getCategoryAxis().setLabelLineFeed(XEnum.LabelLineFeed.ODD_EVEN);
        // 仅能横向移动
        chart.setPlotPanMode(XEnum.PanMode.HORIZONTAL);
    // chart.getDataAxis().hide();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        Log.e(TAG, e.toString());
    }
}
Also used : IFormatterTextCallBack(org.xclcharts.common.IFormatterTextCallBack) DecimalFormat(java.text.DecimalFormat) IFormatterDoubleCallBack(org.xclcharts.common.IFormatterDoubleCallBack)

Aggregations

IFormatterTextCallBack (org.xclcharts.common.IFormatterTextCallBack)39 DecimalFormat (java.text.DecimalFormat)33 IFormatterDoubleCallBack (org.xclcharts.common.IFormatterDoubleCallBack)25 PlotGrid (org.xclcharts.renderer.plot.PlotGrid)3 CategoryAxis (org.xclcharts.renderer.axis.CategoryAxis)2 DataAxis (org.xclcharts.renderer.axis.DataAxis)2 Paint (android.graphics.Paint)1 ArrayList (java.util.ArrayList)1 CustomLineData (org.xclcharts.chart.CustomLineData)1 AnchorDataPoint (org.xclcharts.renderer.info.AnchorDataPoint)1 DyLine (org.xclcharts.renderer.info.DyLine)1