Search in sources :

Example 11 with CustomLineData

use of org.xclcharts.chart.CustomLineData in project XCL-Charts by xcltapestry.

the class PlotCustomLine method renderHorizontalCustomlinesDataAxis.

/**
 * 用来画横向柱形图,竖向的定制线
 * @param canvas 画布
 * @return 是否成功
 */
public boolean renderHorizontalCustomlinesDataAxis(Canvas canvas) {
    if (!validateParams())
        return false;
    if (0.0f == mAxisScreenWidth) {
        Log.e(TAG, "轴的屏幕宽度值没有传过来。");
        return false;
    }
    double axisHeight = mDataAxis.getAxisMax() - mDataAxis.getAxisMin();
    for (CustomLineData line : mCustomLineDataset) {
        line.getCustomLinePaint().setColor(line.getColor());
        line.getCustomLinePaint().setStrokeWidth(line.getLineStroke());
        double postion = mAxisScreenWidth * ((line.getValue() - mDataAxis.getAxisMin()) / axisHeight);
        float currentX = (float) (mPlotArea.getLeft() + postion);
        // 绘制线
        if (line.isShowLine())
            DrawHelper.getInstance().drawLine(line.getLineStyle(), currentX, mPlotArea.getBottom(), currentX, mPlotArea.getTop(), canvas, line.getCustomLinePaint());
        // 绘制标签和箭头
        renderCapLabelHorizontalPlot(canvas, line, postion);
    }
    return true;
}
Also used : CustomLineData(org.xclcharts.chart.CustomLineData)

Example 12 with CustomLineData

use of org.xclcharts.chart.CustomLineData in project XCL-Charts by xcltapestry.

the class PlotCustomLine method renderCategoryAxisCustomlines.

// PlotAreaRender plotArea,
public boolean renderCategoryAxisCustomlines(Canvas canvas, float plotScreenWidth, PlotAreaRender plotArea, double maxValue, double minValue) {
    setPlotArea(plotArea);
    for (CustomLineData line : mCustomLineDataset) {
        line.getCustomLinePaint().setColor(line.getColor());
        line.getCustomLinePaint().setStrokeWidth(line.getLineStroke());
        float pos = MathHelper.getInstance().getLnPlotXValPosition(plotScreenWidth, plotArea.getLeft(), line.getValue(), maxValue, minValue);
        float currentX = MathHelper.getInstance().add(plotArea.getLeft(), pos);
        // 绘制线
        if (line.isShowLine())
            DrawHelper.getInstance().drawLine(line.getLineStyle(), currentX, plotArea.getBottom(), currentX, plotArea.getTop(), canvas, line.getCustomLinePaint());
        // 绘制标签和箭头
        renderCapLabelHorizontalPlot(canvas, line, pos);
    }
    return true;
}
Also used : CustomLineData(org.xclcharts.chart.CustomLineData)

Example 13 with CustomLineData

use of org.xclcharts.chart.CustomLineData 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 14 with CustomLineData

use of org.xclcharts.chart.CustomLineData in project XCL-Charts by xcltapestry.

the class BarChart03View method chartCustomLines.

/**
 * 定制线/分界线
 */
private void chartCustomLines() {
    CustomLineData line1 = new CustomLineData("及格线", 60d, Color.RED, 7);
    line1.setCustomLineCap(XEnum.DotStyle.PRISMATIC);
    line1.setLabelHorizontalPostion(Align.LEFT);
    line1.setLabelOffset(15);
    line1.getLineLabelPaint().setColor(Color.RED);
    mCustomLineDataset.add(line1);
    CustomLineData line2 = new CustomLineData("没过打屁股", 60d, Color.RED, 7);
    line2.setLabelHorizontalPostion(Align.CENTER);
    line2.hideLine();
    mCustomLineDataset.add(line2);
    CustomLineData line3 = new CustomLineData("良好", 80d, Color.rgb(35, 172, 57), 5);
    line3.setCustomLineCap(XEnum.DotStyle.RECT);
    line3.setLabelHorizontalPostion(Align.LEFT);
    line3.setLineStyle(XEnum.LineStyle.DOT);
    mCustomLineDataset.add(line3);
    CustomLineData line4 = new CustomLineData("优秀", 90d, Color.rgb(53, 169, 239), 5);
    line4.setCustomLineCap(XEnum.DotStyle.TRIANGLE);
    line4.setLabelOffset(15);
    line4.getLineLabelPaint().setColor(Color.rgb(216, 44, 41));
    line4.setLineStyle(XEnum.LineStyle.DASH);
    mCustomLineDataset.add(line4);
    int average = calcAvg();
    CustomLineData line6 = new CustomLineData("本次考试平均得分:" + Integer.toString(average), (double) average, Color.BLUE, 5);
    line6.setLabelHorizontalPostion(Align.CENTER);
    line6.setLineStyle(XEnum.LineStyle.DASH);
    line6.getLineLabelPaint().setColor(Color.RED);
    mCustomLineDataset.add(line6);
}
Also used : CustomLineData(org.xclcharts.chart.CustomLineData)

Example 15 with CustomLineData

use of org.xclcharts.chart.CustomLineData in project XCL-Charts by xcltapestry.

the class BarChart05View method chartCustomLines.

/**
 * 定制线/分界线
 */
private void chartCustomLines() {
    CustomLineData line1 = new CustomLineData("及格线", 60d, Color.RED, 3);
    line1.setCustomLineCap(XEnum.DotStyle.TRIANGLE);
    line1.setLabelVerticalAlign(XEnum.VerticalAlign.BOTTOM);
    line1.setLabelOffset(25);
    line1.getLineLabelPaint().setColor(Color.RED);
    line1.setLineStyle(XEnum.LineStyle.DASH);
    mCustomLineDataset.add(line1);
    CustomLineData line2 = new CustomLineData("良好", 80d, Color.rgb(35, 172, 57), 5);
    line2.setCustomLineCap(XEnum.DotStyle.RECT);
    line2.setLabelVerticalAlign(XEnum.VerticalAlign.MIDDLE);
    line2.setLineStyle(XEnum.LineStyle.DOT);
    mCustomLineDataset.add(line2);
    CustomLineData line3 = new CustomLineData("优秀", 90d, Color.rgb(53, 169, 239), 5);
    line3.setCustomLineCap(XEnum.DotStyle.PRISMATIC);
    line3.setLabelOffset(15);
    line3.getLineLabelPaint().setColor(Color.rgb(216, 44, 41));
    line3.setLineStyle(XEnum.LineStyle.DOT);
    mCustomLineDataset.add(line3);
}
Also used : CustomLineData(org.xclcharts.chart.CustomLineData)

Aggregations

CustomLineData (org.xclcharts.chart.CustomLineData)16 DecimalFormat (java.text.DecimalFormat)2 IFormatterDoubleCallBack (org.xclcharts.common.IFormatterDoubleCallBack)2 ArrayList (java.util.ArrayList)1 IFormatterTextCallBack (org.xclcharts.common.IFormatterTextCallBack)1 AnchorDataPoint (org.xclcharts.renderer.info.AnchorDataPoint)1