如何知道JfreeChart Mouseover或Mouse Click事件上每个DataSet的值

时间:2010-11-16 13:23:51

标签: java jfreechart

我想知道当我在XYPlot上站立时,如何知道曲线的值(数据集)。

我已经实现了kwnoing轴上刻度值的代码:

    int mouseX = event.getTrigger().getX();
    int mouseY = event.getTrigger().getY();

    Point mousePoint = new Point(mouseX, mouseY);

    // convert the Java2D coordinate to axis coordinates...

    ChartRenderingInfo chartInfo = chart.getChartRenderingInfo();
    Point2D java2DPoint = chart.translateScreenToJava2D(mousePoint);
    PlotRenderingInfo plotInfo = chartInfo.getPlotInfo();

    Rectangle2D panelArea = chart.getScreenDataArea(mouseX, mouseY);

    double yy = Math.round(plot.getRangeAxis().java2DToValue(
            mousePoint.getY(), panelArea, plot.getRangeAxisEdge()));

    StringBuffer stringB = new StringBuffer();
    stringB.append("Profundidad : " + yy);

    // the x coordinate is the same for all subplots
    Rectangle2D dataArea = plotInfo.getDataArea();

    List<Long> curvas = pista.getCurvas();

    for (int i = 0, j = curvas.size(); i < j; i++) {
        if (curvas.get(i) != null) {
            double puntoXX = plot.getDomainAxis(i)
                    .java2DToValue(java2DPoint.getX(), dataArea,
                            plot.getDomainAxisEdge(i));

            double xx = (Math.ceil((puntoXX + 0.05d) * 100)) / 100;

            MDCurva curva = BuscadoresLista.buscarEnListaCurvas(curvas
                    .get(i));
            stringB.append(" " + curva.getNombreCurva() + " " + xx);
        }
    }

    PBarraEstado.getInstance().getTextoSubEstado2().setText(
            stringB.toString());

但是,现在我想知道情节中每个曲线的价值。 可以帮助我吗

1 个答案:

答案 0 :(得分:2)

我从examplesMiscellaneous > Crosshairs下的JFreeChart Demo开始。