Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/352.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何获得鼠标';JXY图中的s y或x轴坐标_Java_Mouse_Coordinates_Jfreechart - Fatal编程技术网

Java 如何获得鼠标';JXY图中的s y或x轴坐标

Java 如何获得鼠标';JXY图中的s y或x轴坐标,java,mouse,coordinates,jfreechart,Java,Mouse,Coordinates,Jfreechart,我已经设法用jfreechart绘制了一个带有几个点的xy图表 我试图做的是能够点击已经绘制的直线上的任意位置,并获得其x或y轴值 有人能帮我吗? 这是我第一次使用j freechart,我感到有些失落 到目前为止,我创建了数据集并生成了图表 TimeSeries s = new TimeSeries("security", Day.class); while (rate_i.hasNext()) { rate r = (rate) rate_i.

我已经设法用jfreechart绘制了一个带有几个点的xy图表

我试图做的是能够点击已经绘制的直线上的任意位置,并获得其x或y轴值

有人能帮我吗? 这是我第一次使用j freechart,我感到有些失落

到目前为止,我创建了数据集并生成了图表

TimeSeries s = new TimeSeries("security", Day.class);
        while (rate_i.hasNext()) {    
            rate r = (rate) rate_i.next();    
            Calendar cal = Calendar.getInstance();
            cal.setTime(r.d);
            int month = cal.get(Calendar.MONTH) + 1;
            int day = cal.get(Calendar.DATE);
            int year = cal.get(Calendar.YEAR);
            s.add(new Day(day, month, year), r.rate);    
        }
        TimeSeriesCollection ds = new TimeSeriesCollection();
        ds.addSeries(s);
        JFreeChart chart = ChartFactory.createTimeSeriesChart(
                "Security Performance over time.", // title
                "Date", // x-axis label
                "Value", // y-axis label
                ds, // data
                true, // create legend?
                true, // generate tooltips?
                false // generate URLs?
                );
        XYPlot xyplot = (XYPlot) chart.getPlot();
        xyplot.setDomainPannable(true);
        xyplot.setRangePannable(false);
        xyplot.setDomainCrosshairVisible(true);
        xyplot.setRangeCrosshairVisible(true);
        org.jfree.chart.renderer.xy.XYItemRenderer xyitemrenderer = xyplot
                .getRenderer();
        if (xyitemrenderer instanceof XYLineAndShapeRenderer) {
            XYLineAndShapeRenderer xylineandshaperenderer = 
                  (XYLineAndShapeRenderer) xyitemrenderer;
            xylineandshaperenderer.setBaseShapesVisible(false);
        }
        DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();
        dateaxis.setDateFormatOverride(
             new SimpleDateFormat("EEE, MMM d, ''yy"));    
        ChartFrame frame = new ChartFrame("Chart", chart);
        frame.setVisible(true);
        frame.setSize(700, 900);

ChartMouseListener
添加到您的附件
ChartPanel
;示例见和。
ChartEntity
将包含有关鼠标目标的详细信息。

谢谢,我将尽快对此进行调查:)