List of usage examples for org.jfree.chart ChartFactory createXYLineChart
public static JFreeChart createXYLineChart(String title, String xAxisLabel, String yAxisLabel, XYDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls)
From source file:com.anji.floatingeye.FloatingEyeDisplay.java
private void init(Java2DSurface surface, FloatingEye anEye) { eye = anEye;/*from w w w .ja va2s.c o m*/ // this frame has 3 sections - status, surface canvas, and eye canvas addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { setVisible(false); dispose(); } }); GridLayout mainLayout = new GridLayout(2, 1); mainLayout.setHgap(10); mainLayout.setVgap(10); getContentPane().setLayout(mainLayout); GridLayout topPanelLayout = new GridLayout(2, 1); topPanelLayout.setHgap(10); topPanelLayout.setVgap(10); Panel topPanel = new Panel(topPanelLayout); GridLayout bottomPanelLayout = new GridLayout(1, 2); bottomPanelLayout.setHgap(10); bottomPanelLayout.setVgap(10); Panel bottomPanel = new Panel(bottomPanelLayout); // 1 - status area statusArea = new TextArea("", 1, 1, TextArea.SCROLLBARS_VERTICAL_ONLY); statusArea.setEditable(false); statusArea.setFont(new Font("Dialog", Font.PLAIN, 10)); statusArea.setSize(new Dimension(IMG_WIDTH * 2, IMG_HEIGHT / 2)); // 2 - affinity history chart XYSeriesCollection seriesCollection = new XYSeriesCollection(affinitySeries); JFreeChart chart = ChartFactory.createXYLineChart("affinity history", "step", "affinity", seriesCollection, PlotOrientation.VERTICAL, false, false, false); ValueAxis rangeAxis = chart.getXYPlot().getRangeAxis(); rangeAxis.setAutoRange(false); rangeAxis.setRange(0d, 1d); ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new Dimension(IMG_WIDTH * 2, IMG_HEIGHT / 2)); // 3 - surface canvas surfaceCanvas = new SurfaceCanvas(surface, eye, IMG_WIDTH, IMG_HEIGHT); surfaceCanvas.setBackground(Color.WHITE); // 4 - eye canvas eyeCanvas = new EyeCanvas(eye, IMG_WIDTH, IMG_HEIGHT); eyeCanvas.setBackground(Color.WHITE); topPanel.add(statusArea); topPanel.add(chartPanel); bottomPanel.add(surfaceCanvas); bottomPanel.add(eyeCanvas); getContentPane().add(topPanel); getContentPane().add(bottomPanel); pack(); }
From source file:umontreal.iro.lecuyer.charts.MultipleDatasetChart.java
/** * Initializes a new <TT>MultipleDatasetChart</TT> instance. * <TT>title</TT> sets a title, <TT>XLabel</TT> is a short description of * the <SPAN CLASS="MATH"><I>x</I></SPAN>-axis, and <TT>YLabel</TT> is a short description of the <SPAN CLASS="MATH"><I>y</I></SPAN>-axis. * /*from w w w.j ava 2s . c om*/ * @param title chart title. * * @param XLabel Label on <SPAN CLASS="MATH"><I>x</I></SPAN>-axis. * * @param YLabel Label on <SPAN CLASS="MATH"><I>y</I></SPAN>-axis. * */ public MultipleDatasetChart(String title, String XLabel, String YLabel) { // create the chart... chart = ChartFactory.createXYLineChart(title, // chart title XLabel, // x axis label YLabel, // y axis label null, // data PlotOrientation.VERTICAL, true, // include legend true, // tool tips false // urls ); datasetList = new ArrayList<SSJXYSeriesCollection>(); //Initialize axis variables XAxis = new Axis((NumberAxis) ((XYPlot) chart.getPlot()).getDomainAxis(), Axis.ORIENTATION_HORIZONTAL); YAxis = new Axis((NumberAxis) ((XYPlot) chart.getPlot()).getRangeAxis(), Axis.ORIENTATION_VERTICAL); }
From source file:org.interpss.chart.dist.LoadScheduleChart.java
public void createChart() { final JFreeChart chart = ChartFactory.createXYLineChart(plotTitle, xLabel, voltYLabel, createDataSet(voltDataAry, voltDataLabel), PlotOrientation.VERTICAL, true, false, false); final XYPlot plot = (XYPlot) chart.getPlot(); final XYStepRenderer renderer = new XYStepRenderer(); renderer.setToolTipGenerator(new StandardXYToolTipGenerator()); plot.setRenderer(renderer);/*from w w w. j a v a 2 s .c om*/ //NumberAxis axis_x = (NumberAxis) plot.getDomainAxis(); //axis_x.setRangeAboutValue(12.0, 24.0); final NumberAxis axisLeft = (NumberAxis) plot.getRangeAxis(); axisLeft.setAutoRangeIncludesZero(false); axisLeft.setAutoRangeMinimumSize(1.0); final NumberAxis axisRight = new NumberAxis(pqYLabel); axisRight.setAutoRangeIncludesZero(false); axisRight.setAutoRangeMinimumSize(1.0); plot.setRangeAxis(1, axisRight); final XYItemRenderer v_renderer = plot.getRenderer(0); v_renderer.setSeriesPaint(0, vColor); plot.setDataset(1, createDataSet(pDataAry, pDataLabel)); plot.mapDatasetToRangeAxis(1, 1); final XYStepRenderer p_renderer = new XYStepRenderer(); p_renderer.setSeriesPaint(0, pColor); p_renderer.setBaseShapesVisible(false); plot.setRenderer(1, p_renderer); plot.setDataset(2, createDataSet(qDataAry, qDataLabel)); plot.mapDatasetToRangeAxis(2, 1); final XYStepRenderer q_renderer = new XYStepRenderer(); q_renderer.setSeriesPaint(0, qColor); q_renderer.setBaseShapesVisible(false); plot.setRenderer(2, q_renderer); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(Chart_Width, Chart_Height)); setContentPane(chartPanel); }
From source file:JDAC.JDAC.java
public JDAC() { setTitle("JDAC"); ImageIcon img = new ImageIcon("logo.png"); setIconImage(img.getImage());/*from w w w.j a v a2 s. co m*/ //setLayout(new FlowLayout()); mDataset = createDataset("A"); mChart = ChartFactory.createXYLineChart("Preview", "Time (ms)", "Value", mDataset, PlotOrientation.VERTICAL, false, true, false); mLastChart = ChartFactory.createXYLineChart("Last n values", "Time (ms)", "Value", createLastDataset("B"), PlotOrientation.VERTICAL, false, true, false); mChart.getXYPlot().getDomainAxis().setLowerMargin(0); mChart.getXYPlot().getDomainAxis().setUpperMargin(0); mLastChart.getXYPlot().getDomainAxis().setLowerMargin(0); mLastChart.getXYPlot().getDomainAxis().setUpperMargin(0); ChartPanel chartPanel = new ChartPanel(mChart); ChartPanel chartLastPanel = new ChartPanel(mLastChart); //chartPanel.setPreferredSize( new java.awt.Dimension( 560 , 367 ) ); XYPlot plot = mChart.getXYPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesPaint(0, Color.GREEN); renderer.setSeriesStroke(0, new BasicStroke(1.0f)); plot.setRenderer(renderer); XYPlot lastPlot = mLastChart.getXYPlot(); XYLineAndShapeRenderer lastRenderer = new XYLineAndShapeRenderer(); lastRenderer.setSeriesPaint(0, Color.RED); lastRenderer.setSeriesStroke(0, new BasicStroke(1.0f)); lastPlot.setRenderer(lastRenderer); resetChartButton = new JButton("Reset"); resetChartButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { resetChart(); } }); mMenuBar = new JMenuBar(); JMenu fileMenu = new JMenu("File"); JMenu sensorMenu = new JMenu("Sensor"); JMenu deviceMenu = new JMenu("Device"); portSubMenu = new JMenu("Port"); JMenu helpMenu = new JMenu("Help"); serialStatusLabel = new JLabel("Disconnected"); statusLabel = new JLabel("Ready"); clearStatus = new LabelClear(statusLabel); clearStatus.resetTime(); connectButton = new JMenuItem("Connect"); disconnectButton = new JMenuItem("Disconnect"); startButton = new JButton("Start"); stopButton = new JButton("Stop"); scanButton = new JMenuItem("Refresh port list"); exportCSVButton = new JMenuItem("Export data to CSV"); exportCSVButton.setAccelerator(KeyStroke.getKeyStroke("control S")); exportCSVButton.setMnemonic(KeyEvent.VK_S); exportPNGButton = new JMenuItem("Export chart to PNG"); JPanel optionsPanel = new JPanel(new BorderLayout()); JMenuItem exitItem = new JMenuItem("Exit"); exitItem.setAccelerator(KeyStroke.getKeyStroke("control X")); exitItem.setMnemonic(KeyEvent.VK_X); JMenuItem aboutItem = new JMenuItem("About"); JMenuItem helpItem = new JMenuItem("Help"); JMenuItem quickStartItem = new JMenuItem("Quick start"); lastSpinner = new JSpinner(new SpinnerNumberModel(10, 0, 1000, 1)); ActionListener mSensorListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { setSensor(e.getActionCommand()); } }; ButtonGroup sensorGroup = new ButtonGroup(); JRadioButtonMenuItem tmpRadioButton = new JRadioButtonMenuItem("Temperature"); sensorGroup.add(tmpRadioButton); sensorMenu.add(tmpRadioButton); tmpRadioButton.addActionListener(mSensorListener); tmpRadioButton = new JRadioButtonMenuItem("Distance"); sensorGroup.add(tmpRadioButton); sensorMenu.add(tmpRadioButton); tmpRadioButton.addActionListener(mSensorListener); tmpRadioButton = new JRadioButtonMenuItem("Voltage"); sensorGroup.add(tmpRadioButton); sensorMenu.add(tmpRadioButton); tmpRadioButton.addActionListener(mSensorListener); tmpRadioButton = new JRadioButtonMenuItem("Generic"); tmpRadioButton.setSelected(true); setSensor("Generic"); sensorGroup.add(tmpRadioButton); sensorMenu.add(tmpRadioButton); tmpRadioButton.addActionListener(mSensorListener); connectButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (selectedPortName == null) { setStatus("No port selected"); return; } connect(selectedPortName); } }); disconnectButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { serialStatusLabel.setText("Disconnecting..."); if (serialPort == null) { serialStatusLabel.setText("Disconnected"); serialConnected = false; return; } stopCollect(); disconnect(); } }); scanButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { searchForPorts(); } }); exportCSVButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { saveData(); } }); exportPNGButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { exportPNG(); } }); startButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { startCollect(); } }); stopButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { stopCollect(); } }); lastSpinner.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { numLastValues = (Integer) lastSpinner.getValue(); updateLastTitle(); } }); updateLastTitle(); exitItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.exit(0); } }); helpItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { new HelpFrame(); } }); aboutItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { new AboutFrame(); } }); quickStartItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { new StartFrame(); } }); fileMenu.add(exportCSVButton); fileMenu.add(exportPNGButton); fileMenu.addSeparator(); fileMenu.add(exitItem); deviceMenu.add(connectButton); deviceMenu.add(disconnectButton); deviceMenu.addSeparator(); deviceMenu.add(portSubMenu); deviceMenu.add(scanButton); helpMenu.add(quickStartItem); helpMenu.add(helpItem); helpMenu.add(aboutItem); mMenuBar.add(fileMenu); mMenuBar.add(sensorMenu); mMenuBar.add(deviceMenu); mMenuBar.add(helpMenu); JPanel controlsPanel = new JPanel(); controlsPanel.add(startButton); controlsPanel.add(stopButton); controlsPanel.add(resetChartButton); optionsPanel.add(controlsPanel, BorderLayout.LINE_START); JPanel lastPanel = new JPanel(new FlowLayout()); lastPanel.add(new JLabel("Shown values: ")); lastPanel.add(lastSpinner); optionsPanel.add(lastPanel); JPanel serialPanel = new JPanel(new FlowLayout()); serialPanel.add(serialStatusLabel); optionsPanel.add(serialPanel, BorderLayout.LINE_END); add(optionsPanel, BorderLayout.PAGE_START); JPanel mainPanel = new JPanel(new GridLayout(0, 2)); mainPanel.add(chartPanel); mainPanel.add(chartLastPanel); add(mainPanel); add(statusLabel, BorderLayout.PAGE_END); setJMenuBar(mMenuBar); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { dispose(); } }); setSize(800, 800); pack(); new StartFrame(); //center on screen Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize(); int x = (int) ((dimension.getWidth() - getWidth()) / 2); int y = (int) ((dimension.getHeight() - getHeight()) / 2); setLocation(x, y); setVisible(true); }
From source file:gov.nih.nci.caintegrator.plots.kaplanmeier.JFreeChartIKMPlottermpl.java
public JFreeChart createKMPlot(Collection<GroupCoordinates> groupsToBePlotted, String title, String xAxisLabel, String yAxisLabel) {/*from w w w . jav a 2 s . c o m*/ List<KMPlotPointSeriesSet> kmPlotSets = new ArrayList<KMPlotPointSeriesSet>( convertToKaplanMeierPlotPointSeriesSet(groupsToBePlotted)); XYSeriesCollection finalDataCollection = new XYSeriesCollection(); /* Repackage all the datasets to go into the XYSeriesCollection */ for (KMPlotPointSeriesSet dataSet : kmPlotSets) { finalDataCollection.addSeries(dataSet.getCensorPlotPoints()); finalDataCollection.addSeries(dataSet.getProbabilityPlotPoints()); } JFreeChart chart = ChartFactory.createXYLineChart("", xAxisLabel, yAxisLabel, finalDataCollection, PlotOrientation.VERTICAL, true, //legend true, //tooltips false//urls ); XYPlot plot = (XYPlot) chart.getPlot(); /* * Ideally the actual Renderer settings should have been created * at the survivalLength of iterating KaplanMeierPlotPointSeriesSets, adding them to the actual * Data Set that is going to be going into the Chart plotter. But you have no idea how * they are going to be sitting in the Plot dataset so there is no guarantee that setting the * renderer based on a supposed index will actually work. In fact */ XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); for (int i = 0; i < finalDataCollection.getSeriesCount(); i++) { KMPlotPointSeries kmSeries = (KMPlotPointSeries) finalDataCollection.getSeries(i); if (kmSeries.getType() == KMPlotPointSeries.SeriesType.CENSOR) { renderer.setSeriesLinesVisible(i, false); renderer.setSeriesShapesVisible(i, true); renderer.setSeriesShape(i, getCensorShape()); } else if (kmSeries.getType() == KMPlotPointSeries.SeriesType.PROBABILITY) { renderer.setSeriesLinesVisible(i, true); renderer.setSeriesShapesVisible(i, false); } else { //don't show this set as it is not a known type renderer.setSeriesLinesVisible(i, false); renderer.setSeriesShapesVisible(i, false); } renderer.setSeriesPaint(i, getKMSetColor(kmPlotSets, kmSeries.getKey(), kmSeries.getType()), true); } renderer.setToolTipGenerator(new StandardXYToolTipGenerator()); renderer.setDefaultEntityRadius(6); plot.setRenderer(renderer); /* change the auto tick unit selection to integer units only... */ NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits()); /* OPTIONAL CUSTOMISATION COMPLETED. */ rangeAxis.setAutoRange(true); rangeAxis.setRange(0.0, 1.0); /* set Title and Legend */ chart.setTitle(title); createLegend(chart, kmPlotSets); return chart; }
From source file:org.graphstream.algorithm.measure.ChartSeriesMeasure.java
public JFreeChart createChart(PlotParameters params) throws PlotException { JFreeChart chart;//from ww w. j a v a2 s . c o m XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(getXYSeries()); switch (params.type) { case LINE: chart = ChartFactory.createXYLineChart(params.title, params.xAxisLabel, params.yAxisLabel, dataset, params.orientation, params.showLegend, false, false); break; case BAR: chart = ChartFactory.createXYBarChart(params.title, params.xAxisLabel, false, params.yAxisLabel, dataset, params.orientation, params.showLegend, false, false); break; case SCATTER: chart = ChartFactory.createScatterPlot(params.title, params.xAxisLabel, params.yAxisLabel, dataset, params.orientation, params.showLegend, false, false); break; default: throw new PlotException("unsupported plot type"); } return chart; }
From source file:BaselinePlotGenerator.java
private JFreeChart createChart(String filename, NssBaseline nssBaseline) { XYSeries series = new XYSeries(""); float[] baselineValues = nssBaseline.getBaselineValues(); // plot subband values for (int i = 0; i < baselineValues.length; i++) { series.add(i, baselineValues[i]); }/*from www . ja va2 s.c om*/ // add a final point at the end with a zero Y value, // to force the y axis to display full scale series.add(baselineValues.length, 0.0); XYDataset data = new XYSeriesCollection(series); String title = "SonATA Baseline"; String xAxisLabel = "Subband"; String yAxisLabel = "Power"; JFreeChart chart = ChartFactory.createXYLineChart(title, xAxisLabel, yAxisLabel, data, PlotOrientation.VERTICAL, false, // legend true, // tooltips false // urls ); String filenameBase = new File(filename).getName(); String subTitle1 = filenameBase; chart.addSubtitle(new TextTitle(subTitle1)); DecimalFormat freqFormatter = new DecimalFormat("0000.000 MHz "); String freqString = freqFormatter.format(nssBaseline.getCenterFreqMhz()); DecimalFormat bandwidthFormatter = new DecimalFormat("0.00 MHz "); String bandwidthString = bandwidthFormatter.format(nssBaseline.getBandwidthMhz()); String subTitle2 = "Center Freq: " + freqString + " Bandwidth: " + bandwidthString; chart.addSubtitle(new TextTitle(subTitle2)); // move the data off of the axes // by extending the minimum axis value XYPlot plot = (XYPlot) ((JFreeChart) chart).getPlot(); double axisMarginPercent = 0.02; NumberAxis valueAxis = (NumberAxis) plot.getRangeAxis(); valueAxis.setLowerBound(-1.0 * valueAxis.getUpperBound() * axisMarginPercent); valueAxis = (NumberAxis) plot.getDomainAxis(); valueAxis.setLowerBound(-1.0 * valueAxis.getUpperBound() * axisMarginPercent); return chart; }
From source file:pwr.lab5.Window.java
public void showChart(Window win) { final JFreeChart chart = ChartFactory.createXYLineChart("DOM, SAX, StAX parsing time", // chart title "number of XML nodes", // x axis label "time [ms]", // y axis label win.dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls );/*from w w w . ja va2 s .co m*/ ChartFrame pane = new ChartFrame("ELO", chart); pane.pack(); pane.setVisible(true); }
From source file:com.choicemaker.cm.modelmaker.gui.panels.AsymmetricThresholdVsAccuracyPlotPanel.java
private JFreeChart buildPlot(XYSeries d, XYSeries m, String title, String xAxis) { XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(d);//from ww w . ja va 2 s . c o m dataset.addSeries(m); final String yAxis = ChoiceMakerCoreMessages.m .formatMessage("train.gui.modelmaker.panel.asymm.cm.accuracy"); final PlotOrientation orientation = PlotOrientation.VERTICAL; final boolean hasLegend = true; final boolean hasToolTips = true; final boolean hasURLs = true; JFreeChart chart = // ChartFactory.createLineXYChart( // title, // xAxis, // ChoiceMakerCoreMessages.m.formatMessage("train.gui.modelmaker.panel.asymm.cm.accuracy"), // dataset, // true, true, true); ChartFactory.createXYLineChart(title, xAxis, yAxis, dataset, orientation, hasLegend, hasToolTips, hasURLs); chart.setBackgroundPaint(getBackground()); return chart; }
From source file:org.jgrasstools.gears.utils.chart.Scatter.java
public JFreeChart getChart() { if (chart == null) { chart = ChartFactory.createXYLineChart(title, // chart title xLabel,/*from www . j a v a 2 s .c om*/ // domain axis label yLabel, // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips? false // URLs? ); XYPlot plot = (XYPlot) chart.getPlot(); if (xLog) { LogAxis xAxis = new LogAxis(""); xAxis.setBase(10); plot.setDomainAxis(xAxis); } if (yLog) { LogAxis yAxis = new LogAxis(""); yAxis.setBase(10); plot.setRangeAxis(yAxis); } ValueAxis rangeAxis = plot.getRangeAxis(); if (rangeAxis instanceof NumberAxis) { NumberAxis axis = (NumberAxis) rangeAxis; axis.setAutoRangeIncludesZero(false); } XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); double x = 1.5; double w = x * 2; renderer.setSeriesShape(0, new Ellipse2D.Double(-x, x, w, w)); setShapeLinesVisibility(plot); } return chart; }