Example usage for org.jfree.chart.plot XYPlot getDataset

List of usage examples for org.jfree.chart.plot XYPlot getDataset

Introduction

In this page you can find the example usage for org.jfree.chart.plot XYPlot getDataset.

Prototype

public XYDataset getDataset() 

Source Link

Document

Returns the primary dataset for the plot.

Usage

From source file:com.peterbochs.instrument.InstrumentPanel.java

@Override
public void chartMouseClicked(ChartMouseEvent event) {
    try {//from  ww w . j a  v  a  2  s  .  c  o  m
        // System.out.println(event.getTrigger().getX());
        JFreeChart chart = event.getChart();
        XYPlot xyplot = chart.getXYPlot();
        MyXYBlockRenderer renderer = (MyXYBlockRenderer) xyplot.getRenderer();

        XYZDataset dataset = (XYZDataset) xyplot.getDataset();
        XYItemEntity entity = (XYItemEntity) event.getEntity();
        int series = entity.getSeriesIndex();
        int item = entity.getItem();

        int i = event.getTrigger().getX();
        int j = event.getTrigger().getY();
        Point2D point2d = jMemoryChartPanel.translateScreenToJava2D(new Point(i, j));
        ChartRenderingInfo chartrenderinginfo = jMemoryChartPanel.getChartRenderingInfo();
        Rectangle2D rectangle2d = chartrenderinginfo.getPlotInfo().getDataArea();
        double x = xyplot.getDomainAxis().java2DToValue(point2d.getX(), rectangle2d,
                xyplot.getDomainAxisEdge());
        double y = xyplot.getRangeAxis().java2DToValue(point2d.getY(), rectangle2d, xyplot.getRangeAxisEdge());
        int realX = (int) Math.round(x);
        int realY = (int) Math.round(y);
        renderer.setSelectedXY(realX, realY);
        long blockSize = CommonLib.convertFilesize((String) jBlockSizeComboBox.getSelectedItem());
        long columnCount = Data.getColumnCount(
                CommonLib.convertFilesize((String) jFromComboBox.getSelectedItem()),
                CommonLib.convertFilesize((String) jToComboBox.getSelectedItem()), blockSize);
        Long address = ((realY * columnCount) + realX) * blockSize;

        updateHotestTable(address, blockSize);

        this.jAddressLabel.setText("Address=0x" + Long.toHexString(address));
        this.jRWCountLabel.setText("R/W count=" + (int) dataset.getZValue(series, item));
    } catch (Exception ex) {

    }
}

From source file:velocitekProStartAnalyzer.MainWindow.java

private void createChartPanel() {
    XYSeriesCollection dataset = JDBCPointDao.dataSet;
    JFreeChart chart = createChart(dataset);
    ChartPanel chartPanel = new ChartPanel(chart, true, false, false, true, false);
    chartPanel.setMinimumDrawWidth(0);/*from w  ww.  jav  a2  s. co m*/
    chartPanel.setMinimumDrawHeight(0);
    chartPanel.setMaximumDrawWidth(1920);
    chartPanel.setMaximumDrawHeight(1200);
    chartPanel.getPopupMenu().addSeparator();
    chartPanel.getPopupMenu().add(btnAvgSpeedChart);
    chartPanel.getPopupMenu().add(btnMedianSpeedChart);
    chartPanel.getPopupMenu().add(btnResetSpeedChart);
    chartPanel.getPopupMenu().addSeparator();
    btnMenuSaveSubmenuForChart = new JMenu("Save");
    chartPanel.getPopupMenu().add(btnMenuSaveSubmenuForChart);

    if (JDBCPointDao.points.isEmpty()) {
        btnSaveAsVCC.setEnabled(false);
    }
    saveChartAsPng(chartPanel);

    btnMenuSaveSubmenuForChart.add(btnSaveChartAsPngForChart);
    btnMenuSaveSubmenuForChart.add(btnSaveTableAsPngForChart);
    btnMenuSaveSubmenuForChart.add(btnSaveMapAsPngForChart);
    btnMenuSaveSubmenuForChart.addSeparator();
    btnMenuSaveSubmenuForChart.add(btnSaveAsVCC);
    chartPanel.addChartMouseListener(new ChartMouseListener() {

        @Override
        public void chartMouseClicked(ChartMouseEvent event) {
            Rectangle2D dataArea = chartPanel.getScreenDataArea();
            JFreeChart chart = event.getChart();
            XYPlot plot = (XYPlot) chart.getPlot();
            ValueAxis xAxis = plot.getDomainAxis();
            double x = xAxis.java2DToValue(event.getTrigger().getX(), dataArea, RectangleEdge.BOTTOM);
            // make the crosshairs disappear if the mouse is out of range
            if (!xAxis.getRange().contains(x)) {
                x = Double.NaN;
            }

            x = Math.round(x);

            if (SwingUtilities.isLeftMouseButton(event.getTrigger()) && event.getTrigger().isShiftDown()) {
                for (PointDto cord : JDBCPointDao.points) {
                    {
                        if (cord.getPointID() == x) {
                            if (pointTable.getSelectionModel() == null) {
                                for (int i = 0; i < pointTable.getModel().getRowCount(); i++) {
                                    if (pointTable.getModel().getValueAt(i, 0).equals(cord.getPointID())) {
                                        pointTable.setRowSelectionInterval(i, i);
                                    }
                                }
                            } else {
                                for (int i = 0; i < pointTable.getModel().getRowCount(); i++) {
                                    if (pointTable.getModel().getValueAt(i, 0).equals(cord.getPointID())) {
                                        pointTable.addRowSelectionInterval(pointTable.getSelectedRow(), i);
                                    }
                                }
                            }
                            pointTable.scrollRectToVisible(
                                    pointTable.getCellRect(pointTable.getSelectedRow(), 0, true));
                        }
                    }
                }
            } else {
                for (PointDto cord : JDBCPointDao.points) {
                    {
                        if (cord.getPointID() == x) {
                            if (pointTable.getSelectionModel() != null) {
                                pointTable.getSelectionModel().clearSelection();
                            }
                            for (int i = 0; i < pointTable.getModel().getRowCount(); i++) {
                                if (pointTable.getModel().getValueAt(i, 0).equals(cord.getPointID())) {
                                    pointTable.setRowSelectionInterval(i, i);
                                }
                            }
                            pointTable.scrollRectToVisible(
                                    pointTable.getCellRect(pointTable.getSelectedRow(), 0, true));
                            //MainWindow.pointTable.revalidate();                      
                        }
                    }

                }
            }
        }

        @Override
        public void chartMouseMoved(ChartMouseEvent event) {

            Rectangle2D dataArea = chartPanel.getScreenDataArea();
            JFreeChart chart = event.getChart();
            XYPlot plot = (XYPlot) chart.getPlot();
            ValueAxis xAxis = plot.getDomainAxis();
            double x = xAxis.java2DToValue(event.getTrigger().getX(), dataArea, RectangleEdge.BOTTOM);
            // make the crosshairs disappear if the mouse is out of range
            if (!xAxis.getRange().contains(x)) {
                x = Double.NaN;
            }
            double y = DatasetUtilities.findYValue(plot.getDataset(), 0, x);
            xCrosshair.setValue(x);
            yCrosshair.setValue(y);
            x = Math.round(x);
            for (PointDto cord : JDBCPointDao.points) {

                if (cord.getPointID() == x) {
                    mapPanel.map().removeMapMarker(mapPanel.getMapPoint());
                    mapPanel.setMapPoint(
                            new MapMarkerDot(null, null, cord.getPointLatidude(), cord.getPointLongtidude()));
                    mapPanel.setMapPoint(mapPanel.getMapPoint());
                    mapPanel.getMapPoint().setColor(colorMapMarkerCircle);
                    mapPanel.getMapPoint().setBackColor(colorMapMarkerHover);
                    mapPanel.map().addMapMarker(mapPanel.getMapPoint());
                }

            }
        }

    });
    XYPlot xyPlot = (XYPlot) chart.getPlot();
    ValueAxis rangeAxis = xyPlot.getRangeAxis();
    NavigableMap<Double, PointDto> pointDtoSortedSpeedMap = new TreeMap<Double, PointDto>();

    if (!JDBCPointDao.points.isEmpty()) {
        for (PointDto pointDto : JDBCPointDao.points) {
            pointDtoSortedSpeedMap.put(pointDto.getPointSpeed(), pointDto);
        }
        rangeAxis.setRange(pointDtoSortedSpeedMap.firstEntry().getKey() - 0.1,
                pointDtoSortedSpeedMap.lastEntry().getKey() + 0.1);
    }

    CrosshairOverlay crosshairOverlay = new CrosshairOverlay();
    xCrosshair = new Crosshair(Double.NaN, Color.GRAY, new BasicStroke(0f));
    xCrosshair.setLabelVisible(true);
    yCrosshair = new Crosshair(Double.NaN, Color.GRAY, new BasicStroke(0f));
    yCrosshair.setLabelVisible(true);
    crosshairOverlay.addDomainCrosshair(xCrosshair);
    crosshairOverlay.addRangeCrosshair(yCrosshair);
    chartPanel.addOverlay(crosshairOverlay);
    graphPanel.removeAll();
    graphPanel.add(chartPanel, BorderLayout.CENTER);
    graphPanel.revalidate();
    graphPanel.repaint();
    graphMapSplitPanel.revalidate();
}