List of usage examples for org.jfree.chart ChartPanel addChartMouseListener
public void addChartMouseListener(ChartMouseListener listener)
From source file:fr.crnan.videso3d.ihm.PLNSPanel.java
private void addChart(JFreeChart chart) { ChartPanel panel = new ChartPanel(chart); chartPanels.add(panel);//from w w w. jav a 2s . co m JInternalFrame frame = new JInternalFrame(chart.getTitle().getText(), true, false, true, true); frame.add(panel); frame.pack(); frame.setVisible(true); desktop.add(frame); desktop.tile(true); if (chartMouseListener != null) { panel.addChartMouseListener(chartMouseListener); } }
From source file:GUI.ResponseStatistics.java
/** * Creates a sample dataset */ private void InitPieChart(JFreeChart chart) { ChartPanel chartPanel = new ChartPanel(chart); // default size chartPanel.setSize(560, 800);//from ww w. j a va2 s.co m Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize(); int x = (int) ((dimension.getWidth() - chartPanel.getWidth()) / 2); int y = (int) ((dimension.getHeight() - chartPanel.getHeight()) / 2); chartPanel.setLocation(WIDTH, WIDTH); // add it to our application setContentPane(chartPanel); chartPanel.addChartMouseListener(new ChartMouseListener() { public void chartMouseClicked(ChartMouseEvent e) { wait = false; } public void chartMouseMoved(ChartMouseEvent e) { } }); }
From source file:net.sf.maltcms.common.charts.ui.CategoryChartTopComponent.java
private void createChartPanel(final CategoryChartBuilder cb, final ACategoryDataset<?, TARGET> dataset, final InstanceContent content) { content.add(dataset);//from w w w . j a v a 2 s .c o m ChartPanel customPanel = cb.buildPanel(); SelectionOverlay so = new SelectionOverlay(Color.RED, Color.BLUE, 1.75f, 1.75f, 0.66f); customPanel.getChart().getCategoryPlot().getRangeAxis().addChangeListener(so); customPanel.getChart().getCategoryPlot().getDomainAxis().addChangeListener(so); InstanceContentSelectionHandler selectionHandler = new InstanceContentSelectionHandler(content, so, InstanceContentSelectionHandler.Mode.ON_CLICK, dataset); CategoryMouseSelectionHandler<TARGET> sl = new CategoryMouseSelectionHandler<>(dataset); sl.addSelectionChangeListener(so); sl.addSelectionChangeListener(selectionHandler); customPanel.addChartMouseListener(sl); customPanel.addOverlay(so); so.addChangeListener(customPanel); customizeChart(customPanel); content.add(customPanel); content.add(selectionHandler); content.add(sl); }
From source file:com.philng.telemetrydisplay.GraphDisplay.java
/** * Build all the initial data/*ww w.j a v a 2s.com*/ */ public GraphDisplay() { voltage = new TimeSeries("Voltage"); current = new TimeSeries("Current"); this.setLayout(new BorderLayout()); final JFreeChart chart = createChart(createDatasetVoltage()); final ChartPanel chartPanel = new ChartPanel(chart); add(chartPanel, BorderLayout.CENTER); chartPanel.setVisible(true); setVisible(true); // Add a mouse listener for when the user double clicks the mousse // on the graph, it will reset the zoome ChartMouseListener cml = new ChartMouseListener() { @Override public void chartMouseClicked(ChartMouseEvent chartMouseEvent) { if (chartMouseEvent.getTrigger().getClickCount() == 2) { chartPanel.restoreAutoBounds(); } } @Override public void chartMouseMoved(ChartMouseEvent chartMouseEvent) { } }; chartPanel.addChartMouseListener(cml); }
From source file:uk.ac.lkl.cram.ui.ModuleFrame.java
private JXTaskPane createLearningTypeChartPane() { JXTaskPane typeChartPane = new JXTaskPane(); typeChartPane.setTitle("Learning Types"); typeChartPane.setScrollOnExpand(true); final LearningTypeChartMaker maker = new LearningTypeChartMaker(module); final ChartPanel chartPanel = maker.getChartPanel(); //Add a mouse listener to the chart chartPanel.addChartMouseListener(new ChartMouseListener() { @Override/*from w ww . jav a 2s.c om*/ public void chartMouseClicked(ChartMouseEvent cme) { //Get the mouse event MouseEvent trigger = cme.getTrigger(); //Test if the mouse event is a left-button if (trigger.getButton() == MouseEvent.BUTTON1 && trigger.getClickCount() == 2) { //Check that the mouse click is on a segment of the pie if (cme.getEntity() instanceof PieSectionEntity) { //Get the selected segment of the pie PieSectionEntity pieSection = (PieSectionEntity) cme.getEntity(); //Get the key that corresponds to that segment--this is a learning type String key = pieSection.getSectionKey().toString(); //Get the set of tlalineitems whose activity contains that learning type Set<TLALineItem> relevantTLAs = maker.getLearningTypeMap().get(key); //Create a pop up dialog containing that set of tlalineitems LearningTypePopupDialog popup = new LearningTypePopupDialog( (Frame) SwingUtilities.getWindowAncestor(chartPanel), true, relevantTLAs, key); //Set the title of the popup to indicate which learning type was selected popup.setTitle("Activities with \'" + key + "\'"); //Centre the popup at the location of the mouse click Point location = trigger.getLocationOnScreen(); int w = popup.getWidth(); int h = popup.getHeight(); popup.setLocation(location.x - w / 2, location.y - h / 2); popup.setVisible(true); int returnStatus = popup.getReturnStatus(); if (returnStatus == LearningTypePopupDialog.RET_OK) { modifyTLALineItem(popup.getSelectedTLALineItem(), 0); } } } } @Override public void chartMouseMoved(ChartMouseEvent cme) { //Set the cursor shape according to the location of the cursor if (cme.getEntity() instanceof PieSectionEntity) { chartPanel.setCursor(HAND); } else { chartPanel.setCursor(Cursor.getDefaultCursor()); } } }); chartPanel.setPreferredSize(new Dimension(150, 200)); typeChartPane.add(chartPanel); return typeChartPane; }
From source file:net.sf.maltcms.common.charts.ui.XYChartTopComponent.java
private void createChartPanel(final XYChartBuilder cb, final ADataset1D<?, TARGET> dataset, final InstanceContent content) { content.add(dataset);/*from ww w . j a va2 s.co m*/ ChartPanel customPanel = cb.buildPanel(); SelectionOverlay so = new SelectionOverlay(Color.RED, Color.BLUE, 1.75f, 1.75f, 0.66f); customPanel.getChart().getXYPlot().getRangeAxis().addChangeListener(so); customPanel.getChart().getXYPlot().getDomainAxis().addChangeListener(so); InstanceContentSelectionHandler selectionHandler = new InstanceContentSelectionHandler(content, so, InstanceContentSelectionHandler.Mode.ON_CLICK, dataset); XYMouseSelectionHandler<TARGET> sl = new XYMouseSelectionHandler<>(dataset); sl.addSelectionChangeListener(so); sl.addSelectionChangeListener(selectionHandler); customPanel.addChartMouseListener(sl); customPanel.addOverlay(so); so.addChangeListener(customPanel); customizeChart(customPanel); content.add(customPanel); content.add(selectionHandler); content.add(sl); }
From source file:org.trade.ui.chart.CandlestickChart.java
/** * A demonstration application showing a candlestick chart. * // www. j a v a 2s . c o m * @param title * the frame title. * @param strategyData * StrategyData */ public CandlestickChart(final String title, StrategyData strategyData, Tradingday tradingday) { this.strategyData = strategyData; this.setLayout(new BorderLayout()); // Used to mark the current price stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 10, 3 }, 0); valueMarker = new ValueMarker(0.00, Color.black, stroke); this.chart = createChart(this.strategyData, title, tradingday); BlockContainer container = new BlockContainer(new BorderArrangement()); container.add(titleLegend1, RectangleEdge.LEFT); container.add(titleLegend2, RectangleEdge.RIGHT); container.add(new EmptyBlock(2000, 0)); CompositeTitle legends = new CompositeTitle(container); legends.setPosition(RectangleEdge.BOTTOM); this.chart.addSubtitle(legends); final ChartPanel chartPanel = new ChartPanel(this.chart); chartPanel.setFillZoomRectangle(true); chartPanel.setMouseZoomable(true, true); chartPanel.setRefreshBuffer(true); chartPanel.setDoubleBuffered(true); chartPanel.setVerticalAxisTrace(true); chartPanel.setHorizontalAxisTrace(true); chartPanel.addChartMouseListener(new ChartMouseListener() { public void chartMouseMoved(ChartMouseEvent e) { } public void chartMouseClicked(final ChartMouseEvent e) { CombinedDomainXYPlot combinedXYplot = (CombinedDomainXYPlot) e.getChart().getPlot(); @SuppressWarnings("unchecked") List<XYPlot> subplots = combinedXYplot.getSubplots(); if (e.getTrigger().getClickCount() == 2) { double xItem = 0; double yItem = 0; if (e.getEntity() instanceof XYItemEntity) { XYItemEntity xYItemEntity = ((XYItemEntity) e.getEntity()); xItem = xYItemEntity.getDataset().getXValue(xYItemEntity.getSeriesIndex(), xYItemEntity.getItem()); yItem = xYItemEntity.getDataset().getYValue(xYItemEntity.getSeriesIndex(), xYItemEntity.getItem()); } else { PlotEntity plotEntity = ((PlotEntity) e.getEntity()); XYPlot plot = (XYPlot) plotEntity.getPlot(); xItem = plot.getDomainCrosshairValue(); yItem = plot.getRangeCrosshairValue(); } for (XYPlot xyplot : subplots) { double x = xyplot.getDomainCrosshairValue(); double y = xyplot.getRangeCrosshairValue(); /* * If the cross hair is from a right-hand y axis we need * to convert this to a left-hand y axis. */ String rightAxisName = ", Price: "; double rangeLowerLeft = 0; double rangeUpperLeft = 0; double rangeLowerRight = 0; double rangeUpperRight = 0; double yRightLocation = 0; for (int index = 0; index < xyplot.getRangeAxisCount(); index++) { AxisLocation axisLocation = xyplot.getRangeAxisLocation(index); Range range = xyplot.getRangeAxis(index).getRange(); if (axisLocation.equals(AxisLocation.BOTTOM_OR_LEFT) || axisLocation.equals(AxisLocation.TOP_OR_LEFT)) { rangeLowerLeft = range.getLowerBound(); rangeUpperLeft = range.getUpperBound(); rightAxisName = ", " + xyplot.getRangeAxis(index).getLabel() + ": "; } if (y >= range.getLowerBound() && y <= range.getUpperBound() && (axisLocation.equals(AxisLocation.BOTTOM_OR_RIGHT) || axisLocation.equals(AxisLocation.TOP_OR_RIGHT))) { rangeUpperRight = range.getUpperBound(); rangeLowerRight = range.getLowerBound(); } } if ((rangeUpperRight - rangeLowerRight) > 0) { yRightLocation = rangeLowerLeft + ((rangeUpperLeft - rangeLowerLeft) * ((y - rangeLowerRight) / (rangeUpperRight - rangeLowerRight))); } else { yRightLocation = y; } String text = " Time: " + dateFormatShort.format(new Date((long) (x))) + rightAxisName + new Money(y); if (x == xItem && y == yItem) { titleLegend1.setText(text); if (null == clickCrossHairs) { clickCrossHairs = new XYTextAnnotation(text, x, yRightLocation); clickCrossHairs.setTextAnchor(TextAnchor.BOTTOM_LEFT); xyplot.addAnnotation(clickCrossHairs); } else { clickCrossHairs.setText(text); clickCrossHairs.setX(x); clickCrossHairs.setY(yRightLocation); } } } } else if (e.getTrigger().getClickCount() == 1 && null != clickCrossHairs) { for (XYPlot xyplot : subplots) { if (xyplot.removeAnnotation(clickCrossHairs)) { clickCrossHairs = null; titleLegend1.setText(" Time: 0, Price :0.0"); break; } } } } }); this.add(chartPanel, null); this.strategyData.getCandleDataset().getSeries(0).addChangeListener(this); }
From source file:uk.ac.lkl.cram.ui.ModuleFrame.java
private JXTaskPane createLearnerFeedbackChartPane() { JXTaskPane feedbackChartPane = new JXTaskPane(); feedbackChartPane.setScrollOnExpand(true); feedbackChartPane.setTitle("Learner Feedback"); FeedbackChartMaker maker = new FeedbackChartMaker(module); final ChartPanel chartPanel = maker.getChartPanel(); //Add a mouselistener, listening for a double click on a bar of the stacked bar chartPanel.addChartMouseListener(new ChartMouseListener() { @Override/*from w w w.j ava2 s .c o m*/ public void chartMouseClicked(ChartMouseEvent cme) { //Get the mouse event MouseEvent trigger = cme.getTrigger(); //Test if the mouse event is a left-button if (trigger.getButton() == MouseEvent.BUTTON1 && trigger.getClickCount() == 2) { //Create a pop up dialog containing that the tlalineitems FeedbackPopupDialog popup = new FeedbackPopupDialog( (Frame) SwingUtilities.getWindowAncestor(chartPanel), true, module.getTLALineItems()); //Set the title of the popup popup.setTitle("All Activities"); //Centre the popup at the location of the mouse click Point location = trigger.getLocationOnScreen(); int w = popup.getWidth(); int h = popup.getHeight(); popup.setLocation(location.x - w / 2, location.y - h / 2); popup.setVisible(true); int returnStatus = popup.getReturnStatus(); if (returnStatus == LearningTypePopupDialog.RET_OK) { modifyTLALineItem(popup.getSelectedTLALineItem(), 1); } } } @Override public void chartMouseMoved(ChartMouseEvent cme) { //Set the cursor shape according to the location of the cursor if (cme.getEntity() instanceof CategoryItemEntity) { chartPanel.setCursor(HAND); } else { chartPanel.setCursor(Cursor.getDefaultCursor()); } } }); chartPanel.setPreferredSize(new Dimension(150, 200)); feedbackChartPane.add(chartPanel); return feedbackChartPane; }
From source file:uk.ac.lkl.cram.ui.ModuleFrame.java
private JXTaskPane createLearningExperienceChartPane() { JXTaskPane experienceChartPane = new JXTaskPane(); experienceChartPane.setScrollOnExpand(true); experienceChartPane.setTitle("Learning Experiences"); final LearningExperienceChartMaker maker = new LearningExperienceChartMaker(module); final ChartPanel chartPanel = maker.getChartPanel(); //Add a mouselistener, listening for a double click on a bar of the stacked bar chartPanel.addChartMouseListener(new ChartMouseListener() { @Override//from www . ja v a 2 s . c o m public void chartMouseClicked(ChartMouseEvent cme) { //Get the mouse event MouseEvent trigger = cme.getTrigger(); //Test if the mouse event is a left-button if (trigger.getButton() == MouseEvent.BUTTON1 && trigger.getClickCount() == 2) { //Get the selected segment of the pie CategoryItemEntity bar = (CategoryItemEntity) cme.getEntity(); //Get the row key that corresponds to that segment--this is a learning experience String key = bar.getRowKey().toString(); //Get the set of tlalineitems whose activity contains that learning type Set<TLALineItem> relevantTLAs = maker.getLearningExperienceMap().get(key); //Create a pop up dialog containing that set of tlalineitems LearningExperiencePopupDialog popup = new LearningExperiencePopupDialog( (Frame) SwingUtilities.getWindowAncestor(chartPanel), true, relevantTLAs); //Set the title of the popup to indicate which learning type was selected popup.setTitle("Activities with \'" + key + "\'"); //Centre the popup at the location of the mouse click Point location = trigger.getLocationOnScreen(); int w = popup.getWidth(); int h = popup.getHeight(); popup.setLocation(location.x - w / 2, location.y - h / 2); popup.setVisible(true); int returnStatus = popup.getReturnStatus(); if (returnStatus == LearningTypePopupDialog.RET_OK) { modifyTLALineItem(popup.getSelectedTLALineItem(), 0); } } } @Override public void chartMouseMoved(ChartMouseEvent cme) { //Set the cursor shape according to the location of the cursor if (cme.getEntity() instanceof CategoryItemEntity) { chartPanel.setCursor(HAND); } else { chartPanel.setCursor(Cursor.getDefaultCursor()); } } }); chartPanel.setPreferredSize(new Dimension(125, 75)); chartPanel.setMinimumDrawHeight(75); experienceChartPane.add(chartPanel); return experienceChartPane; }
From source file:roaded.MainGUI.java
public void loadGraphInfo() { if (busyStatus) { infoBox("Please load 311 data first on the data tab.", "Message"); return;/*from w w w .j av a 2 s . c o m*/ } pieDataset.clear(); // Store coordinates of each related ticket incident Coordinates coordinateData = new Coordinates(); coords.clear(); for (int i = 0; i < 12; i++) { int counter = 0; if (wardsSelected[i] == true) { for (TicketData entry : ticketObj.getData()) { if (i < 10) { if (entry.getWard() != null && entry.getWard().compareTo("WARD 0" + (i + 1)) == 0) { counter++; coordinateData = new Coordinates(); coordinateData.setCoordinates(entry.getLoc_lat(), entry.getLoc_long()); coords.add(coordinateData); } } else { if (entry.getWard() != null && entry.getWard().compareTo("WARD 1" + (i - 9)) == 0) { counter++; coordinateData = new Coordinates(); coordinateData.setCoordinates(entry.getLoc_lat(), entry.getLoc_long()); coords.add(coordinateData); } } } pieDataset.setValue("Ward " + (i + 1), counter); counter = 0; } } // Export to file so that pin mapper can retrieve it try { PrintStream out = new PrintStream(new FileOutputStream("plotData.txt")); for (Coordinates coord : coords) { out.println(coord); } } catch (FileNotFoundException ex) { Logger.getLogger(MainGUI.class.getName()).log(Level.SEVERE, null, ex); } // Loads the pie chart for all wards selected JFreeChart chart = ChartFactory.createPieChart(wardNumber, pieDataset); chart.removeLegend(); PieChart.setLayout(new java.awt.BorderLayout()); ChartPanel CP = new ChartPanel(chart); CP.addChartMouseListener(CML); CP.setPreferredSize(new Dimension(785, 440)); //size according to my window CP.setMouseWheelEnabled(true); PieChart.add(CP); //bargraph dataset.clear(); //resets bargraph when new wards are elected CategoryDataset dataset1 = createDataset1(); //uses dataset to create the bargraph JFreeChart chart1 = ChartFactory.createBarChart( // bargraph labels and orientation "Ward Incidents", "Wards", "Incidents", dataset1, PlotOrientation.VERTICAL, true, true, false); //bargraph settings DualAxis.setLayout(new java.awt.BorderLayout()); chart1.setBackgroundPaint(Color.white); final CategoryPlot plot = chart1.getCategoryPlot(); plot.setBackgroundPaint(new Color(0xEE, 0xEE, 0xFF)); plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); final LineAndShapeRenderer renderer2 = new LineAndShapeRenderer(); renderer2.setToolTipGenerator(new StandardCategoryToolTipGenerator()); plot.setRenderer(1, renderer2); plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE); //bar graph chart panel creation final ChartPanel chartPanel = new ChartPanel(chart1); chartPanel.setDomainZoomable(true); chartPanel.setRangeZoomable(true); chartPanel.setMouseZoomable(true); chartPanel.setMouseWheelEnabled(true); DualAxis.add(chartPanel); }