Search in sources :

Example 21 with IFormatterDoubleCallBack

use of org.xclcharts.common.IFormatterDoubleCallBack 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 22 with IFormatterDoubleCallBack

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

the class AreaChart03View method chartRender.

private void chartRender() {
    try {
        // 设置绘图区默认缩进px值,留置空间显示Axis,Axistitle....
        int[] ltrb = getBarLnDefaultSpadding();
        chart.setPadding(ltrb[0], ltrb[1], ltrb[2], ltrb[3]);
        chart.disableHighPrecision();
        chart.disablePanMode();
        // 轴数据源
        // 标签轴
        chart.setCategories(mLabels);
        // 数据轴
        chart.setDataSource(mDataset);
        chart.setCrurveLineStyle(XEnum.CrurveLineStyle.BEELINE);
        // 数据轴最大值
        chart.getDataAxis().setAxisMax(100);
        // 数据轴刻度间隔
        chart.getDataAxis().setAxisSteps(10);
        // 网格
        chart.getPlotGrid().hideHorizontalLines();
        chart.getPlotGrid().hideVerticalLines();
        // 把顶轴和右轴隐藏
        // chart.hideTopAxis();
        // chart.hideRightAxis();
        // 把轴线和刻度线给隐藏起来
        chart.getDataAxis().hideAxisLine();
        chart.getDataAxis().hideTickMarks();
        chart.getCategoryAxis().hideAxisLine();
        chart.getCategoryAxis().hideTickMarks();
        // 标题
        chart.setTitle("区域图(Area Chart)");
        chart.addSubtitle("(XCL-Charts Demo)");
        // 设定交叉点标签显示格式
        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.getBackgroundPaint().setAlpha(254);
        // 背景渐变
        // chart.getPlotArea().setBackgroundColor(true, Color.rgb(163, 69, 213));
        // chart.getPlotArea().setApplayGradient(true);
        // chart.getPlotArea().setEndColor(Color.WHITE);
        chart.getAreaFillPaint().setAlpha(254);
        chart.setAreaAlpha(254);
        chart.getDataAxis().hide();
        chart.getCategoryAxis().hide();
        CustomLineData line1 = new CustomLineData("30", mStdValue, Color.RED, 7);
        line1.getLineLabelPaint().setColor(Color.RED);
        line1.setLabelHorizontalPostion(Align.LEFT);
        line1.setLineStyle(XEnum.LineStyle.DASH);
        line1.setLabelOffset(chart.getDataAxis().getTickLabelMargin());
        mCustomLineDataset.add(line1);
        CustomLineData line2 = new CustomLineData("20", 20d, Color.RED, 7);
        line2.setLabelHorizontalPostion(Align.LEFT);
        line2.hideLine();
        line2.setLabelOffset(chart.getDataAxis().getTickLabelMargin());
        line2.getLineLabelPaint().setColor(Color.RED);
        mCustomLineDataset.add(line2);
        CustomLineData line3 = new CustomLineData("10", 10d, Color.RED, 7);
        line3.setLabelHorizontalPostion(Align.LEFT);
        line3.hideLine();
        line3.getLineLabelPaint().setColor(Color.RED);
        line3.setLabelOffset(chart.getDataAxis().getTickLabelMargin());
        mCustomLineDataset.add(line3);
        chart.setCustomLines(mCustomLineDataset);
        chart.getPlotLegend().hide();
    // chart.disablePanMode();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        Log.e(TAG, e.toString());
    }
}
Also used : IFormatterDoubleCallBack(org.xclcharts.common.IFormatterDoubleCallBack) DecimalFormat(java.text.DecimalFormat) CustomLineData(org.xclcharts.chart.CustomLineData)

Example 23 with IFormatterDoubleCallBack

use of org.xclcharts.common.IFormatterDoubleCallBack 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 24 with IFormatterDoubleCallBack

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

Example 25 with IFormatterDoubleCallBack

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

the class BarChart01View method chartRender.

private void chartRender() {
    try {
        // 设置绘图区默认缩进px值,留置空间显示Axis,Axistitle....
        int[] ltrb = getBarLnDefaultSpadding();
        chart.setPadding(ltrb[0], ltrb[1], ltrb[2], ltrb[3]);
        // 数据源
        chart.setDataSource(chartData);
        chart.setCategories(chartLabels);
        // 轴标题
        chart.getAxisTitle().setLeftTitle("数据库");
        chart.getAxisTitle().setLowerTitle("分布位置");
        // 数据轴
        chart.getDataAxis().setAxisMax(100);
        chart.getDataAxis().setAxisMin(0);
        chart.getDataAxis().setAxisSteps(5);
        // 定义数据轴标签显示格式
        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.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().setBarInnerMargin(0d);
        // 轴颜色
        chart.getDataAxis().getAxisPaint().setColor(colorTitalAxes);
        chart.getCategoryAxis().getAxisPaint().setColor(colorTitalAxes);
        chart.getDataAxis().getTickMarksPaint().setColor(colorTitalAxes);
        chart.getCategoryAxis().getTickMarksPaint().setColor(colorTitalAxes);
        chart.getDataAxis().getTickLabelPaint().setColor(colorTitalAxes);
        chart.getCategoryAxis().getTickLabelPaint().setColor(colorTitalAxes);
        chart.getAxisTitle().getLeftTitlePaint().setColor(colorTitalAxes);
        chart.getAxisTitle().getLowerTitlePaint().setColor(colorTitalAxes);
        chart.getBar().getItemLabelPaint().setColor(Color.rgb(246, 133, 39));
        chart.getBar().getItemLabelPaint().setTextSize(15);
        // 指隔多少个轴刻度(即细刻度)后为主刻度
        chart.getDataAxis().setDetailModeSteps(5);
        // 显示十字交叉线
        chart.showDyLine();
        DyLine dyl = chart.getDyLine();
        if (null != dyl) {
            dyl.setDyLineStyle(XEnum.DyLineStyle.Horizontal);
            dyl.setLineDrawStyle(XEnum.LineStyle.DASH);
        }
    // 数据轴居中显示
    // chart.setDataAxisLocation(XEnum.AxisLocation.VERTICAL_CENTER);
    // 忽略Java的float计算误差,提高性能
    // chart.disableHighPrecision();
    // 柱形和标签居中方式
    // chart.setBarCenterStyle(XEnum.BarCenterStyle.TICKMARKS);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        Log.e(TAG, "chartRender():" + e.toString());
    }
}
Also used : IFormatterTextCallBack(org.xclcharts.common.IFormatterTextCallBack) DecimalFormat(java.text.DecimalFormat) IFormatterDoubleCallBack(org.xclcharts.common.IFormatterDoubleCallBack) DyLine(org.xclcharts.renderer.info.DyLine)

Aggregations

DecimalFormat (java.text.DecimalFormat)29 IFormatterDoubleCallBack (org.xclcharts.common.IFormatterDoubleCallBack)29 IFormatterTextCallBack (org.xclcharts.common.IFormatterTextCallBack)25 CustomLineData (org.xclcharts.chart.CustomLineData)2 SuppressLint (android.annotation.SuppressLint)1 Paint (android.graphics.Paint)1 ArrayList (java.util.ArrayList)1 CategoryAxis (org.xclcharts.renderer.axis.CategoryAxis)1 Bar (org.xclcharts.renderer.bar.Bar)1 AnchorDataPoint (org.xclcharts.renderer.info.AnchorDataPoint)1 DyLine (org.xclcharts.renderer.info.DyLine)1