Search in sources :

Example 31 with IFormatterTextCallBack

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

the class SplineChart03View method chartRender.

private void chartRender() {
    try {
        // 设置绘图区默认缩进px值,留置空间显示Axis,Axistitle....
        int[] ltrb = getBarLnDefaultSpadding();
        chart.setPadding(ltrb[0], ltrb[1], ltrb[2], ltrb[3]);
        // 显示边框
        chart.showRoundBorder();
        // 数据源
        chart.setCategories(labels);
        chart.setDataSource(chartData);
        // 坐标系
        // 数据轴最大值
        chart.getDataAxis().setAxisMax(100);
        // chart.getDataAxis().setAxisMin(0);
        // 数据轴刻度间隔
        chart.getDataAxis().setAxisSteps(10);
        // y轴
        chart.setCustomLines(mYCustomLineDataset);
        // 标签轴最大值
        chart.setCategoryAxisMax(100);
        // 标签轴最小值
        chart.setCategoryAxisMin(0);
        // chart.setCustomLines(mXCustomLineDataset); //y轴
        // x轴
        chart.setCategoryAxisCustomLines(mXCustomLineDataset);
        // 设置图的背景色
        chart.setApplyBackgroundColor(true);
        chart.setBackgroundColor(Color.rgb(212, 194, 129));
        chart.getBorder().setBorderLineColor(Color.rgb(179, 147, 197));
        // 调轴线与网络线风格
        chart.getCategoryAxis().hideTickMarks();
        chart.getDataAxis().hideAxisLine();
        chart.getDataAxis().hideTickMarks();
        chart.getPlotGrid().showHorizontalLines();
        // chart.hideTopAxis();
        // chart.hideRightAxis();
        chart.getPlotGrid().getHorizontalLinePaint().setColor(Color.rgb(179, 147, 197));
        chart.getCategoryAxis().getAxisPaint().setColor(chart.getPlotGrid().getHorizontalLinePaint().getColor());
        chart.getCategoryAxis().getAxisPaint().setStrokeWidth(chart.getPlotGrid().getHorizontalLinePaint().getStrokeWidth());
        // 定义交叉点标签显示格式,特别备注,因曲线图的特殊性,所以返回格式为:  x值,y值
        // 请自行分析定制
        chart.setDotLabelFormatter(new IFormatterTextCallBack() {

            @Override
            public String textFormatter(String value) {
                // TODO Auto-generated method stub
                String label = "[" + value + "]";
                return (label);
            }
        });
        // 标题
        chart.setTitle("Spline Chart");
        chart.addSubtitle("(XCL-Charts Demo)");
        // 激活点击监听
        chart.ActiveListenItemClick();
        // 为了让触发更灵敏,可以扩大5px的点击监听范围
        chart.extPointClickRange(5);
        chart.showClikedFocus();
        // 显示平滑曲线
        chart.setCrurveLineStyle(XEnum.CrurveLineStyle.BEZIERCURVE);
        // 图例显示在正下方
        chart.getPlotLegend().setVerticalAlign(XEnum.VerticalAlign.BOTTOM);
        chart.getPlotLegend().setHorizontalAlign(XEnum.HorizontalAlign.CENTER);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        Log.e(TAG, e.toString());
    }
}
Also used : IFormatterTextCallBack(org.xclcharts.common.IFormatterTextCallBack)

Example 32 with IFormatterTextCallBack

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

the class StackBarChart02View method chartRender.

private void chartRender() {
    try {
        // 设置绘图区默认缩进px值,留置空间显示Axis,Axistitle....
        int[] ltrb = getBarLnDefaultSpadding();
        chart.setPadding(DensityUtil.dip2px(getContext(), 50), ltrb[1], ltrb[2], ltrb[3]);
        // 显示边框
        chart.showRoundBorder();
        // 指定显示为横向柱形
        chart.setChartDirection(XEnum.Direction.HORIZONTAL);
        // 数据源
        chart.setCategories(chartLabels);
        chart.setDataSource(BarDataSet);
        // 坐标系
        chart.getDataAxis().setAxisMax(1200);
        chart.getDataAxis().setAxisMin(100);
        chart.getDataAxis().setAxisSteps(100);
        // 指定数据轴标签旋转-45度显示
        chart.getCategoryAxis().setTickLabelRotateAngle(-45f);
        // 标题
        chart.setTitle("费用预算与实际发生对比");
        chart.addSubtitle("(XCL-Charts Demo)");
        chart.setTitleAlign(XEnum.HorizontalAlign.CENTER);
        // 图例
        chart.getAxisTitle().setLowerTitle("单位为(W)");
        // 背景网格
        chart.getPlotGrid().showVerticalLines();
        chart.getPlotGrid().setVerticalLineStyle(XEnum.LineStyle.DOT);
        // chart.getPlotGrid().setVerticalLinesVisible(true);
        // chart.getPlotGrid().setEvenRowsFillVisible(true);
        // chart.getPlotGrid().getEvenFillPaint().setColor((int)Color.rgb(225, 230, 246));
        // 定义数据轴标签显示格式
        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().getTickLabelPaint().setColor(Color.rgb(1, 188, 242));
        // 定义柱形上标签显示格式
        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(225, 43, 44));
        // 柱形形标签字体大小
        chart.getBar().getItemLabelPaint().setTextSize(18);
        // 激活点击监听
        chart.ActiveListenItemClick();
        chart.showClikedFocus();
        chart.setPlotPanMode(XEnum.PanMode.VERTICAL);
        // 设置柱子的最大高度范围,不然有些数据太少时,柱子太高不太好看。
        chart.getBar().setBarMaxPxHeight(100.f);
    } 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 33 with IFormatterTextCallBack

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

the class AreaChart03View method chartBgRender.

private void chartBgRender() {
    try {
        // 设置绘图区默认缩进px值,留置空间显示Axis,Axistitle....
        int[] ltrb = getBarLnDefaultSpadding();
        chartBg.setPadding(ltrb[0], ltrb[1], ltrb[2], ltrb[3]);
        chartBg.disableHighPrecision();
        chartBg.disablePanMode();
        // 轴数据源
        // 标签轴
        chartBg.setCategories(mBgLabels);
        // 数据轴
        // chartBg.setDataSource(mDataset);
        chartBg.setCrurveLineStyle(XEnum.CrurveLineStyle.BEELINE);
        // 数据轴最大值
        chartBg.getDataAxis().setAxisMax(100);
        // 数据轴刻度间隔
        chartBg.getDataAxis().setAxisSteps(10);
        // 网格
        chartBg.getPlotGrid().showHorizontalLines();
        chartBg.getPlotGrid().showVerticalLines();
        chartBg.getPlotGrid().setHorizontalLineStyle(XEnum.LineStyle.DOT);
        chartBg.getPlotGrid().setVerticalLineStyle(XEnum.LineStyle.DOT);
        // 把轴线和刻度线给隐藏起来
        chartBg.getDataAxis().hideAxisLine();
        chartBg.getDataAxis().hideTickMarks();
        chartBg.getCategoryAxis().hideAxisLine();
        chartBg.getCategoryAxis().hideTickMarks();
        chartBg.getDataAxis().getTickLabelPaint().setColor(Color.GREEN);
        // 定义数据轴标签显示格式
        chartBg.getDataAxis().setLabelFormatter(new IFormatterTextCallBack() {

            @Override
            public String textFormatter(String value) {
                // TODO Auto-generated method stub
                Double tmp = Double.parseDouble(value);
                if (Double.compare(tmp, mStdValue) == -1 || Double.compare(tmp, mStdValue) == 0) {
                    return "";
                } else {
                    DecimalFormat df = new DecimalFormat("#0");
                    String label = df.format(tmp).toString();
                    return (label);
                }
            }
        });
        chartBg.getPlotLegend().hide();
    // chart.disablePanMode();
    } 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)

Example 34 with IFormatterTextCallBack

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

the class BarChart02View method chartRender.

private void chartRender() {
    try {
        // 设置绘图区默认缩进px值,留置空间显示Axis,Axistitle....
        int[] ltrb = getBarLnDefaultSpadding();
        chart.setPadding(DensityUtil.dip2px(getContext(), 50), ltrb[1], ltrb[2], ltrb[3]);
        chart.setTitle("每日收益情况");
        chart.addSubtitle("(XCL-Charts Demo)");
        chart.setTitleVerticalAlign(XEnum.VerticalAlign.MIDDLE);
        chart.setTitleAlign(XEnum.HorizontalAlign.LEFT);
        // 数据源
        chart.setDataSource(chartData);
        chart.setCategories(chartLabels);
        // 轴标题
        chart.getAxisTitle().setLeftTitle("所售商品");
        chart.getAxisTitle().setLowerTitle("纯利润(天)");
        chart.getAxisTitle().setRightTitle("生意兴隆通四海,财源茂盛达三江。");
        // 数据轴
        chart.getDataAxis().setAxisMax(500);
        chart.getDataAxis().setAxisMin(100);
        chart.getDataAxis().setAxisSteps(100);
        chart.getDataAxis().getTickLabelPaint().setColor(Color.rgb(199, 88, 122));
        chart.getDataAxis().setLabelFormatter(new IFormatterTextCallBack() {

            @Override
            public String textFormatter(String value) {
                // TODO Auto-generated method stub
                String tmp = value + "万元";
                return tmp;
            }
        });
        // 网格
        chart.getPlotGrid().showHorizontalLines();
        chart.getPlotGrid().showVerticalLines();
        chart.getPlotGrid().showEvenRowBgColor();
        // 标签轴文字旋转-45度
        chart.getCategoryAxis().setTickLabelRotateAngle(-45f);
        // 横向显示柱形
        chart.setChartDirection(XEnum.Direction.HORIZONTAL);
        // 在柱形顶部显示值
        chart.getBar().setItemLabelVisible(true);
        chart.getBar().getItemLabelPaint().setTextSize(22);
        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.ActiveListenItemClick();
        chart.showClikedFocus();
    /*
			chart.setDataAxisPosition(XEnum.DataAxisPosition.BOTTOM);
			chart.getDataAxis().setVerticalTickPosition(XEnum.VerticalAlign.BOTTOM);
			
			chart.setCategoryAxisPosition(XEnum.CategoryAxisPosition.LEFT);
			chart.getCategoryAxis().setHorizontalTickAlign(Align.LEFT);
			*/
    } catch (Exception e) {
        // TODO Auto-generated catch block
        Log.e(TAG, e.toString());
    }
}
Also used : IFormatterTextCallBack(org.xclcharts.common.IFormatterTextCallBack) IFormatterDoubleCallBack(org.xclcharts.common.IFormatterDoubleCallBack) DecimalFormat(java.text.DecimalFormat)

Example 35 with IFormatterTextCallBack

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

the class BarChart09View method chartRender.

private void chartRender() {
    try {
        // 设置绘图区默认缩进px值,留置空间显示Axis,Axistitle....
        int[] ltrb = getBarLnDefaultSpadding();
        chart.setPadding(DensityUtil.dip2px(getContext(), 50), ltrb[1], ltrb[2], ltrb[3]);
        chart.setTitle("正负背向式图(横向)");
        chart.addSubtitle("(XCL-Charts Demo)");
        chart.setTitleVerticalAlign(XEnum.VerticalAlign.MIDDLE);
        // chart.setTitleAlign(XEnum.HorizontalAlign.LEFT);
        // 数据源
        chart.setDataSource(chartData);
        chart.setCategories(chartLabels);
        // 轴标题
        chart.getAxisTitle().setLeftTitle("小于230");
        chart.getAxisTitle().setLowerTitle("营收");
        chart.getAxisTitle().setRightTitle("超出230");
        // 数据轴
        chart.getDataAxis().setAxisMax(500);
        chart.getDataAxis().setAxisMin(100);
        chart.getDataAxis().setAxisSteps(100);
        chart.getDataAxis().enabledAxisStd();
        chart.getDataAxis().setAxisStd(230);
        chart.getCategoryAxis().setAxisBuildStd(true);
        chart.getDataAxis().hideTickMarks();
        chart.getDataAxis().getTickLabelPaint().setColor(Color.rgb(199, 88, 122));
        chart.getDataAxis().setLabelFormatter(new IFormatterTextCallBack() {

            @Override
            public String textFormatter(String value) {
                // TODO Auto-generated method stub
                String tmp = value + "万元";
                return tmp;
            }
        });
        // 网格
        chart.getPlotGrid().showHorizontalLines();
        chart.getPlotGrid().hideVerticalLines();
        chart.getPlotGrid().hideEvenRowBgColor();
        // 标签轴文字旋转-45度
        chart.getCategoryAxis().setTickLabelRotateAngle(-45f);
        // 横向显示柱形
        chart.setChartDirection(XEnum.Direction.HORIZONTAL);
        // 在柱形顶部显示值
        chart.getBar().setItemLabelVisible(true);
        chart.getBar().getItemLabelPaint().setTextSize(22);
        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.ActiveListenItemClick();
        chart.showClikedFocus();
        chart.disablePanMode();
        // chart.getDataAxis().setVerticalTickPosition(XEnum.VerticalAlign.TOP);
        chart.setDataAxisLocation(XEnum.AxisLocation.TOP);
        chart.getPlotLegend().hide();
        chart.getBar().setBarStyle(XEnum.BarStyle.FILL);
    /*
			chart.setDataAxisPosition(XEnum.DataAxisPosition.BOTTOM);
			chart.getDataAxis().setVerticalTickPosition(XEnum.VerticalAlign.BOTTOM);
			
			chart.setCategoryAxisPosition(XEnum.CategoryAxisPosition.LEFT);
			chart.getCategoryAxis().setHorizontalTickAlign(Align.LEFT);
			*/
    } catch (Exception e) {
        // TODO Auto-generated catch block
        Log.e(TAG, e.toString());
    }
}
Also used : IFormatterTextCallBack(org.xclcharts.common.IFormatterTextCallBack) IFormatterDoubleCallBack(org.xclcharts.common.IFormatterDoubleCallBack) DecimalFormat(java.text.DecimalFormat)

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