Search in sources :

Example 26 with IFormatterDoubleCallBack

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

the class BarChart05View method chartRender.

private void chartRender() {
    try {
        // 设置绘图区默认缩进px值,留置空间显示Axis,Axistitle....
        int[] ltrb = getBarLnDefaultSpadding();
        chart.setPadding(DensityUtil.dip2px(getContext(), 35), ltrb[1], ltrb[2], ltrb[3]);
        // 标题
        chart.setTitle("小小熊 - 期末考试成绩");
        chart.addSubtitle("(XCL-Charts Demo)");
        // 数据源
        // chart.setDataSource(chartData);
        chart.setCategories(chartLabels);
        chart.setCustomLines(mCustomLineDataset);
        // 图例
        chart.getAxisTitle().setLeftTitle("科目");
        chart.getAxisTitle().setLowerTitle("分数");
        // 数据轴
        chart.getDataAxis().setAxisMax(110);
        chart.getDataAxis().setAxisMin(0);
        chart.getDataAxis().setAxisSteps(5);
        // 指隔多少个轴刻度(即细刻度)后为主刻度
        chart.getDataAxis().setDetailModeSteps(5);
        // 背景网格
        // chart.getPlotGrid().showHorizontalLines();
        // 横向显示柱形,横向显示效果
        chart.setChartDirection(XEnum.Direction.HORIZONTAL);
        // chart.getPlotGrid().setVerticalLinesVisible(true);
        // 定义数据轴标签显示格式
        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.getBar().getItemLabelPaint().setTextSize(18);
        // 设定格式
        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;
            }
        });
        // 隐藏Key
        chart.getPlotLegend().hide();
        // 禁用平移模式
        chart.disablePanMode();
        // 竖向移动
        // chart.setPlotPanMode(XEnum.PanMode.VERTICAL);
        // 柱形设为outline风格
        chart.getBar().setBarStyle(XEnum.BarStyle.TRIANGLE);
        // 轴
        chart.getCategoryAxis().setHorizontalTickAlign(Align.RIGHT);
        chart.getCategoryAxis().getTickLabelPaint().setTextAlign(Align.LEFT);
        chart.getCategoryAxis().getTickLabelPaint().setColor(Color.rgb(199, 88, 122));
        // chart.getDataAxis().setHorizontalTickAlign(Align.CENTER);
        // chart.getDataAxis().getTickLabelPaint().setTextAlign(Align.CENTER);
        // chart.getDataAxis().setVerticalTickPosition(XEnum.VerticalAlign.BOTTOM);
        // 留出显示箭头的空间
        chart.getClipExt().setExtTop(10.f);
        chart.getClipExt().setExtRight(100.f);
        chart.getDataAxis().setAxisLineStyle(XEnum.AxisLineStyle.CAP);
        chart.getCategoryAxis().setAxisLineStyle(XEnum.AxisLineStyle.CAP);
        // 修改轴标签字体大小
        chart.getDataAxis().getTickLabelPaint().setTextSize(26);
        chart.getCategoryAxis().getTickLabelPaint().setTextSize(36);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : IFormatterTextCallBack(org.xclcharts.common.IFormatterTextCallBack) DecimalFormat(java.text.DecimalFormat) IFormatterDoubleCallBack(org.xclcharts.common.IFormatterDoubleCallBack)

Example 27 with IFormatterDoubleCallBack

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

the class BarChart13View method chartRender.

private void chartRender() {
    try {
        // 设置绘图区默认缩进px值,留置空间显示Axis,Axistitle....
        int[] ltrb = getBarLnDefaultSpadding();
        chart.setPadding(ltrb[0], ltrb[1], ltrb[2], ltrb[3]);
        chart.setTitle("附近广场舞调查 (共23支舞队)");
        chart.addSubtitle("(XCL-Charts Demo)");
        chart.setTitleVerticalAlign(XEnum.VerticalAlign.BOTTOM);
        chart.setTitleAlign(XEnum.HorizontalAlign.RIGHT);
        chart.getPlotTitle().getTitlePaint().setColor(Color.rgb(255, 9, 52));
        // 数据源
        chart.setDataSource(chartData);
        chart.setCategories(chartLabels);
        // 数据轴
        chart.getDataAxis().setAxisMax(500);
        chart.getDataAxis().setAxisMin(100);
        chart.getDataAxis().setAxisSteps(100);
        chart.getDataAxis().getTickLabelPaint().setColor(Color.rgb(199, 88, 122));
        // 网格
        chart.getPlotGrid().hideHorizontalLines();
        chart.getPlotGrid().hideVerticalLines();
        chart.getBar().setItemLabelStyle(XEnum.ItemLabelStyle.BOTTOM);
        chart.getBar().setBarStyle(XEnum.BarStyle.OUTLINE);
        chart.getBar().setBarTickSpacePercent(0.6f);
        // 横向显示柱形
        chart.setChartDirection(XEnum.Direction.HORIZONTAL);
        // 将轴置于右边
        chart.setCategoryAxisLocation(XEnum.AxisLocation.RIGHT);
        chart.getCategoryAxis().hideAxisLine();
        chart.getCategoryAxis().hideTickMarks();
        chart.getDataAxis().hide();
        chart.getCategoryAxis().getTickLabelPaint().setColor(Color.rgb(166, 84, 254));
        // 标签轴文字旋转-45度
        // chart.getCategoryAxis().setTickLabelRotateAngle(-45f);
        // 在柱形顶部显示值
        chart.getBar().setItemLabelVisible(true);
        chart.getBar().getItemLabelPaint().setTextSize(22);
        chart.getBar().setBarStyle(XEnum.BarStyle.ROUNDBAR);
        chart.setItemLabelFormatter(new IFormatterDoubleCallBack() {

            @Override
            public String doubleFormatter(Double value) {
                if (Double.compare(value, 200d) == 0) {
                    return "1) 小苹果";
                } else if (Double.compare(value, 250d) == 0) {
                    return "2) 今夜舞起来";
                } else if (Double.compare(value, 300d) == 0) {
                    return "3) 最炫民族风";
                } else if (Double.compare(value, 350d) == 0) {
                    return "4) 火火的姑娘";
                } else if (Double.compare(value, 400d) == 0) {
                    return "5) 我的玫瑰卓玛拉";
                } else {
                    DecimalFormat df = new DecimalFormat("[#0]");
                    String label = df.format(value).toString();
                    return label;
                }
            }
        });
        chart.disablePanMode();
        // chart.showBorder();
        // 批注
        List<AnchorDataPoint> mAnchorSet = new ArrayList<AnchorDataPoint>();
        AnchorDataPoint an0 = new AnchorDataPoint(0, 0, XEnum.AnchorStyle.ROUNDRECT);
        an0.setBgColor(Color.rgb(255, 145, 126));
        an0.setAnchor("64%");
        AnchorDataPoint an1 = new AnchorDataPoint(0, 1, XEnum.AnchorStyle.ROUNDRECT);
        an1.setBgColor(Color.rgb(255, 145, 126));
        an1.setAnchor("53%");
        AnchorDataPoint an2 = new AnchorDataPoint(0, 2, XEnum.AnchorStyle.ROUNDRECT);
        an2.setBgColor(Color.rgb(255, 145, 126));
        an2.setAnchor("42%");
        AnchorDataPoint an3 = new AnchorDataPoint(0, 3, XEnum.AnchorStyle.CIRCLE);
        an3.setBgColor(Color.rgb(56, 127, 255));
        an3.setAreaStyle(XEnum.DataAreaStyle.FILL);
        an3.setAnchor("二");
        an3.setTextColor(Color.WHITE);
        AnchorDataPoint an4 = new AnchorDataPoint(0, 4, XEnum.AnchorStyle.CIRCLE);
        an4.setBgColor(Color.rgb(56, 127, 255));
        an4.setAreaStyle(XEnum.DataAreaStyle.FILL);
        an4.setAnchor("一");
        an4.setTextColor(Color.WHITE);
        mAnchorSet.add(an0);
        mAnchorSet.add(an1);
        mAnchorSet.add(an2);
        mAnchorSet.add(an3);
        mAnchorSet.add(an4);
        chart.setAnchorDataPoint(mAnchorSet);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        Log.e(TAG, e.toString());
    }
}
Also used : IFormatterDoubleCallBack(org.xclcharts.common.IFormatterDoubleCallBack) DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) AnchorDataPoint(org.xclcharts.renderer.info.AnchorDataPoint)

Example 28 with IFormatterDoubleCallBack

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

the class BarChart3D02View method chartRender.

private void chartRender() {
    try {
        // 设置绘图区默认缩进px值,留置空间显示Axis,Axistitle....
        int[] ltrb = getBarLnDefaultSpadding();
        chart.setPadding(DensityUtil.dip2px(getContext(), 40), ltrb[1], ltrb[2], ltrb[3]);
        // 指定显示为横向3D柱形
        chart.setChartDirection(XEnum.Direction.HORIZONTAL);
        // 数据源
        chart.setDataSource(chartData);
        chart.setCategories(chartLabels);
        // 坐标系
        chart.getDataAxis().setAxisMax(50);
        chart.getDataAxis().setAxisMin(10);
        chart.getDataAxis().setAxisSteps(10);
        chart.getCategoryAxis().setTickLabelRotateAngle(-45f);
        // 标题
        chart.setTitle("本月原料进货情况");
        chart.addSubtitle("(XCL-Charts Demo)");
        // 轴标题
        chart.getAxisTitle().setLeftTitle("原料");
        chart.getAxisTitle().setLowerTitle("进货量");
        // 背景网格
        chart.getPlotGrid().showHorizontalLines();
        chart.getPlotGrid().showVerticalLines();
        chart.getPlotGrid().showEvenRowBgColor();
        // 定义数据轴标签显示格式
        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.00");
                String label = df.format(value).toString();
                return label;
            }
        });
        chart.getBar().getItemLabelPaint().setTextSize(22);
        // 定义基座颜色
        chart.setAxis3DBaseColor(Color.rgb(132, 162, 197));
        // 激活点击监听
        chart.ActiveListenItemClick();
        // 仅能纵向移动
        chart.setPlotPanMode(XEnum.PanMode.VERTICAL);
    } 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 29 with IFormatterDoubleCallBack

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

the class AreaChart01View method chartRender.

private void chartRender() {
    try {
        // 设置绘图区默认缩进px值,留置空间显示Axis,Axistitle....
        int[] ltrb = getBarLnDefaultSpadding();
        chart.setPadding(ltrb[0], ltrb[1], ltrb[2], ltrb[3]);
        // 轴数据源
        // 标签轴
        chart.setCategories(mLabels);
        // 数据轴
        chart.setDataSource(mDataset);
        chart.setCrurveLineStyle(XEnum.CrurveLineStyle.BEELINE);
        // 数据轴最大值
        chart.getDataAxis().setAxisMax(100);
        // 数据轴刻度间隔
        chart.getDataAxis().setAxisSteps(10);
        // 网格
        chart.getPlotGrid().showHorizontalLines();
        chart.getPlotGrid().showVerticalLines();
        // 把顶轴和右轴隐藏
        // 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.getAxisTitle().setLowerAxisTitle("(年份)");
				*/
        // 透明度
        chart.setAreaAlpha(200);
        /*
				//显示图例
				chart.getPlotLegend().showLegend();
				
				//激活点击监听
				chart.ActiveListenItemClick();
				//为了让触发更灵敏,可以扩大5px的点击监听范围
				chart.extPointClickRange(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.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.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) IFormatterDoubleCallBack(org.xclcharts.common.IFormatterDoubleCallBack)

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