Search in sources :

Example 6 with AnchorDataPoint

use of org.xclcharts.renderer.info.AnchorDataPoint in project XCL-Charts by xcltapestry.

the class XChart method drawAnchor.

/**
 * 绘制批注
 * @param anchorSet 批注集合
 * @param dataID    主数据集id
 * @param childID   子数据集id
 * @param canvas	画布
 * @param x			X坐标点
 * @param y			y坐标点
 * @return 是否有绘制
 */
protected boolean drawAnchor(List<AnchorDataPoint> anchorSet, int dataID, int childID, Canvas canvas, float x, float y, float radius) {
    if (null == anchorSet || -1 == dataID)
        return false;
    int count = anchorSet.size();
    float left = getPlotArea().getLeft();
    float right = getPlotArea().getRight();
    float top = getPlotArea().getTop();
    float bottom = getPlotArea().getBottom();
    for (int i = 0; i < count; i++) {
        AnchorDataPoint an = anchorSet.get(i);
        if (an.getDataSeriesID() == dataID) {
            if ((-1 == childID || -1 == an.getDataChildID()) || (-1 != childID && an.getDataChildID() == childID)) {
                AnchorRender.getInstance().renderAnchor(canvas, an, x, y, radius, left, top, right, bottom);
                return true;
            }
        }
    }
    return false;
}
Also used : AnchorDataPoint(org.xclcharts.renderer.info.AnchorDataPoint) Paint(android.graphics.Paint) AnchorDataPoint(org.xclcharts.renderer.info.AnchorDataPoint)

Example 7 with AnchorDataPoint

use of org.xclcharts.renderer.info.AnchorDataPoint in project XCL-Charts by xcltapestry.

the class BarChart01View method drawLast.

private void drawLast() {
    // 标题
    chart.setTitle("数据库统计");
    chart.addSubtitle("(XCL-Charts Demo)");
    chart.getPlotTitle().getTitlePaint().setColor(colorTitalAxes);
    chart.getPlotTitle().getSubtitlePaint().setColor(colorTitalAxes);
    // 激活点击监听
    chart.ActiveListenItemClick();
    chart.showClikedFocus();
    // 扩展横向显示范围,当数据太多时可用这个扩展实际绘图面积
    // chart.getPlotArea().extWidth(200f);
    // 禁用平移模式
    chart.disablePanMode();
    // 限制只能左右滑动
    // chart.setPlotPanMode(XEnum.PanMode.HORIZONTAL);
    // 禁用双指缩放
    // chart.disableScale();
    chart.getDataAxis().show();
    chart.getPlotLegend().show();
    // 当值与轴最小值相等时,不显示轴
    chart.hideBarEqualAxisMin();
    // 批注
    List<AnchorDataPoint> mAnchorSet = new ArrayList<AnchorDataPoint>();
    AnchorDataPoint an1 = new AnchorDataPoint(2, 0, XEnum.AnchorStyle.CIRCLE);
    an1.setAlpha(200);
    an1.setBgColor(Color.rgb(203, 189, 231));
    // an1.setAreaStyle(XEnum.DataAreaStyle.FILL);
    // CIRCLE
    AnchorDataPoint an2 = new AnchorDataPoint(1, 1, XEnum.AnchorStyle.CIRCLE);
    an2.setBgColor(Color.GRAY);
    // CAPROUNDRECT  RECT
    AnchorDataPoint an3 = new AnchorDataPoint(0, 2, XEnum.AnchorStyle.RECT);
    an3.setBgColor(Color.rgb(255, 145, 126));
    AnchorDataPoint an4 = new AnchorDataPoint(0, 1, XEnum.AnchorStyle.CAPRECT);
    an4.setBgColor(Color.rgb(255, 145, 126));
    an4.setAnchor("我是批注");
    mAnchorSet.add(an1);
    mAnchorSet.add(an2);
    mAnchorSet.add(an3);
    mAnchorSet.add(an4);
    chart.setAnchorDataPoint(mAnchorSet);
    chart.setApplyBackgroundColor(true);
    // Color.rgb(17, 162, 255),Color.rgb(163, 219, 254));//Color.WHITE);
    chart.setBackgroundColor(XEnum.Direction.VERTICAL, Color.rgb(69, 117, 180), Color.rgb(224, 243, 248));
    chart.getBorder().setBorderLineColor(Color.rgb(181, 64, 1));
    chart.getBorder().getLinePaint().setStrokeWidth(3);
    chart.getPlotArea().setBackgroundColor(true, colorPlotArea);
    // chart.getPlotArea().setApplayGradient(true);
    // chart.getPlotArea().setGradientDirection(XEnum.Direction.VERTICAL);
    // chart.getPlotArea().setBeginColor(Color.rgb(116, 174, 210));
    // chart.getPlotArea().setEndColor(Color.WHITE);
    chart.showRoundBorder();
    CustomLineData line1 = new CustomLineData("分界", 60d, Color.rgb(218, 198, 61), 7);
    line1.setCustomLineCap(XEnum.DotStyle.HIDE);
    line1.setLabelHorizontalPostion(Align.RIGHT);
    // line1.setLabelOffset(15);
    line1.getLineLabelPaint().setColor(Color.RED);
    mCustomLineDataset.add(line1);
    chart.setCustomLines(mCustomLineDataset);
    // 饼图
    float pieWH = DensityUtil.dip2px(getContext(), 70);
    float pieX = chart.getPlotArea().getRight() - pieWH * 3;
    chartPie.setChartRange(pieX, pieWH, pieWH, pieWH);
}
Also used : ArrayList(java.util.ArrayList) AnchorDataPoint(org.xclcharts.renderer.info.AnchorDataPoint) CustomLineData(org.xclcharts.chart.CustomLineData)

Example 8 with AnchorDataPoint

use of org.xclcharts.renderer.info.AnchorDataPoint 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)

Aggregations

AnchorDataPoint (org.xclcharts.renderer.info.AnchorDataPoint)8 ArrayList (java.util.ArrayList)6 CustomLineData (org.xclcharts.chart.CustomLineData)2 SuppressLint (android.annotation.SuppressLint)1 Paint (android.graphics.Paint)1 DecimalFormat (java.text.DecimalFormat)1 LinkedList (java.util.LinkedList)1 LineData (org.xclcharts.chart.LineData)1 IFormatterDoubleCallBack (org.xclcharts.common.IFormatterDoubleCallBack)1 IFormatterTextCallBack (org.xclcharts.common.IFormatterTextCallBack)1 PlotGrid (org.xclcharts.renderer.plot.PlotGrid)1