List of usage examples for org.jfree.chart ChartPanel getPopupMenu
public JPopupMenu getPopupMenu()
From source file:net.sf.mzmine.chartbasics.graphicsexport.ChartExportUtil.java
/** * Add export dialog to popup menu of a chartpanel * /*from w w w .jav a 2 s . c om*/ * @param plotChartPanel */ public static void addExportDialogToMenu(final ChartPanel cp) { JMenuItem exportGraphics = new JMenuItem("Export graphics..."); exportGraphics.addActionListener(e -> GraphicsExportDialog.openDialog(cp.getChart())); // add to menu cp.getPopupMenu().add(exportGraphics); }
From source file:com.itemanalysis.jmetrik.graph.scatterplot.ScatterplotPanel.java
public void setGraph() { DefaultXYDataset dataset = new DefaultXYDataset(); PlotOrientation orientation = PlotOrientation.VERTICAL; try {/* w w w .ja v a2 s . com*/ chart = ChartFactory.createScatterPlot(title, // chart title xlabel, // x axis label ylabel, // y axis label dataset, // data orientation, showLegend, // include legend true, // tooltips false // urls ); if (subtitle != null && !"".equals(subtitle)) { TextTitle subtitle1 = new TextTitle(subtitle); chart.addSubtitle(subtitle1); } XYPlot plot = (XYPlot) chart.getPlot(); plot.setNoDataMessage("NO DATA"); plot.setDomainZeroBaselineVisible(false); plot.setRangeZeroBaselineVisible(false); plot.setBackgroundPaint(Color.WHITE); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); ChartPanel panel = new ChartPanel(chart); panel.getPopupMenu().addSeparator(); this.addJpgMenuItem(this, panel.getPopupMenu()); panel.setPreferredSize(new Dimension(width, height)); chart.setPadding(new RectangleInsets(20.0, 5.0, 20.0, 5.0)); this.setBackground(Color.WHITE); this.add(panel); } catch (IllegalArgumentException ex) { logger.fatal(ex.getMessage(), ex); this.firePropertyChange("error", "", "Error - Check log for details."); } }
From source file:com.itemanalysis.jmetrik.graph.histogram.HistogramPanel.java
public void setGraph() { HistogramChartDataset dataset = null; dataset = new HistogramChartDataset(); chart = HistogramChart.createHistogram(chartTitle, xlabel, //x-axis label ylabel, //y-axis label dataset, chartOrientation, hasGroupingVariable, //legend true, //tooltips false //urls );/*from ww w .j a v a 2 s .c om*/ if (chartSubtitle != null && !"".equals(chartSubtitle)) { TextTitle subtitle1 = new TextTitle(); chart.addSubtitle(subtitle1); } XYPlot plot = (XYPlot) chart.getPlot(); if (hasGroupingVariable) plot.setForegroundAlpha(0.80f); plot.setBackgroundPaint(Color.WHITE); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(true); renderer.setShadowVisible(false); //next two lines are temp setting for book //these two lines will create a histogram with white bars so it appears as just the bar outline // renderer.setBarPainter(new StandardXYBarPainter()); // renderer.setSeriesPaint(0, Color.white); ChartPanel panel = new ChartPanel(chart); panel.getPopupMenu().addSeparator(); this.addJpgMenuItem(this, panel.getPopupMenu()); panel.setPreferredSize(new Dimension(width, height)); // //temp setting for book // this.addLocalEPSMenuItem(this, panel.getPopupMenu(), chart);//remove this line for public release versions chart.setPadding(new RectangleInsets(20.0, 5.0, 20.0, 5.0)); this.setBackground(Color.WHITE); this.add(panel); }
From source file:com.itemanalysis.jmetrik.graph.barchart.BarChartPanel.java
public void setGraph() throws IllegalArgumentException { boolean hasGroupingVariable = false; if (command.getFreeOption("groupvar").hasValue()) { hasGroupingVariable = true;//from www .j a va 2s. c om } String name = command.getFreeOption("variable").getString(); String xLabel = name; DefaultCategoryDataset dataset = new DefaultCategoryDataset(); String yLabel = ""; if (command.getSelectOneOption("yaxis").isValueSelected("freq")) { yLabel = "Frequency"; } else { yLabel = "Percentage"; } if (command.getSelectOneOption("layout").isValueSelected("stacked")) { chart = ChartFactory.createStackedBarChart(command.getFreeOption("title").getString(), xLabel, yLabel, dataset, chartOrientation, hasGroupingVariable, //only show legend if has grouping variable true, false); CategoryPlot plot = (CategoryPlot) chart.getPlot(); StackedBarRenderer renderer = (StackedBarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); renderer.setBaseItemLabelsVisible(true); renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); } else if (command.getSelectOneOption("view").isValueSelected("3D")) { chart = ChartFactory.createBarChart3D(command.getFreeOption("title").getString(), xLabel, yLabel, dataset, chartOrientation, hasGroupingVariable, //only show legend if has grouping variable true, false); } else { chart = ChartFactory.createBarChart(command.getFreeOption("title").getString(), xLabel, yLabel, dataset, chartOrientation, hasGroupingVariable, //only show legend if has grouping variable true, false); } String sub = ""; if (command.getFreeOption("subtitle").getString() != null) { sub = command.getFreeOption("subtitle").getString(); } TextTitle subtitle1 = new TextTitle(sub); chart.addSubtitle(subtitle1); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setDomainGridlinesVisible(true); if (command.getSelectOneOption("layout").isValueSelected("layered")) { LayeredBarRenderer renderer = new LayeredBarRenderer(); // renderer.setDrawBarOutline(false); plot.setRenderer(renderer); plot.setRowRenderingOrder(SortOrder.DESCENDING); } chart.setPadding(new RectangleInsets(20.0, 5.0, 20.0, 5.0)); ChartPanel panel = new ChartPanel(chart); panel.getPopupMenu().addSeparator(); this.addJpgMenuItem(BarChartPanel.this, panel.getPopupMenu()); panel.setPreferredSize(new Dimension(width, height)); plot.setBackgroundPaint(Color.WHITE); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); // plot.setForegroundAlpha(0.80f); BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(true); renderer.setShadowVisible(false); this.setBackground(Color.WHITE); this.add(panel); }
From source file:com.itemanalysis.jmetrik.graph.nicc.NonparametricCurvePanel.java
private void createChart(String name, String title, String xLabel, String yLabel, double minScore, double maxScore) { XYSeriesCollection dataset = new XYSeriesCollection(); final JFreeChart chart = ChartFactory.createXYLineChart(title, // chart title xLabel, // x axis label yLabel, // y axis label dataset, // data chartOrientation, // chart orientation showLegend, // include legend true, // tooltips false // urls );// w w w. java 2 s. c o m if (showLegend) { LegendTitle chartTitle = chart.getLegend(); chartTitle.setPosition(legendPosition); } XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); // //can use this code to fix the number of tick marks on the y-axis // NumberFormat myFormatter = new DecimalFormat("#.0"); // NumberAxis yaxis = (NumberAxis)plot.getRangeAxis(); // yaxis.setTickUnit(new NumberTickUnit(.1, myFormatter)); ChartPanel panel = new ChartPanel(chart); panel.getPopupMenu().addSeparator(); panel.setPreferredSize(new Dimension(width, height)); // this.addLocalEPSMenuItem(this, panel.getPopupMenu(), chart);//remove this line for public release versions chart.setPadding(new RectangleInsets(20.0, 5.0, 20.0, 5.0)); charts.put(name, chart); JPanel subPanel = new JPanel();//additional panel needed to prevent gridlayout from stretching graph subPanel.add(panel); subPanel.setBackground(Color.WHITE); this.add(subPanel); }
From source file:com.itemanalysis.jmetrik.graph.itemmap.ItemMapPanel.java
public void setGraph() { HistogramChartDataset personDataset = null; HistogramChartDataset itemData = null; try {//from ww w . j a v a 2 s. c om //get titles String chartTitle = command.getFreeOption("title").getString(); String chartSubtitle = command.getFreeOption("subtitle").getString(); PlotOrientation itemMapOrientation = PlotOrientation.HORIZONTAL; //create common x-axis NumberAxis domainAxis = new NumberAxis(); domainAxis.setLabel("Logits"); //create histogram personDataset = new HistogramChartDataset(); ValueAxis rangeAxis = new NumberAxis("Person Density"); if (itemMapOrientation == PlotOrientation.HORIZONTAL) rangeAxis.setInverted(true); XYBarRenderer renderer = new XYBarRenderer(); renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); renderer.setURLGenerator(new StandardXYURLGenerator()); renderer.setDrawBarOutline(true); renderer.setShadowVisible(false); XYPlot personPlot = new XYPlot(personDataset, null, rangeAxis, renderer); personPlot.setOrientation(PlotOrientation.HORIZONTAL); //create scatterplot of item difficulty itemData = new HistogramChartDataset(); NumberAxis itemRangeAxis = new NumberAxis("Item Frequency"); if (itemMapOrientation == PlotOrientation.VERTICAL) { itemRangeAxis.setInverted(true); } XYBarRenderer itemRenderer = new XYBarRenderer(); itemRenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); itemRenderer.setURLGenerator(new StandardXYURLGenerator()); itemRenderer.setDrawBarOutline(true); itemRenderer.setShadowVisible(false); XYPlot itemPlot = new XYPlot(itemData, null, itemRangeAxis, itemRenderer); itemPlot.setOrientation(PlotOrientation.HORIZONTAL); //combine the two charts CombinedDomainXYPlot cplot = new CombinedDomainXYPlot(domainAxis); cplot.add(personPlot, 3); cplot.add(itemPlot, 2); cplot.setGap(8.0); cplot.setDomainGridlinePaint(Color.white); cplot.setDomainGridlinesVisible(true); cplot.setOrientation(itemMapOrientation); // //next four lines are temp setting for book // //these four lines will create a histogram with white bars so it appears as just the bar outline // renderer.setBarPainter(new StandardXYBarPainter()); // renderer.setSeriesPaint(0, Color.white); // itemRenderer.setBarPainter(new StandardXYBarPainter()); // itemRenderer.setSeriesPaint(0, Color.white); chart = new JFreeChart(chartTitle, JFreeChart.DEFAULT_TITLE_FONT, cplot, false); chart.setBackgroundPaint(Color.white); if (chartSubtitle != null && !"".equals(chartSubtitle)) { chart.addSubtitle(new TextTitle(chartSubtitle)); } ChartPanel panel = new ChartPanel(chart); panel.getPopupMenu().addSeparator(); this.addJpgMenuItem(this, panel.getPopupMenu()); panel.setPreferredSize(new Dimension(width, height)); // //temp setting for book // this.addLocalEPSMenuItem(this, panel.getPopupMenu(), chart);//remove this line for public release versions chart.setPadding(new RectangleInsets(20.0, 5.0, 20.0, 5.0)); this.setBackground(Color.WHITE); this.add(panel); } catch (IllegalArgumentException ex) { logger.fatal(ex.getMessage(), ex); this.firePropertyChange("error", "", "Error - Check log for details."); } }
From source file:com.itemanalysis.jmetrik.graph.irt.IrtPlotPanel.java
private void createChart(String name, String title, String xLabel, String yLabel, double minScore, double maxScore) { XYSeriesCollection dataset = new XYSeriesCollection(); JFreeChart chart = ChartFactory.createXYLineChart(title, // chart title xLabel, // x axis label yLabel, // y axis label dataset, // data chartOrientation, // chart orientation showLegend, // include legend true, // tooltips false // urls );/*from w w w . ja va 2s .c o m*/ // get a reference to the plot for further customisation... XYPlot plot = (XYPlot) chart.getPlot(); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setBaseShapesFilled(false); renderer.setDrawOutlines(true); plot.setBackgroundPaint(Color.WHITE); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.getDomainAxis().setRange(minScore, maxScore); ChartPanel panel = new ChartPanel(chart); panel.getPopupMenu().addSeparator(); panel.setPreferredSize(new Dimension(width, height)); // this.addLocalEPSMenuItem(this, panel.getPopupMenu(), chart);//remove this line for public release versions chart.setPadding(new RectangleInsets(20.0, 5.0, 20.0, 5.0)); charts.put(name, chart); JPanel subPanel = new JPanel();//additional panel needed to prevent gridlayout from stretching graph subPanel.add(panel); // this.addJpgMenuItem(subPanel, panel.getPopupMenu()); subPanel.setBackground(Color.WHITE); this.add(subPanel); }
From source file:com.itemanalysis.jmetrik.swing.GraphPanel.java
public void setLineChart(String title, String subtitle, String xlabel, String ylabel) { XYSeriesCollection dataset = new XYSeriesCollection(); chart = ChartFactory.createXYLineChart(title, // chart title xlabel, // x axis label ylabel, // y axis label dataset, // data chartOrientation, showLegend, // include legend true, // tooltips false // urls );/*ww w . ja v a2 s . c o m*/ if (showLegend) { LegendTitle chartTitle = chart.getLegend(); chartTitle.setPosition(legendPosition); } if (subtitle != null && !"".equals(subtitle)) { TextTitle subtitle1 = new TextTitle(subtitle); chart.addSubtitle(subtitle1); } XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); //can use this code to modify charts for book. DO NOT USE FOR NORMAL FUNCTIONING // NumberAxis yaxis = (NumberAxis)plot.getRangeAxis(); // yaxis.setTickUnit(new NumberTickUnit(.1)); ChartPanel panel = new ChartPanel(chart); panel.getPopupMenu().addSeparator(); this.addJpgMenuItem(this, panel.getPopupMenu()); // this.addEPSMenuItem(this, panel.getPopupMenu());//remove this line for public release versions panel.setPreferredSize(new Dimension(width, height)); chart.setPadding(new RectangleInsets(20.0, 5.0, 20.0, 5.0)); this.setBackground(Color.WHITE); this.add(panel); }
From source file:sturesy.voting.gui.VotingEvaluationPanelUI.java
/** * creates a new ChartPanel inside this UI * //from w w w . jav a2 s .c o m * @param categoryDataset * the Data * @param questionText * the questiontext to display above * @param background * background color * @param showAnswers * highlight correct answer in green? * @param correctAnswer * index of correct answer * @param showPercent * should it show percent values or absolute values? */ public void createNewChartPanel(CategoryDataset categoryDataset, String questionText, Color background, boolean showAnswers, List<Integer> correctAnswers, boolean showPercent) { JFreeChart chart = createChart(categoryDataset, questionText, background, showAnswers, correctAnswers, showPercent); ChartPanel chartPanel = new ChartPanel(chart); setNewChartPanel(chartPanel); String menuItemText = Localize .getString(showPercent ? "label.jfreechart.switch.absolute" : "label.jfreechart.switch.percent"); JMenuItem menuItem = new JMenuItem(menuItemText); chartPanel.getPopupMenu().addSeparator(); chartPanel.getPopupMenu().add(menuItem); menuItem.addActionListener(_menuItemActionListener); }
From source file:de.biomedical_imaging.ij.plot.HistogramPlotter.java
public HistogramPlotter(String title, String xlabel, double[][] data, int numberOfParticles, int meanTrackLength, IDatasetCreator datacreator) { super(title); this.title = title; this.xlabel = xlabel; this.numberOfParticles = numberOfParticles; this.meanTrackLength = meanTrackLength; IntervalXYDataset xydataset = datacreator.create(data); boolean isbarplot = (datacreator instanceof BarplotDataset); txt = new JLabel(); Font f = new Font("Verdana", Font.PLAIN, 12); txt.setFont(f);//ww w. j a v a 2s .co m JFreeChart chart = createChart(xydataset, isbarplot); ChartPanel chartPanel = new ChartPanel(chart); txt.setText(formatSettingsString()); main = new JPanel(); main.setPreferredSize(new java.awt.Dimension(500, 350)); main.add(chartPanel); main.add(txt); setContentPane(main); setLayout(new BoxLayout(main, BoxLayout.Y_AXIS)); pack(); setVisible(true); JMenuItem savebutton = ((JMenuItem) chartPanel.getPopupMenu().getComponent(3)); chartPanel.getPopupMenu().remove(3); // Remove Save button //ActionListener al = savebutton.getActionListeners()[0]; savebutton = new JMenuItem("Save as png"); //savebutton.removeActionListener(al); savebutton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub try { JFileChooser saveFile = new JFileChooser(); saveFile.setAcceptAllFileFilterUsed(false); saveFile.addChoosableFileFilter(new FileNameExtensionFilter("Images", "png")); int userSelection = saveFile.showSaveDialog(main); if (userSelection == JFileChooser.APPROVE_OPTION) { BufferedImage bi = ScreenImage.createImage(main); File fileToSave = saveFile.getSelectedFile(); String filename = fileToSave.getName(); int i = filename.lastIndexOf('.'); String suffix = filename.substring(i + 1); String path = fileToSave.getAbsolutePath(); if (!(suffix.equals("png"))) { path += ".png"; } ScreenImage.writeImage(bi, path); } } catch (IOException e) { // TODO Auto-generated catch block IJ.log("" + e.getMessage()); } } }); chartPanel.getPopupMenu().insert(savebutton, 3); }