private void chartRender() {
    try {
      // 设置绘图区默认缩进px值,留置空间显示Axis,Axistitle....
      int[] ltrb = getBarLnDefaultSpadding();
      chart.setPadding(mOffset, ltrb[1], ltrb[2], ltrb[3]);

      chart.getBar().setBarStyle(XEnum.BarStyle.FILL);

      chart.setApplyBackgroundColor(true);
      chart.setBackgroundColor(Color.rgb(19, 163, 224));
      chart.showRoundBorder();

      // 数据源
      chart.setDataSource(chartData);
      chart.setCategories(chartLabels);

      // 数据轴
      chart.getDataAxis().setAxisMax(2500);
      chart.getDataAxis().setAxisMin(0);
      chart.getDataAxis().setAxisSteps(500);

      // 让柱子间没空白
      chart.getBar().setBarInnerMargin(0.f);

      // 隐藏轴
      chart.getDataAxis().hide();
      chart.getCategoryAxis().hide();
    } catch (Exception e) {
      // TODO Auto-generated catch block
      Log.e(TAG, e.toString());
    }
  }
示例#2
0
  private void chartAnimation() {
    try {
      chart.getDataAxis().hide();
      chart.getPlotLegend().hide();

      int[] ltrb = getBarLnDefaultSpadding();
      for (int i = 8; i > 0; i--) {
        Thread.sleep(100);
        chart.setPadding(ltrb[0], i * ltrb[1], ltrb[2], ltrb[3]);

        if (1 == i) {
          drawLast();
          drawDyLegend();
        }
        postInvalidate();
      }

    } catch (Exception e) {
      Thread.currentThread().interrupt();
    }
  }
示例#3
0
  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());
    }
  }
  private void chartRender2() {
    try {
      // 设置绘图区默认缩进px值,留置空间显示Axis,Axistitle....
      int[] ltrb = getBarLnDefaultSpadding();
      chart2.setPadding(mOffset, ltrb[1], ltrb[2], ltrb[3]);

      // 显示边框
      // chart2.showRoundBorder();

      // chart.setApplyBackgroundColor(true);
      chart2.setBackgroundColor(Color.rgb(19, 163, 224));
      chart2.showRoundBorder();

      chart2.getBar().setBarStyle(XEnum.BarStyle.FILL);

      // 标题
      chart2.setTitle("负债率标准: 40%~60%");
      chart2.addSubtitle("(XCL-Charts Demo)");
      chart2.getPlotTitle().getTitlePaint().setColor(axisColor);
      chart2.getPlotTitle().getSubtitlePaint().setColor(axisColor);
      // 数据源
      chart2.setDataSource(chartData2);
      chart2.setCategories(chartLabels);

      // 轴标题
      chart2.getAxisTitle().setLeftTitle("金额");
      chart2.getAxisTitle().setLowerTitle("资产负债率");

      // 数据轴
      chart2.getDataAxis().setAxisMax(2500);
      chart2.getDataAxis().setAxisMin(0);
      chart2.getDataAxis().setAxisSteps(500);

      // 定义数据轴标签显示格式
      chart2
          .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);
                }
              });

      // 在柱形顶部显示值
      chart2.getBar().setItemLabelVisible(true);
      // 设定格式
      chart2.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;
            }
          });

      // 让柱子间没空白
      chart2.getBar().setBarInnerMargin(0.f);

      // 轴颜色
      chart2.getDataAxis().getAxisPaint().setColor(axisColor);
      chart2.getCategoryAxis().getAxisPaint().setColor(axisColor);
      chart2.getDataAxis().getTickMarksPaint().setColor(axisColor);
      chart2.getCategoryAxis().getTickMarksPaint().setColor(axisColor);

      chart2.getDataAxis().getTickLabelPaint().setColor(axisColor);
      chart2.getCategoryAxis().getTickLabelPaint().setColor(axisColor);

      chart2.getAxisTitle().getLeftTitlePaint().setColor(axisColor);
      chart2.getAxisTitle().getLowerTitlePaint().setColor(axisColor);

      // 隐藏图例
      chart2.getPlotLegend().hide();
      // chart2.showRoundBorder();

    } catch (Exception e) {
      // TODO Auto-generated catch block
      Log.e(TAG, e.toString());
    }
  }