List of usage examples for org.jfree.chart.entity XYItemEntity getItem
public int getItem()
From source file:dbseer.gui.panel.DBSeerSelectableChartPanel.java
@Override public void chartMouseMoved(ChartMouseEvent chartMouseEvent) { ChartEntity entity = chartMouseEvent.getEntity(); // System.out.println(entity.toString()); if (entity != null) { if (entity instanceof PieSectionEntity) { PieSectionEntity pieSectionEntity = (PieSectionEntity) entity; int index = pieSectionEntity.getSectionIndex(); PiePlot plot = (PiePlot) chart.getPlot(); int sectionCount = plot.getDataset().getItemCount(); for (int i = 0; i < sectionCount; ++i) { String key = (String) plot.getDataset().getKey(i); if (i == index) { plot.setExplodePercent(key, 0.20); } else { plot.setExplodePercent(key, 0.0); }//from w w w . j a va2s . c o m } lastSeries = index; lastCategory = -1; showQueryAction.setSeries(lastSeries); showQueryAction.setCategory(lastCategory); showQueriesMenuItem.setEnabled(true); } if (entity instanceof XYItemEntity) { XYItemEntity xyItemEntity = (XYItemEntity) entity; XYPlot plot = chart.getXYPlot(); DBSeerXYLineAndShapeRenderer renderer = (DBSeerXYLineAndShapeRenderer) plot.getRenderer(); if (isTransactionSampleChart && xyItemEntity.getSeriesIndex() < maxTransactionSeries) { renderer.setLastSeriesAndCategory(xyItemEntity.getSeriesIndex(), xyItemEntity.getItem()); lastSeries = xyItemEntity.getSeriesIndex(); lastCategory = xyItemEntity.getItem(); showQueryAction.setSeries(lastSeries); showQueryAction.setCategory(lastCategory); showQueriesMenuItem.setEnabled(true); this.setRefreshBuffer(true); this.repaint(); } } } }
From source file:com.igalia.java.zk.components.JFreeChartEngine.java
/** * decode XYItemEntity into key-value pair of Area's componentScope. *///from w w w. j av a 2 s . c o m private void decodeXYInfo(Area area, XYItemEntity info, Chart chart) { if (info == null) { return; } TimeZone tz = chart.getTimeZone(); if (tz == null) tz = TimeZones.getCurrent(); XYDataset dataset = info.getDataset(); int si = info.getSeriesIndex(); int ii = info.getItem(); area.setAttribute("series", dataset.getSeriesKey(si)); if (dataset instanceof XYZDataset) { XYZDataset ds = (XYZDataset) dataset; area.setAttribute("x", ds.getX(si, ii)); area.setAttribute("y", ds.getY(si, ii)); area.setAttribute("z", ds.getZ(si, ii)); } else { area.setAttribute("x", dataset.getX(si, ii)); area.setAttribute("y", dataset.getY(si, ii)); } }
From source file:com.rapidminer.gui.plotter.charts.MultipleScatterPlotter.java
@Override public void updatePlotter() { prepareData();/*from ww w .jav a 2s.c o m*/ JFreeChart chart = ChartFactory.createScatterPlot(null, // chart title null, // domain axis label null, // range axis label dataSet, // data PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips false // URLs ); if (xAxis >= 0) { int size = dataSet.getSeriesCount(); chart = ChartFactory.createScatterPlot(null, // chart title null, // domain axis label null, // range axis label dataSet, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // URLs ); // renderer settings XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) chart.getXYPlot().getRenderer(); renderer.setBaseOutlinePaint(Color.BLACK); renderer.setUseOutlinePaint(true); renderer.setDrawOutlines(true); for (int i = 0; i < size; i++) { renderer.setSeriesShapesVisible(i, this.showPoints[plotIndexToColumnIndexMap.get(i)]); renderer.setSeriesLinesVisible(i, this.showLines[plotIndexToColumnIndexMap.get(i)]); } renderer.setSeriesShape(0, new Ellipse2D.Double(-3, -3, 7, 7)); // legend settings LegendTitle legend = chart.getLegend(); if (legend != null) { legend.setPosition(RectangleEdge.TOP); legend.setFrame(BlockBorder.NONE); legend.setHorizontalAlignment(HorizontalAlignment.LEFT); legend.setItemFont(LABEL_FONT); } } // GENERAL CHART SETTINGS int size = dataSet.getSeriesCount(); if (size <= 1) { chart.getXYPlot().getRenderer().setSeriesPaint(0, getColorProvider().getPointColor(1.0d)); } else { for (int i = 0; i < dataSet.getSeriesCount(); i++) { chart.getXYPlot().getRenderer().setSeriesStroke(i, new BasicStroke(1.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); chart.getXYPlot().getRenderer().setSeriesPaint(i, getColorProvider().getPointColor(i / (double) (dataSet.getSeriesCount() - 1))); } } // set the background colors for the chart... chart.setBackgroundPaint(Color.WHITE); chart.getPlot().setBackgroundPaint(Color.WHITE); chart.setAntiAlias(false); // general plot settings XYPlot plot = chart.getXYPlot(); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); // domain axis if (xAxis >= 0) { if (dataTable.isNominal(xAxis)) { String[] values = new String[dataTable.getNumberOfValues(xAxis)]; for (int i = 0; i < values.length; i++) { values[i] = dataTable.mapIndex(xAxis, i); } plot.setDomainAxis(new SymbolAxis(dataTable.getColumnName(xAxis), values)); } else if ((dataTable.isDate(xAxis)) || (dataTable.isDateTime(xAxis))) { DateAxis domainAxis = new DateAxis(dataTable.getColumnName(xAxis)); domainAxis.setTimeZone(Tools.getPreferredTimeZone()); plot.setDomainAxis(domainAxis); } else { if (xLogScale) { LogAxis domainAxis = new LogAxis(dataTable.getColumnName(xAxis)); domainAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits(Locale.US)); plot.setDomainAxis(domainAxis); } else { NumberAxis domainAxis = new NumberAxis(dataTable.getColumnName(xAxis)); domainAxis.setAutoRangeStickyZero(false); domainAxis.setAutoRangeIncludesZero(false); plot.setDomainAxis(domainAxis); } } } plot.getDomainAxis().setLabelFont(LABEL_FONT_BOLD); plot.getDomainAxis().setTickLabelFont(LABEL_FONT); // rotate labels if (isLabelRotating()) { plot.getDomainAxis().setTickLabelsVisible(true); plot.getDomainAxis().setVerticalTickLabels(true); } // range axis plot.getRangeAxis().setLabelFont(LABEL_FONT_BOLD); plot.getRangeAxis().setTickLabelFont(LABEL_FONT); // Chart Panel Settings if (panel instanceof AbstractChartPanel) { panel.setChart(chart); } else { panel = new AbstractChartPanel(chart, getWidth(), getHeight() - MARGIN); final ChartPanelShiftController controller = new ChartPanelShiftController(panel); panel.addMouseListener(controller); panel.addMouseMotionListener(controller); // react to mouse clicks // ATTENTION: ACTIVATING THIS WILL LEAD TO SEVERE MEMORY LEAKS!!! (see below) panel.addChartMouseListener(new ChartMouseListener() { @Override public void chartMouseClicked(ChartMouseEvent e) { if (e.getTrigger().getClickCount() > 1) { XYItemEntity entity = (XYItemEntity) e.getEntity(); if (entity != null) { String id = idMap.get(new SeriesAndItem(entity.getSeriesIndex(), entity.getItem())); if (id != null) { ObjectVisualizer visualizer = ObjectVisualizerService .getVisualizerForObject(dataTable); visualizer.startVisualization(id); } } } } @Override public void chartMouseMoved(ChartMouseEvent e) { } }); } // tooltips class CustomXYToolTipGenerator implements XYToolTipGenerator { public CustomXYToolTipGenerator() { } @Override public String generateToolTip(XYDataset dataset, int row, int column) { String id = idMap.get(new SeriesAndItem(row, column)); if (id != null) { return "<html><b>Id: " + id + "</b> (" + dataset.getSeriesKey(row) + ", " + Tools.formatIntegerIfPossible(dataset.getXValue(row, column)) + ", " + Tools.formatIntegerIfPossible(dataset.getYValue(row, column)) + ")</html>"; } else { return "<html>(" + dataset.getSeriesKey(row) + ", " + Tools.formatIntegerIfPossible(dataset.getXValue(row, column)) + ", " + Tools.formatIntegerIfPossible(dataset.getYValue(row, column)) + ")</html>"; } } } for (int i = 0; i < dataSet.getSeriesCount(); i++) { plot.getRenderer().setSeriesToolTipGenerator(i, new CustomXYToolTipGenerator()); } }
From source file:course_generator.param.frmEditCurve.java
/** * This method is called to initialize the form. */// w w w . ja v a 2s .c o m private void initComponents() { int line = 0; setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setTitle(bundle.getString("frmEditCurve.title")); setPreferredSize(new Dimension(1200, 600)); setAlwaysOnTop(true); setResizable(false); setType(java.awt.Window.Type.UTILITY); addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { formWindowClosing(evt); } }); // -- Layout // ------------------------------------------------------------ Container paneGlobal = getContentPane(); paneGlobal.setLayout(new GridBagLayout()); //-- Curves list ListCurves = new javax.swing.JList<>(); model = new ParamListModel(); ListCurves.setModel(model); ListCurves.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); ListCurves.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { SelectCurve(); } }); jScrollPaneCurves = new javax.swing.JScrollPane(); jScrollPaneCurves.setViewportView(ListCurves); Utils.addComponent(paneGlobal, jScrollPaneCurves, 0, 0, 1, 4, 0.5, 1, 10, 10, 0, 0, GridBagConstraints.PAGE_START, GridBagConstraints.BOTH); //-- Curve management toolbar CreateCurvesToolbar(); Utils.addComponent(paneGlobal, ToolBarAction, 1, 0, 1, 4, 0, 0, 10, 0, 0, 0, GridBagConstraints.BASELINE_LEADING, GridBagConstraints.BOTH); lbSelectedCurve = new javax.swing.JLabel(); lbSelectedCurve.setBorder(javax.swing.BorderFactory.createEtchedBorder()); lbSelectedCurve.setText("Selected"); lbSelectedCurve.setHorizontalAlignment(JLabel.LEFT); Utils.addComponent(paneGlobal, lbSelectedCurve, 2, 0, GridBagConstraints.REMAINDER, 1, 1, 0, 10, 0, 5, 10, GridBagConstraints.BASELINE_LEADING, GridBagConstraints.HORIZONTAL); //-- Curve name lbName = new javax.swing.JLabel(); lbName.setBorder(javax.swing.BorderFactory.createEtchedBorder()); lbName.setText(" " + bundle.getString("frmEditCurve.lbName.text") + " "); Utils.addComponent(paneGlobal, lbName, 2, 1, 1, 1, 0, 0, 0, 0, 5, 0, GridBagConstraints.BASELINE_LEADING, GridBagConstraints.HORIZONTAL); lbNameVal = new javax.swing.JLabel(); lbNameVal.setBorder(javax.swing.BorderFactory.createEtchedBorder()); Utils.addComponent(paneGlobal, lbNameVal, 3, 1, GridBagConstraints.REMAINDER, 1, 1, 0, 0, 5, 5, 10, GridBagConstraints.BASELINE_LEADING, GridBagConstraints.BOTH); //-- Curve comment lbComment = new javax.swing.JLabel(); lbComment.setBorder(javax.swing.BorderFactory.createEtchedBorder()); lbComment.setText(" " + bundle.getString("frmEditCurve.lbComment.text") + " "); Utils.addComponent(paneGlobal, lbComment, 2, 2, 1, 1, 0, 0, 0, 0, 5, 0, GridBagConstraints.BASELINE_LEADING, GridBagConstraints.HORIZONTAL); tfComment = new JTextField(); tfComment.setBorder(javax.swing.BorderFactory.createEtchedBorder()); Utils.addComponent(paneGlobal, tfComment, 3, 2, GridBagConstraints.REMAINDER, 1, 1, 0, 0, 5, 5, 10, GridBagConstraints.BASELINE_LEADING, GridBagConstraints.HORIZONTAL); //-- Point list TablePoints = new javax.swing.JTable(); TablePoints.setModel(tablemodel);//new ParamPointsModel(param)); TablePoints.getTableHeader().setReorderingAllowed(false); TablePoints.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { // TableMainMouseClicked(evt); } }); TablePoints.addKeyListener(new java.awt.event.KeyAdapter() { public void keyReleased(java.awt.event.KeyEvent evt) { // TableMainKeyReleased(evt); } }); jScrollPanePoint = new javax.swing.JScrollPane(); jScrollPanePoint.setViewportView(TablePoints); Utils.addComponent(paneGlobal, jScrollPanePoint, 2, 3, 2, 1, 0.5, 0, 0, 0, 0, 0, GridBagConstraints.BASELINE_LEADING, GridBagConstraints.BOTH); //-- Edit toolbar CreateEditToolbar(); Utils.addComponent(paneGlobal, ToolBarEdit, 4, 3, 1, 1, 0, 0, 0, 0, 0, 0, GridBagConstraints.BASELINE_LEADING, GridBagConstraints.BOTH); jPanelProfilChart = new ChartPanel(chart); Utils.addComponent(paneGlobal, jPanelProfilChart, 5, 3, 1, 1, 1, 0, 0, 0, 0, 10, GridBagConstraints.BASELINE_LEADING, GridBagConstraints.BOTH); CrosshairOverlay crosshairOverlay = new CrosshairOverlay(); xCrosshair = new Crosshair(Double.NaN, Color.DARK_GRAY, new BasicStroke(0f)); xCrosshair.setLabelVisible(true); xCrosshair.setLabelBackgroundPaint(Color.WHITE); yCrosshair = new Crosshair(Double.NaN, Color.DARK_GRAY, new BasicStroke(0f)); yCrosshair.setLabelVisible(true); yCrosshair.setLabelBackgroundPaint(Color.WHITE); crosshairOverlay.addDomainCrosshair(xCrosshair); crosshairOverlay.addRangeCrosshair(yCrosshair); jPanelProfilChart.addOverlay(crosshairOverlay); jPanelProfilChart.setBackground(new java.awt.Color(255, 0, 51)); jPanelProfilChart.addChartMouseListener(new ChartMouseListener() { @Override public void chartMouseClicked(ChartMouseEvent event) { ChartEntity chartentity = event.getEntity(); if (chartentity instanceof XYItemEntity) { XYItemEntity e = (XYItemEntity) chartentity; XYDataset d = e.getDataset(); int s = e.getSeriesIndex(); int i = e.getItem(); double x = d.getXValue(s, i); double y = d.getYValue(s, i); xCrosshair.setValue(x); yCrosshair.setValue(y); } } @Override public void chartMouseMoved(ChartMouseEvent event) { } }); // == Bottom button // =========================================================== btOk = new javax.swing.JButton(); btOk.setText(bundle.getString("frmEditCurve.btOk.text")); btOk.setIcon(new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/valid.png"))); btOk.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { RequestToClose(); } }); Utils.addComponent(paneGlobal, btOk, 0, 5, GridBagConstraints.REMAINDER, 1, 0, 0, 10, 0, 10, 0, GridBagConstraints.CENTER, GridBagConstraints.NONE); // -- pack(); //-- Refresh the curve list RefreshCurveList(); //-- Center the windows setLocationRelativeTo(null); }
From source file:ec.util.chart.swing.JTimeSeriesChart.java
private void enableObsTriggering() { chartPanel.addChartMouseListener(new ChartMouseListener() { @Override/*w w w.jav a 2 s. co m*/ public void chartMouseClicked(ChartMouseEvent event) { if (isInteractive()) { setSelectedObs(getObsIndex(event)); } } @Override public void chartMouseMoved(ChartMouseEvent event) { if (isInteractive()) { setHoveredObs(getObsIndex(event)); } } private ObsIndex getObsIndex(ChartMouseEvent event) { if (event.getEntity() instanceof XYItemEntity) { XYItemEntity xxx = (XYItemEntity) event.getEntity(); int series = ((FilteredXYDataset) xxx.getDataset()).originalIndexOf(xxx.getSeriesIndex()); int obs = xxx.getItem(); return ObsIndex.valueOf(series, obs); } else { return ObsIndex.NULL; } } }); }
From source file:de.bfs.radon.omsimulation.gui.OMPanelResults.java
/** * Creates a panel displaying the distribution chart of certain selected * statistical values.//from w w w . j a v a 2 s.com * * @param title * The headline of the chart. Will be hidden if set to null. * @param statistics * The selected statistics of a campaign containing all needed * values. * @param roomType * The room type to determine the colour of the chart. * @param preview * Will hide annotations, labels and headlines if set true. * @param fullscreen * Will correctly adjust the preferred size to screen resolution if * true. * @param mouseEvent * Will enable mouseClickedEvent if set true. Use with care, and only * inside the results panel. Set to false if you are unsure what you * are doing. * @return A chart displaying the distribution of certain selected statistical * values. */ public JPanel createDistributionPanel(String title, DescriptiveStatistics statistics, OMRoomType roomType, boolean preview, boolean fullscreen, boolean mouseEvent) { JFreeChart chart = OMCharts.createDistributionChart(title, statistics, roomType, preview); ChartPanel chartPanel = new ChartPanel(chart); Dimension dim; if (fullscreen) { dim = Toolkit.getDefaultToolkit().getScreenSize(); } else { dim = new Dimension(730, 347); } chartPanel.setPreferredSize(dim); if (mouseEvent) { chartPanel.addChartMouseListener(new ChartMouseListener() { @Override public void chartMouseClicked(ChartMouseEvent e) { OMSimulation simulation = (OMSimulation) comboBoxSimulations.getSelectedItem(); OMCampaign[] campaigns = simulation.getCampaigns(); try { XYItemEntity entity = (XYItemEntity) e.getEntity(); XYDataset dataset = entity.getDataset(); int item = entity.getItem(); double x = dataset.getXValue(0, item); double comparable = 0.0; OMCampaign result = null; OMStatistics selectedType = (OMStatistics) comboBoxStatistics.getSelectedItem(); for (int i = 0; i < campaigns.length; i++) { switch (selectedType) { case RoomArithmeticMeans: comparable = campaigns[i].getRoomAverage(); break; case RoomGeometricMeans: comparable = campaigns[i].getRoomLogAverage(); break; case RoomMedianQ50: comparable = campaigns[i].getRoomMedian(); break; case RoomMaxima: comparable = campaigns[i].getRoomMaximum(); break; case CellarArithmeticMeans: comparable = campaigns[i].getCellarAverage(); break; case CellarGeometricMeans: comparable = campaigns[i].getCellarLogAverage(); break; case CellarMedianQ50: comparable = campaigns[i].getCellarMedian(); break; case CellarMaxima: comparable = campaigns[i].getCellarMaximum(); break; default: comparable = campaigns[i].getRoomAverage(); break; } if (comparable == x) { result = campaigns[i]; } } if (result != null) { try { Thread.sleep(100); } catch (InterruptedException ie) { ie.printStackTrace(); } JTabbedPane tab = (JTabbedPane) getParent(); tab.remove(tab.getComponentAt(4)); JPanel jpanelTesting = new OMPanelTesting(simulation, result); tab.add(jpanelTesting, "Analyse", 4); tab.updateUI(); tab.setSelectedIndex(4); } } catch (Exception x) { x.printStackTrace(); } } @Override public void chartMouseMoved(ChartMouseEvent ignore) { } }); } JPanel distPanel = (JPanel) chartPanel; return distPanel; }
From source file:org.talend.dataprofiler.chart.TOPChartService.java
@Override public void addSpecifiedListenersForCorrelationChart(Object chartcomp, final Object chart, final boolean isAvg, final boolean isDate, final Map<Integer, Object> keyWithAdapter) { final ChartComposite chartComp = (ChartComposite) chartcomp; chartComp.addChartMouseListener(new ChartMouseListener() { @Override/*from w ww . ja v a 2s . c o m*/ public void chartMouseClicked(ChartMouseEvent event) { chartComp.setRangeZoomable(event.getTrigger().getButton() == 1); chartComp.setDomainZoomable(event.getTrigger().getButton() == 1); if (event.getTrigger().getButton() != 3) { return; } final Menu menu = new Menu(chartComp.getShell(), SWT.POP_UP); MenuItem itemShowInFullScreen = new MenuItem(menu, SWT.PUSH); itemShowInFullScreen.setText(Messages.getString("HideSeriesChartComposite.ShowInFullScreen")); //$NON-NLS-1$ itemShowInFullScreen.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { Display.getDefault().asyncExec(new Runnable() { @Override public void run() { showChartInFillScreen(chart, isAvg, isDate); } }); } }); chartComp.setMenu(menu); ChartEntity chartEntity = event.getEntity(); if (chartEntity != null) { if (isAvg) { addMenuOnBubbleChart(menu, chartEntity); } else if (isDate) { addMenuOnGantChart(menu, chartEntity); } } menu.setVisible(true); } private void addMenuOnBubbleChart(Menu menu, ChartEntity chartEntity) { if (chartEntity instanceof XYItemEntity) { XYItemEntity xyItemEntity = (XYItemEntity) chartEntity; createMenuItem(menu, xyItemEntity.getItem()); } } private void addMenuOnGantChart(Menu menu, ChartEntity chartEntity) { if (chartEntity instanceof CategoryItemEntity) { CategoryItemEntity itemEntity = (CategoryItemEntity) chartEntity; createMenuItem(menu, itemEntity.getCategoryIndex()); } } private void createMenuItem(Menu menu, final int seriesK) { final SelectionAdapter selectionAdapter = (SelectionAdapter) keyWithAdapter.get(seriesK); MenuItem item; item = new MenuItem(menu, SWT.PUSH); item.setText(Messages.getString("HideSeriesChartComposite.ViewRow")); //$NON-NLS-1$ item.addSelectionListener(selectionAdapter); } @Override public void chartMouseMoved(ChartMouseEvent event) { // no need to implement } }); }
From source file:com.rapidminer.gui.plotter.charts.Abstract2DChartPlotter.java
@Override public void updatePlotter() { prepareData();// w w w .j av a2 s .c o m JFreeChart chart; if (axis[X_AXIS] >= 0 && axis[Y_AXIS] >= 0) { if (nominal) { int size = dataSet.getSeriesCount(); chart = ChartFactory.createScatterPlot(null, // chart title null, // domain axis label null, // range axis label dataSet, // data PlotOrientation.VERTICAL, // orientation colorColumn >= 0 && size < 100 ? true : false, // include legend true, // tooltips false // URLs ); // renderer settings try { chart.getXYPlot().setRenderer(getItemRenderer(nominal, size, this.minColor, this.maxColor)); } catch (Exception e) { // do nothing } // legend settings LegendTitle legend = chart.getLegend(); if (legend != null) { legend.setPosition(RectangleEdge.TOP); legend.setFrame(BlockBorder.NONE); legend.setHorizontalAlignment(HorizontalAlignment.LEFT); legend.setItemFont(LABEL_FONT); BlockContainer wrapper = new BlockContainer(new BorderArrangement()); LabelBlock title = new LabelBlock(getDataTable().getColumnName(colorColumn), new Font("SansSerif", Font.BOLD, 12)); title.setPadding(0, 5, 5, 5); wrapper.add(title, RectangleEdge.LEFT); BlockContainer items = legend.getItemContainer(); wrapper.add(items, RectangleEdge.RIGHT); legend.setWrapper(wrapper); } } else { chart = ChartFactory.createScatterPlot(null, // chart title null, // domain axis label null, // range axis label dataSet, // data PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips false // URLs ); // renderer settings try { chart.getXYPlot().setRenderer(getItemRenderer(nominal, -1, minColor, maxColor)); } catch (Exception e) { // do nothing } LegendTitle legendTitle = new LegendTitle(chart.getXYPlot().getRenderer()) { private static final long serialVersionUID = 1288380309936848376L; @Override public Object draw(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D area, java.lang.Object params) { if (dataTable.isDate(colorColumn) || dataTable.isTime(colorColumn) || dataTable.isDateTime(colorColumn)) { drawSimpleDateLegend(g2, (int) (area.getCenterX() - 170), (int) (area.getCenterY() + 7), dataTable, colorColumn, minColor, maxColor); return new BlockResult(); } else { final String minColorString = Tools.formatNumber(minColor); final String maxColorString = Tools.formatNumber(maxColor); drawSimpleNumericalLegend(g2, (int) (area.getCenterX() - 75), (int) (area.getCenterY() + 7), getDataTable().getColumnName(colorColumn), minColorString, maxColorString); return new BlockResult(); } } @Override public void draw(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D area) { draw(g2, area, null); } }; BlockContainer wrapper = new BlockContainer(new BorderArrangement()); LabelBlock title = new LabelBlock(getDataTable().getColumnName(colorColumn), new Font("SansSerif", Font.BOLD, 12)); title.setPadding(0, 5, 5, 5); wrapper.add(title, RectangleEdge.LEFT); BlockContainer items = legendTitle.getItemContainer(); wrapper.add(items, RectangleEdge.RIGHT); legendTitle.setWrapper(wrapper); chart.addLegend(legendTitle); } } else { chart = ChartFactory.createScatterPlot(null, // chart title null, // domain axis label null, // range axis label dataSet, // data PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips false // URLs ); } // GENERAL CHART SETTINGS // set the background colors for the chart... chart.setBackgroundPaint(Color.WHITE); chart.getPlot().setBackgroundPaint(Color.WHITE); chart.setAntiAlias(false); // general plot settings XYPlot plot = chart.getXYPlot(); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); // domain axis if (axis[X_AXIS] >= 0) { if (dataTable.isNominal(axis[X_AXIS])) { String[] values = new String[dataTable.getNumberOfValues(axis[X_AXIS])]; for (int i = 0; i < values.length; i++) { values[i] = dataTable.mapIndex(axis[X_AXIS], i); } plot.setDomainAxis(new SymbolAxis(dataTable.getColumnName(axis[X_AXIS]), values)); } else if (dataTable.isDate(axis[X_AXIS]) || dataTable.isDateTime(axis[X_AXIS])) { DateAxis domainAxis = new DateAxis(dataTable.getColumnName(axis[X_AXIS])); domainAxis.setTimeZone(Tools.getPreferredTimeZone()); plot.setDomainAxis(domainAxis); } else { if (logScales[X_AXIS]) { LogAxis domainAxis = new LogAxis(dataTable.getColumnName(axis[X_AXIS])); domainAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits(Locale.US)); plot.setDomainAxis(domainAxis); } else { NumberAxis domainAxis = new NumberAxis(dataTable.getColumnName(axis[X_AXIS])); domainAxis.setAutoRangeStickyZero(false); domainAxis.setAutoRangeIncludesZero(false); plot.setDomainAxis(domainAxis); } } } if (axis[X_AXIS] >= 0) { Range range = getRangeForDimension(axis[X_AXIS]); if (range != null) { plot.getDomainAxis().setRange(range, true, false); } else { plot.getDomainAxis().setAutoRange(true); } } plot.getDomainAxis().setLabelFont(LABEL_FONT_BOLD); plot.getDomainAxis().setTickLabelFont(LABEL_FONT); // rotate labels if (isLabelRotating()) { plot.getDomainAxis().setTickLabelsVisible(true); plot.getDomainAxis().setVerticalTickLabels(true); } // range axis if (axis[Y_AXIS] >= 0) { if (dataTable.isNominal(axis[Y_AXIS])) { String[] values = new String[dataTable.getNumberOfValues(axis[Y_AXIS])]; for (int i = 0; i < values.length; i++) { values[i] = dataTable.mapIndex(axis[Y_AXIS], i); } plot.setRangeAxis(new SymbolAxis(dataTable.getColumnName(axis[Y_AXIS]), values)); } else if (dataTable.isDate(axis[Y_AXIS]) || dataTable.isDateTime(axis[Y_AXIS])) { DateAxis rangeAxis = new DateAxis(dataTable.getColumnName(axis[Y_AXIS])); rangeAxis.setTimeZone(Tools.getPreferredTimeZone()); plot.setRangeAxis(rangeAxis); } else { if (logScales[Y_AXIS]) { LogAxis rangeAxis = new LogAxis(dataTable.getColumnName(axis[Y_AXIS])); rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits(Locale.US)); plot.setRangeAxis(rangeAxis); } else { NumberAxis rangeAxis = new NumberAxis(dataTable.getColumnName(axis[Y_AXIS])); rangeAxis.setAutoRangeStickyZero(false); rangeAxis.setAutoRangeIncludesZero(false); plot.setRangeAxis(rangeAxis); } } } plot.getRangeAxis().setLabelFont(LABEL_FONT_BOLD); plot.getRangeAxis().setTickLabelFont(LABEL_FONT); if (axis[Y_AXIS] >= 0) { Range range = getRangeForDimension(axis[Y_AXIS]); if (range != null) { plot.getRangeAxis().setRange(range, true, false); } else { plot.getRangeAxis().setAutoRange(true); } } // Chart Panel Settings AbstractChartPanel panel = getPlotterPanel(); if (panel == null) { panel = createPanel(chart); // react to mouse clicks panel.addChartMouseListener(new ChartMouseListener() { @Override public void chartMouseClicked(ChartMouseEvent e) { if (e.getTrigger().getClickCount() > 1) { if (e.getEntity() instanceof XYItemEntity) { XYItemEntity entity = (XYItemEntity) e.getEntity(); if (entity != null) { String id = idMap.get(new SeriesAndItem(entity.getSeriesIndex(), entity.getItem())); if (id != null) { ObjectVisualizer visualizer = ObjectVisualizerService .getVisualizerForObject(dataTable); visualizer.startVisualization(id); } } } } } @Override public void chartMouseMoved(ChartMouseEvent e) { } }); } else { panel.setChart(chart); } // tooltips class CustomXYToolTipGenerator implements XYToolTipGenerator { public CustomXYToolTipGenerator() { } private String formatValue(int axis, double value) { if (dataTable.isNominal(axis)) { // TODO add mapping of value to nominal value return Tools.formatIntegerIfPossible(value); } else if (dataTable.isNumerical(axis)) { return Tools.formatIntegerIfPossible(value); } else if (dataTable.isDate(axis)) { return Tools.createDateAndFormat(value); } else if (dataTable.isTime(axis)) { return Tools.createTimeAndFormat(value); } else if (dataTable.isDateTime(axis)) { return Tools.createDateTimeAndFormat(value); } return "?"; } @Override public String generateToolTip(XYDataset dataset, int row, int column) { String id = idMap.get(new SeriesAndItem(row, column)); if (id != null) { return "<html><b>Id: " + id + "</b> (" + dataset.getSeriesKey(row) + ", " + formatValue(axis[X_AXIS], dataset.getXValue(row, column)) + ", " + formatValue(axis[Y_AXIS], dataset.getYValue(row, column)) + ")</html>"; } else { return "<html>(" + dataset.getSeriesKey(row) + ", " + formatValue(axis[X_AXIS], dataset.getXValue(row, column)) + ", " + formatValue(axis[Y_AXIS], dataset.getYValue(row, column)) + ")</html>"; } } } for (int i = 0; i < dataSet.getSeriesCount(); i++) { plot.getRenderer().setSeriesToolTipGenerator(i, new CustomXYToolTipGenerator()); } }
From source file:com.chart.SwingChart.java
/** * // w w w .jav a 2s .co m * @param name Chart name * @param parent Skeleton parent * @param axes Configuration of axes * @param abcissaName Abcissa name */ public SwingChart(String name, final Skeleton parent, List<AxisChart> axes, String abcissaName) { this.skeleton = parent; this.axes = axes; this.name = name; this.abcissaFormat = NumberFormat.getInstance(Locale.getDefault()); this.ordinateFormat = NumberFormat.getInstance(Locale.getDefault()); plot = new XYPlot(); plot.setBackgroundPaint(scene2awtColor(javafx.scene.paint.Color.web(strChartBackgroundColor))); plot.setDomainGridlinePaint(scene2awtColor(javafx.scene.paint.Color.web(strGridlineColor))); plot.setRangeGridlinePaint(scene2awtColor(javafx.scene.paint.Color.web(strGridlineColor))); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); abcissaAxis = new NumberAxis(abcissaName); ((NumberAxis) abcissaAxis).setAutoRangeIncludesZero(false); abcissaAxis.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 12)); abcissaAxis.setLabelFont(new Font("SansSerif", Font.PLAIN, 12)); abcissaAxis.setLabelPaint(scene2awtColor(javafx.scene.paint.Color.web(strTickColor))); abcissaAxis.setTickLabelPaint(scene2awtColor(javafx.scene.paint.Color.web(strTickColor))); abcissaAxis.setAutoRange(true); abcissaAxis.setLowerMargin(0.0); abcissaAxis.setUpperMargin(0.0); abcissaAxis.setTickLabelsVisible(true); abcissaAxis.setLabelFont(abcissaAxis.getLabelFont().deriveFont(fontSize)); abcissaAxis.setTickLabelFont(abcissaAxis.getLabelFont().deriveFont(fontSize)); plot.setDomainAxis(abcissaAxis); for (int i = 0; i < axes.size(); i++) { AxisChart categoria = axes.get(i); addAxis(categoria.getName()); for (int j = 0; j < categoria.configSerieList.size(); j++) { SimpleSeriesConfiguration cs = categoria.configSerieList.get(j); addSeries(categoria.getName(), cs); } } chart = new JFreeChart("", new Font("SansSerif", Font.BOLD, 16), plot, false); chart.setBackgroundPaint(scene2awtColor(javafx.scene.paint.Color.web(strBackgroundColor))); chartPanel = new ChartPanel(chart); chartPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4), BorderFactory.createLineBorder(scene2awtColor(javafx.scene.paint.Color.web(strBackgroundColor))))); chartPanel.getInputMap().put(KeyStroke.getKeyStroke("ESCAPE"), "escape"); chartPanel.getActionMap().put("escape", new AbstractAction() { @Override public void actionPerformed(java.awt.event.ActionEvent e) { for (int i = 0; i < plot.getDatasetCount(); i++) { XYDataset test = plot.getDataset(i); XYItemRenderer r = plot.getRenderer(i); r.removeAnnotations(); } } }); chartPanel.addChartMouseListener(cml = new ChartMouseListener() { @Override public void chartMouseClicked(ChartMouseEvent event) { } @Override public void chartMouseMoved(ChartMouseEvent event) { try { XYItemEntity xyitem = (XYItemEntity) event.getEntity(); // get clicked entity XYDataset dataset = (XYDataset) xyitem.getDataset(); // get data set double x = dataset.getXValue(xyitem.getSeriesIndex(), xyitem.getItem()); double y = dataset.getYValue(xyitem.getSeriesIndex(), xyitem.getItem()); final XYPlot plot = chart.getXYPlot(); for (int i = 0; i < plot.getDatasetCount(); i++) { XYDataset test = plot.getDataset(i); XYItemRenderer r = plot.getRenderer(i); r.removeAnnotations(); if (test == dataset) { NumberAxis ejeOrdenada = AxesList.get(i); double y_max = ejeOrdenada.getUpperBound(); double y_min = ejeOrdenada.getLowerBound(); double x_max = abcissaAxis.getUpperBound(); double x_min = abcissaAxis.getLowerBound(); double angulo; if (y > (y_max + y_min) / 2 && x > (x_max + x_min) / 2) { angulo = 3.0 * Math.PI / 4.0; } else if (y > (y_max + y_min) / 2 && x < (x_max + x_min) / 2) { angulo = 1.0 * Math.PI / 4.0; } else if (y < (y_max + y_min) / 2 && x < (x_max + x_min) / 2) { angulo = 7.0 * Math.PI / 4.0; } else { angulo = 5.0 * Math.PI / 4.0; } CircleDrawer cd = new CircleDrawer((Color) r.getSeriesPaint(xyitem.getSeriesIndex()), new BasicStroke(2.0f), null); //XYAnnotation bestBid = new XYDrawableAnnotation(dataset.getXValue(xyitem.getSeriesIndex(), xyitem.getItem()), dataset.getYValue(xyitem.getSeriesIndex(), xyitem.getItem()), 11, 11, cd); String txt = "X:" + abcissaFormat.format(x) + ", Y:" + ordinateFormat.format(y); XYPointerAnnotation anotacion = new XYPointerAnnotation(txt, dataset.getXValue(xyitem.getSeriesIndex(), xyitem.getItem()), dataset.getYValue(xyitem.getSeriesIndex(), xyitem.getItem()), angulo); anotacion.setTipRadius(10.0); anotacion.setBaseRadius(35.0); anotacion.setFont(new Font("SansSerif", Font.PLAIN, 10)); if (Long.parseLong((strChartBackgroundColor.replace("#", "")), 16) > 0xffffff / 2) { anotacion.setPaint(Color.black); anotacion.setArrowPaint(Color.black); } else { anotacion.setPaint(Color.white); anotacion.setArrowPaint(Color.white); } //bestBid.setPaint((Color) r.getSeriesPaint(xyitem.getSeriesIndex())); r.addAnnotation(anotacion); } } //LabelValorVariable.setSize(LabelValorVariable.getPreferredSize()); } catch (NullPointerException | ClassCastException ex) { } } }); chartPanel.setPopupMenu(null); chartPanel.setBackground(scene2awtColor(javafx.scene.paint.Color.web(strBackgroundColor))); SwingNode sn = new SwingNode(); sn.setContent(chartPanel); chartFrame = new VBox(); chartFrame.getChildren().addAll(sn, legendFrame); VBox.setVgrow(sn, Priority.ALWAYS); VBox.setVgrow(legendFrame, Priority.NEVER); chartFrame.getStylesheets().addAll(SwingChart.class.getResource("overlay-chart.css").toExternalForm()); legendFrame.setStyle("marco: " + strBackgroundColor + ";-fx-background-color: marco;"); MenuItem mi; mi = new MenuItem("Print"); mi.setOnAction((ActionEvent t) -> { print(chartFrame); }); contextMenuList.add(mi); sn.setOnMouseClicked((MouseEvent t) -> { if (menu != null) { menu.hide(); } if (t.getClickCount() == 2) { backgroundEdition(); } }); mi = new MenuItem("Copy to clipboard"); mi.setOnAction((ActionEvent t) -> { copyClipboard(chartFrame); }); contextMenuList.add(mi); mi = new MenuItem("Export values"); mi.setOnAction((ActionEvent t) -> { FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Export to file"); fileChooser.getExtensionFilters() .addAll(new FileChooser.ExtensionFilter("Comma Separated Values", "*.csv")); Window w = null; try { w = parent.getScene().getWindow(); } catch (NullPointerException e) { } File file = fileChooser.showSaveDialog(w); if (file != null) { export(file); } }); contextMenuList.add(mi); chartFrame.setOnContextMenuRequested((ContextMenuEvent t) -> { if (menu != null) { menu.hide(); } menu = new ContextMenu(); menu.getItems().addAll(contextMenuList); menu.show(chartFrame, t.getScreenX(), t.getScreenY()); }); }
From source file:com.att.aro.ui.view.diagnostictab.GraphPanel.java
@Override public void chartMouseClicked(ChartMouseEvent chartmouseevent) { Point2D point = chartmouseevent.getTrigger().getPoint(); Rectangle2D plotArea = getChartPanel().getScreenDataArea(); XYPlot plot = (XYPlot) getAdvancedGraph().getPlot(); final double lastChartX = new Double( plot.getDomainAxis().java2DToValue(point.getX(), plotArea, plot.getDomainAxisEdge())); // setCrossHair(lastChartX); // SwingUtilities.invokeLater(new Runnable() { // @Override/*from w w w . j a va2 s . c om*/ // public void run() { // setCrossHair(lastChartX); // } // }); for (GraphPanelListener gpl : listeners) { gpl.graphPanelClicked(lastChartX); /* New added @Tinbit */ ChartEntity entity = chartmouseevent.getEntity(); if (entity instanceof XYItemEntity) { XYItemEntity xyItem = (XYItemEntity) entity; XYDataset xyDataset = xyItem.getDataset(); int seriesIndex = xyItem.getSeriesIndex(); int itemIndex = xyItem.getItem(); double xDataValue = xyDataset.getXValue(seriesIndex, itemIndex); double yDataValue = xyDataset.getYValue(seriesIndex, itemIndex); Map<Integer, VideoEvent> veSegment = vcPlot.getChunk(xDataValue); int indexKey = 0; if (vcPlot.isDataItemPoint(xDataValue, yDataValue)) { if (veSegment != null) { for (int key : veSegment.keySet()) { // String value="Chunk "+(key+1)+" at // "+String.format("%.2f", // veSegment.get(key).getDLTimeStamp())+"S"; chunkInfo.put(key, veSegment.get(key)); // chunkInfo.add(value); } indexKey = (int) veSegment.keySet().toArray()[0]; } launchSliderDialog(indexKey); } else if (vcPlot.getBufferTimePlot().isDataItemStallPoint(xDataValue, yDataValue) != null) { VideoEvent segmentToPlay = vcPlot.getBufferTimePlot().isDataItemStallPoint(xDataValue, yDataValue); veSegment = vcPlot.getSegmentToPlayLocation(segmentToPlay); if (veSegment != null) { for (int key : veSegment.keySet()) { chunkInfo.put(key, veSegment.get(key)); } indexKey = (int) veSegment.keySet().toArray()[0]; } launchSliderDialog(indexKey); } } } }