// 触发监听 private void triggerClick(float x, float y) { // 交叉线 if (chart.getDyLineVisible()) chart.getDyLine().setCurrentXY(x, y); if (!chart.getListenItemClickStatus()) { // 交叉线 if (chart.getDyLineVisible() && chart.getDyLine().isInvalidate()) this.invalidate(); } else { BarPosition record = chart.getPositionRecord(x, y); if (null == record) { if (chart.getDyLineVisible()) this.invalidate(); return; } if (record.getDataID() >= chartData.size()) return; BarData bData = chartData.get(record.getDataID()); if (record.getDataChildID() >= bData.getDataSet().size()) return; Double bValue = bData.getDataSet().get(record.getDataChildID()); // 显示选中框 chart.showFocusRectF(record.getRectF()); chart.getFocusPaint().setStyle(Style.STROKE); chart.getFocusPaint().setStrokeWidth(3); chart.getFocusPaint().setColor(Color.GREEN); // 在点击处显示tooltip mPaintToolTip.setAntiAlias(true); mPaintToolTip.setColor(bData.getColor()); mDotToolTip.setDotStyle(XEnum.DotStyle.RECT); mDotToolTip.setColor(Color.BLUE); // bData.getColor()); // 位置显示方法一: // 用下列方法可以让tooltip显示在柱形顶部 // chart.getToolTip().setCurrentXY(record.getRectF().centerX(),record.getRectF().top); // 位置显示方法二: // 用下列方法可以让tooltip在所点击位置显示 chart.getToolTip().setCurrentXY(x, y); chart.getToolTip().setStyle(XEnum.DyInfoStyle.ROUNDRECT); chart.getToolTip().addToolTip(mDotToolTip, bData.getKey(), mPaintToolTip); chart.getToolTip().addToolTip("数量:" + Double.toString(bValue), mPaintToolTip); chart.getToolTip().getBackgroundPaint().setAlpha(100); chart.getToolTip().setAlign(Align.CENTER); chart.getToolTip().setInfoStyle(XEnum.DyInfoStyle.CIRCLE); // chart.getToolTip().getBackgroundPaint().setColor(Color.rgb(30, 30, 30)); this.invalidate(); } }