List of usage examples for org.jfree.chart.plot XYPlot getRangeAxis
public ValueAxis getRangeAxis()
From source file:edu.ucla.stat.SOCR.chart.SuperIntervalXYChart.java
/** * Creates a chart.//from w w w . ja va 2s .c o m * * @param dataset the dataset. * * @return a chart. */ protected JFreeChart createChart(IntervalXYDataset dataset) { JFreeChart chart = ChartFactory.createXYBarChart(chartTitle, domainLabel, false, rangeLabel, dataset, PlotOrientation.VERTICAL, !legendPanelOn, true, false); // then customise it a little... // chart.addSubtitle(new TextTitle("Source: http://www.amnestyusa.org/abolish/listbyyear.do")); chart.setBackgroundPaint(Color.white); XYPlot plot = chart.getXYPlot(); plot.setRenderer(new ClusteredXYBarRenderer()); XYItemRenderer renderer = plot.getRenderer(); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator()); return chart; }
From source file:net.sf.mzmine.util.dialogs.AxesSetupDialog.java
/** * Constructor//from ww w . jav a 2s . c om */ public AxesSetupDialog(XYPlot plot) { // Make dialog modal super(MZmineCore.getDesktop().getMainWindow(), true); xAxis = plot.getDomainAxis(); yAxis = plot.getRangeAxis(); NumberFormat defaultFormatter = NumberFormat.getNumberInstance(); NumberFormat xAxisFormatter = defaultFormatter; if (xAxis instanceof NumberAxis) xAxisFormatter = ((NumberAxis) xAxis).getNumberFormatOverride(); NumberFormat yAxisFormatter = defaultFormatter; if (yAxis instanceof NumberAxis) yAxisFormatter = ((NumberAxis) yAxis).getNumberFormatOverride(); // Create labels and fields JLabel lblXTitle = new JLabel(xAxis.getLabel()); JLabel lblXAutoRange = new JLabel("Auto range"); JLabel lblXMin = new JLabel("Minimum"); JLabel lblXMax = new JLabel("Maximum"); JLabel lblXAutoTick = new JLabel("Auto tick size"); JLabel lblXTick = new JLabel("Tick size"); JLabel lblYTitle = new JLabel(yAxis.getLabel()); JLabel lblYAutoRange = new JLabel("Auto range"); JLabel lblYMin = new JLabel("Minimum"); JLabel lblYMax = new JLabel("Maximum"); JLabel lblYAutoTick = new JLabel("Auto tick size"); JLabel lblYTick = new JLabel("Tick size"); checkXAutoRange = new JCheckBox(); checkXAutoRange.addActionListener(this); checkXAutoTick = new JCheckBox(); checkXAutoTick.addActionListener(this); fieldXMin = new JFormattedTextField(xAxisFormatter); fieldXMax = new JFormattedTextField(xAxisFormatter); fieldXTick = new JFormattedTextField(xAxisFormatter); checkYAutoRange = new JCheckBox(); checkYAutoRange.addActionListener(this); checkYAutoTick = new JCheckBox(); checkYAutoTick.addActionListener(this); fieldYMin = new JFormattedTextField(yAxisFormatter); fieldYMax = new JFormattedTextField(yAxisFormatter); fieldYTick = new JFormattedTextField(yAxisFormatter); // Create a panel for labels and fields JPanel pnlLabelsAndFields = new JPanel(new GridLayout(0, 2)); pnlLabelsAndFields.add(lblXTitle); pnlLabelsAndFields.add(new JPanel()); pnlLabelsAndFields.add(lblXAutoRange); pnlLabelsAndFields.add(checkXAutoRange); pnlLabelsAndFields.add(lblXMin); pnlLabelsAndFields.add(fieldXMin); pnlLabelsAndFields.add(lblXMax); pnlLabelsAndFields.add(fieldXMax); if (xAxis instanceof NumberAxis) { pnlLabelsAndFields.add(lblXAutoTick); pnlLabelsAndFields.add(checkXAutoTick); pnlLabelsAndFields.add(lblXTick); pnlLabelsAndFields.add(fieldXTick); } // Empty row pnlLabelsAndFields.add(new JPanel()); pnlLabelsAndFields.add(new JPanel()); pnlLabelsAndFields.add(lblYTitle); pnlLabelsAndFields.add(new JPanel()); pnlLabelsAndFields.add(lblYAutoRange); pnlLabelsAndFields.add(checkYAutoRange); pnlLabelsAndFields.add(lblYMin); pnlLabelsAndFields.add(fieldYMin); pnlLabelsAndFields.add(lblYMax); pnlLabelsAndFields.add(fieldYMax); if (yAxis instanceof NumberAxis) { pnlLabelsAndFields.add(lblYAutoTick); pnlLabelsAndFields.add(checkYAutoTick); pnlLabelsAndFields.add(lblYTick); pnlLabelsAndFields.add(fieldYTick); } // Create buttons JPanel pnlButtons = new JPanel(); btnOK = new JButton("OK"); btnOK.addActionListener(this); btnApply = new JButton("Apply"); btnApply.addActionListener(this); btnCancel = new JButton("Cancel"); btnCancel.addActionListener(this); pnlButtons.add(btnOK); pnlButtons.add(btnApply); pnlButtons.add(btnCancel); // Put everything into a main panel JPanel pnlAll = new JPanel(new BorderLayout()); pnlAll.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); add(pnlAll); pnlAll.add(pnlLabelsAndFields, BorderLayout.CENTER); pnlAll.add(pnlButtons, BorderLayout.SOUTH); pack(); setTitle("Please set ranges for axes"); setResizable(false); setLocationRelativeTo(MZmineCore.getDesktop().getMainWindow()); getValuesToControls(); }
From source file:networkanalyzer.DynamicPing.java
public JFreeChart createChart(final XYDataset dataset) { final JFreeChart result = ChartFactory.createTimeSeriesChart("Ping Chart", //title "Time", //x-axis "Ping", //y-axis dataset, false, false, false); final XYPlot plot = result.getXYPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); ValueAxis xaxis = plot.getDomainAxis(); xaxis.setAutoRange(true);//from w w w . j a va2s. c o m xaxis.setFixedAutoRange(60000.0); xaxis.setVerticalTickLabels(true); ValueAxis yaxis = plot.getRangeAxis(); yaxis.setAutoRange(true); return result; }
From source file:c.depthchart.ViewerPanel.java
private void initChart() // create the dataset, chart, panel, and window { // create an empty data set series = new XYSeries("Depth Counts Histogram"); for (int i = 0; i <= CHART_MAX_DEPTH; i++) series.add(i, 0); // depth with a zero count XYSeriesCollection dataset = new XYSeriesCollection(series); // put the data into a chart JFreeChart chart = ChartFactory.createXYBarChart("Depth Histogram", "Depth (mm)", false, "Depth Count", dataset, PlotOrientation.VERTICAL, false, true, false); // legend, tooltips, urls // modify the chart axes XYPlot plot = (XYPlot) chart.getPlot(); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); // x-axis domainAxis.setVerticalTickLabels(true); domainAxis.setRange(0, CHART_MAX_DEPTH); domainAxis.setTickUnit(new NumberTickUnit(100)); ValueAxis rangeAxis = plot.getRangeAxis(); // y-axis rangeAxis.setRange(0, 15000); // a bit of a guess // add the chart to a panel ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new Dimension(1000, 500)); // add the panel to a window JFrame chartFrame = new JFrame("Depth Histogram"); chartFrame.setContentPane(chartPanel); chartFrame.pack();/*from www . ja va 2 s . co m*/ chartFrame.setVisible(true); }
From source file:charts.Chart.java
public static void MultipleLineChart(XYDataset[] datasets, String title, String x_axis_label, String y_axis_label, boolean showlegend, float maxvalue, float minvalue) { JFrame chartwindow = new JFrame(title); CombinedDomainXYPlot parent = new CombinedDomainXYPlot(new NumberAxis(x_axis_label)); for (int i = 0; i < datasets.length; i++) { XYItemRenderer renderer = new StandardXYItemRenderer(); renderer.setBaseSeriesVisibleInLegend(showlegend); XYPlot subplot = new XYPlot(datasets[i], null, new NumberAxis(y_axis_label), renderer); NumberAxis axis = (NumberAxis) subplot.getRangeAxis(); //axis.setTickLabelFont(new Font("SansSerif", Font.BOLD,12)); //axis.setLabelFont(new Font("SansSerif", Font.PLAIN,10)); axis.setAutoRangeIncludesZero(true); axis.setLabelFont(new Font("SansSerif", Font.BOLD, 12)); NumberAxis daxis = (NumberAxis) parent.getDomainAxis(); daxis.setLabelFont(new Font("SansSerif", Font.BOLD, 12)); parent.add(subplot, 1);// w ww. ja v a2 s .c om } JFreeChart jfreechart = new JFreeChart(title, parent); JPanel jpanel = new ChartPanel(jfreechart); jpanel.setPreferredSize(new Dimension(defaultwidth, defaultheight)); chartwindow.setContentPane(jpanel); chartwindow.pack(); RefineryUtilities.centerFrameOnScreen(chartwindow); chartwindow.setVisible(true); }
From source file:org.rioproject.examples.hospital.ui.PatientStatsPanel.java
private JFreeChart createTimeSeriesChart(TimeSeriesCollection dataSet, Color color) { JFreeChart chart = ChartFactory.createTimeSeriesChart("", "", "", dataSet, true, true, false); XYPlot plot = (XYPlot) chart.getPlot(); plot.getRenderer().setSeriesPaint(0, color); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); ValueAxis yAxis = plot.getRangeAxis(); yAxis.setRange(0, 150);// w w w.ja v a 2s. com ValueAxis xAxis = plot.getDomainAxis(); xAxis.setAutoRange(true); xAxis.setFixedAutoRange(5 * MINUTE); return chart; }
From source file:org.limy.eclipse.qalab.task.DistanceGraphTask.java
/** * @param dataset //from w ww . j a v a 2 s . co m * @throws IOException * */ private void drawGraph(XYDataset dataset) throws IOException { JFreeChart chart = ChartFactory.createScatterPlot("Distance from the Main Sequence", "Instability", "Abstractness", dataset, PlotOrientation.VERTICAL, false, false, false); XYPlot plot = chart.getXYPlot(); plot.getRenderer().addAnnotation( new XYLineAnnotation(-0.1, 1.1, 1.1, -0.1, new BasicStroke(2), new Color(50, 220, 50)), Layer.BACKGROUND); plot.getRenderer().setShape(new Ellipse2D.Double(-4, -4, 8, 8)); plot.getRenderer().setPaint(new Color(0xec, 0x76, 0x37)); plot.getDomainAxis().setRangeWithMargins(0, 1); plot.getRangeAxis().setRangeWithMargins(0, 1); chart.getTitle().setPaint(Color.BLUE); plot.setDomainCrosshairVisible(true); plot.setDomainCrosshairPaint(Color.GRAY); plot.setRangeCrosshairVisible(true); plot.setRangeCrosshairPaint(Color.GRAY); LimyGraphUtils.writeImagePng(chart, out, 400, 380); }
From source file:playground.artemc.analysis.AnalysisControlerListener.java
private void writeGraph(String name, String yLabel, Map<Integer, Double> it2Double) { XYLineChart chart = new XYLineChart(name, "Iteration", yLabel); double[] xValues = new double[it2Double.size()]; double[] yValues = new double[it2Double.size()]; int counter = 0; for (Integer iteration : it2Double.keySet()) { xValues[counter] = iteration.doubleValue(); yValues[counter] = it2Double.get(iteration); counter++;// w ww. j ava 2s. co m } chart.addSeries(name, xValues, yValues); XYPlot plot = chart.getChart().getXYPlot(); NumberAxis axis = (NumberAxis) plot.getRangeAxis(); axis.setAutoRange(true); axis.setAutoRangeIncludesZero(false); String outputFile = this.scenario.getConfig().controler().getOutputDirectory() + "/" + name + ".png"; chart.saveAsPng(outputFile, 1000, 800); // File Export }
From source file:org.jax.maanova.plot.MaanovaChartPanel.java
/** * Convert the given point in java2d coordinates to chart coordinates. * @param java2DPoint the point to convert * @return the converted point//from w ww . ja v a 2s . c om * @throws ClassCastException the plot isn't an XYPlot */ public Point2D toChartPoint(Point2D java2DPoint) throws ClassCastException { XYPlot plot = this.getChart().getXYPlot(); Rectangle2D dataArea = this.chartRenderingInfo.getPlotInfo().getDataArea(); double graphX = plot.getDomainAxis().java2DToValue(java2DPoint.getX(), dataArea, plot.getDomainAxisEdge()); double graphY = plot.getRangeAxis().java2DToValue(java2DPoint.getY(), dataArea, plot.getRangeAxisEdge()); return new Point2D.Double(graphX, graphY); }
From source file:playground.artemc.analysis.AnalysisControlerListener.java
private void writeGraphSum(String name, String yLabel, Map<Integer, Double> it2Double1, Map<Integer, Double> it2Double2) { XYLineChart chart = new XYLineChart(name, "Iteration", yLabel); double[] xValues = new double[it2Double1.size()]; double[] yValues = new double[it2Double1.size()]; int counter = 0; for (Integer iteration : it2Double1.keySet()) { xValues[counter] = iteration.doubleValue(); yValues[counter] = (it2Double1.get(iteration)) + (it2Double2.get(iteration)); counter++;/* ww w . j a v a 2s .c o m*/ } chart.addSeries(name, xValues, yValues); XYPlot plot = chart.getChart().getXYPlot(); NumberAxis axis = (NumberAxis) plot.getRangeAxis(); axis.setAutoRange(true); axis.setAutoRangeIncludesZero(false); String outputFile = this.scenario.getConfig().controler().getOutputDirectory() + "/" + name + ".png"; chart.saveAsPng(outputFile, 1000, 800); // File Export }