List of usage examples for org.jfree.chart.plot XYPlot setRangeGridlinePaint
public void setRangeGridlinePaint(Paint paint)
From source file:jchrest.gui.VisualSearchPane.java
private ChartPanel createPanel() { XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(_trainingTimes);/*from www .j av a 2s. c om*/ JFreeChart chart = ChartFactory.createXYLineChart("Plot of network size vs. number of training patterns", "Number of training patterns", "Network size", dataset, org.jfree.chart.plot.PlotOrientation.VERTICAL, true, true, false); XYPlot plot = (XYPlot) chart.getPlot(); 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); XYItemRenderer r = plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); renderer.setDrawSeriesLineAsPath(true); } return new ChartPanel(chart); }
From source file:jboost.visualization.HistogramFrame.java
private JFreeChart createRocChart(XYDataset dataset) { JFreeChart chart = ChartFactory.createXYLineChart("ROC", // chart title "False positive rate", // x axis label "True positive rate", // y axis label dataset, // data PlotOrientation.VERTICAL, false, // include // legend true, // tooltips false // urls );// ww w .j ava 2 s .c om chart.setAntiAlias(false); RenderingHints hints = new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED); chart.setRenderingHints(hints); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); lower_tprMarker = new ValueMarker(0.5); lower_tprMarker.setPaint(Color.blue); lower_fprMarker = new ValueMarker(0.5); lower_fprMarker.setPaint(Color.blue); plot.addRangeMarker(lower_tprMarker); plot.addDomainMarker(lower_fprMarker); upper_tprMarker = new ValueMarker(0.5); upper_tprMarker.setPaint(Color.red); upper_fprMarker = new ValueMarker(0.5); upper_fprMarker.setPaint(Color.red); plot.addRangeMarker(upper_tprMarker); plot.addDomainMarker(upper_fprMarker); return chart; }
From source file:desmoj.extensions.visualization2d.engine.modelGrafic.StatisticGrafic.java
/** * Build content for animationType StatisticGrafic.ANIMATION_Histogram * @return/*w w w . j a v a 2 s.co m*/ * @throws ModelException */ private JPanel buildHistogramPanel() throws ModelException { XIntervalSeriesCollection dataset = new XIntervalSeriesCollection(); dataset.addSeries(this.statistic.getHistogram()); this.chart = ChartFactory.createXYBarChart(null, "Observation", false, "Count", dataset, PlotOrientation.VERTICAL, false, true, false); this.chart.setBackgroundPaint(Grafic.COLOR_BACKGROUND); XYPlot plot = this.chart.getXYPlot(); plot.setBackgroundPaint(StatisticGrafic.DIAGRAM_BACKGROUND); plot.setDomainGridlinePaint(StatisticGrafic.DIAGRAM_GRID); plot.setRangeGridlinePaint(StatisticGrafic.DIAGRAM_GRID); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); ValueAxis rangeAxis = (ValueAxis) plot.getRangeAxis(); rangeAxis.setLabelFont(Grafic.FONT_DEFAULT); ValueAxis domainAxis = plot.getDomainAxis(); domainAxis.setLabelFont(Grafic.FONT_DEFAULT); domainAxis.setAutoRange(true); XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer(); renderer.setShadowVisible(false); renderer.setBarPainter(new StandardXYBarPainter()); renderer.setDrawBarOutline(true); renderer.setSeriesPaint(0, StatisticGrafic.DIAGRAM_FORGROUND); renderer.setSeriesOutlinePaint(0, StatisticGrafic.DIAGRAM_BORDER); renderer.setSeriesOutlineStroke(0, new BasicStroke(1.0f)); this.buildHistogramAxisFormat(plot, "Observations"); JPanel out = new ChartPanel(chart); out.setPreferredSize(new Dimension(350, 200)); return out; }
From source file:com.vgi.mafscaling.MafCompare.java
/** * Initialize the contents of the frame. *//* www. j a va2 s .c om*/ private void initialize() { try { ImageIcon tableImage = new ImageIcon(getClass().getResource("/table.jpg")); setTitle(Title); setIconImage(tableImage.getImage()); setBounds(100, 100, 621, 372); setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); setSize(Config.getCompWindowSize()); setLocation(Config.getCompWindowLocation()); setLocationRelativeTo(null); setVisible(false); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { Utils.clearTable(origMafTable); Utils.clearTable(newMafTable); Utils.clearTable(compMafTable); Config.setCompWindowSize(getSize()); Config.setCompWindowLocation(getLocation()); origMafData.clear(); newMafData.clear(); } }); JPanel dataPanel = new JPanel(); GridBagLayout gbl_dataPanel = new GridBagLayout(); gbl_dataPanel.columnWidths = new int[] { 0, 0, 0 }; gbl_dataPanel.rowHeights = new int[] { RowHeight, RowHeight, RowHeight, RowHeight, RowHeight, 0 }; gbl_dataPanel.columnWeights = new double[] { 0.0, 0.0, 0.0 }; gbl_dataPanel.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 }; dataPanel.setLayout(gbl_dataPanel); getContentPane().add(dataPanel); JLabel origLabel = new JLabel(origMaf); GridBagConstraints gbc_origLabel = new GridBagConstraints(); gbc_origLabel.anchor = GridBagConstraints.PAGE_START; gbc_origLabel.insets = new Insets(1, 1, 1, 5); gbc_origLabel.weightx = 0; gbc_origLabel.weighty = 0; gbc_origLabel.gridx = 0; gbc_origLabel.gridy = 0; gbc_origLabel.gridheight = 2; dataPanel.add(origLabel, gbc_origLabel); JLabel newLabel = new JLabel(newMaf); GridBagConstraints gbc_newLabel = new GridBagConstraints(); gbc_newLabel.anchor = GridBagConstraints.PAGE_START; gbc_newLabel.insets = new Insets(1, 1, 1, 5); gbc_newLabel.weightx = 0; gbc_newLabel.weighty = 0; gbc_newLabel.gridx = 0; gbc_newLabel.gridy = 2; gbc_newLabel.gridheight = 2; dataPanel.add(newLabel, gbc_newLabel); JLabel compLabel = new JLabel("Change"); GridBagConstraints gbc_compLabel = new GridBagConstraints(); gbc_compLabel.anchor = GridBagConstraints.PAGE_START; gbc_compLabel.insets = new Insets(1, 1, 1, 5); gbc_compLabel.weightx = 0; gbc_compLabel.weighty = 0; gbc_compLabel.gridx = 0; gbc_compLabel.gridy = 4; dataPanel.add(compLabel, gbc_compLabel); JLabel origVoltLabel = new JLabel("volt"); GridBagConstraints gbc_origVoltLabel = new GridBagConstraints(); gbc_origVoltLabel.anchor = GridBagConstraints.PAGE_START; gbc_origVoltLabel.insets = new Insets(1, 1, 1, 5); gbc_origVoltLabel.weightx = 0; gbc_origVoltLabel.weighty = 0; gbc_origVoltLabel.gridx = 1; gbc_origVoltLabel.gridy = 0; dataPanel.add(origVoltLabel, gbc_origVoltLabel); JLabel origGsLabel = new JLabel(" g/s"); GridBagConstraints gbc_origGsLabel = new GridBagConstraints(); gbc_origGsLabel.anchor = GridBagConstraints.PAGE_START; gbc_origGsLabel.insets = new Insets(1, 1, 1, 5); gbc_origGsLabel.weightx = 0; gbc_origGsLabel.weighty = 0; gbc_origGsLabel.gridx = 1; gbc_origGsLabel.gridy = 1; dataPanel.add(origGsLabel, gbc_origGsLabel); JLabel newVoltLabel = new JLabel("volt"); GridBagConstraints gbc_newVoltLabel = new GridBagConstraints(); gbc_newVoltLabel.anchor = GridBagConstraints.PAGE_START; gbc_newVoltLabel.insets = new Insets(1, 1, 1, 5); gbc_newVoltLabel.weightx = 0; gbc_newVoltLabel.weighty = 0; gbc_newVoltLabel.gridx = 1; gbc_newVoltLabel.gridy = 2; dataPanel.add(newVoltLabel, gbc_newVoltLabel); JLabel newGsLabel = new JLabel(" g/s"); GridBagConstraints gbc_newGsLabel = new GridBagConstraints(); gbc_newGsLabel.anchor = GridBagConstraints.PAGE_START; gbc_newGsLabel.insets = new Insets(1, 1, 1, 5); gbc_newGsLabel.weightx = 0; gbc_newGsLabel.weighty = 0; gbc_newGsLabel.gridx = 1; gbc_newGsLabel.gridy = 3; dataPanel.add(newGsLabel, gbc_newGsLabel); JLabel compPctLabel = new JLabel(" % "); GridBagConstraints gbc_compPctLabel = new GridBagConstraints(); gbc_compPctLabel.anchor = GridBagConstraints.PAGE_START; gbc_compPctLabel.insets = new Insets(1, 1, 1, 5); gbc_compPctLabel.weightx = 0; gbc_compPctLabel.weighty = 0; gbc_compPctLabel.gridx = 1; gbc_compPctLabel.gridy = 4; dataPanel.add(compPctLabel, gbc_compPctLabel); JPanel tablesPanel = new JPanel(); GridBagLayout gbl_tablesPanel = new GridBagLayout(); gbl_tablesPanel.columnWidths = new int[] { 0 }; gbl_tablesPanel.rowHeights = new int[] { 0, 0, 0 }; gbl_tablesPanel.columnWeights = new double[] { 0.0 }; gbl_tablesPanel.rowWeights = new double[] { 0.0, 0.0, 1.0 }; tablesPanel.setLayout(gbl_tablesPanel); JScrollPane mafScrollPane = new JScrollPane(tablesPanel); mafScrollPane.setMinimumSize(new Dimension(1600, 107)); mafScrollPane.getHorizontalScrollBar().setMaximumSize(new Dimension(20, 20)); mafScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER); mafScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); GridBagConstraints gbc_mafScrollPane = new GridBagConstraints(); gbc_mafScrollPane.weightx = 1.0; gbc_mafScrollPane.anchor = GridBagConstraints.PAGE_START; gbc_mafScrollPane.fill = GridBagConstraints.HORIZONTAL; gbc_mafScrollPane.gridx = 2; gbc_mafScrollPane.gridy = 0; gbc_mafScrollPane.gridheight = 5; dataPanel.add(mafScrollPane, gbc_mafScrollPane); origMafTable = new JTable(); origMafTable.setColumnSelectionAllowed(true); origMafTable.setCellSelectionEnabled(true); origMafTable.setBorder(new LineBorder(new Color(0, 0, 0))); origMafTable.setRowHeight(RowHeight); origMafTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); origMafTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); origMafTable.setModel(new DefaultTableModel(2, MafTableColumnCount)); origMafTable.setTableHeader(null); Utils.initializeTable(origMafTable, ColumnWidth); GridBagConstraints gbc_origMafTable = new GridBagConstraints(); gbc_origMafTable.anchor = GridBagConstraints.PAGE_START; gbc_origMafTable.insets = new Insets(0, 0, 0, 0); gbc_origMafTable.fill = GridBagConstraints.HORIZONTAL; gbc_origMafTable.weightx = 1.0; gbc_origMafTable.weighty = 0; gbc_origMafTable.gridx = 0; gbc_origMafTable.gridy = 0; tablesPanel.add(origMafTable, gbc_origMafTable); excelAdapter.addTable(origMafTable, false, false, false, false, true, false, true, false, true); newMafTable = new JTable(); newMafTable.setColumnSelectionAllowed(true); newMafTable.setCellSelectionEnabled(true); newMafTable.setBorder(new LineBorder(new Color(0, 0, 0))); newMafTable.setRowHeight(RowHeight); newMafTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); newMafTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); newMafTable.setModel(new DefaultTableModel(2, MafTableColumnCount)); newMafTable.setTableHeader(null); Utils.initializeTable(newMafTable, ColumnWidth); GridBagConstraints gbc_newMafTable = new GridBagConstraints(); gbc_newMafTable.anchor = GridBagConstraints.PAGE_START; gbc_newMafTable.insets = new Insets(0, 0, 0, 0); gbc_newMafTable.fill = GridBagConstraints.HORIZONTAL; gbc_newMafTable.weightx = 1.0; gbc_newMafTable.weighty = 0; gbc_newMafTable.gridx = 0; gbc_newMafTable.gridy = 1; tablesPanel.add(newMafTable, gbc_newMafTable); excelAdapter.addTable(newMafTable, false, false, false, false, false, false, false, false, true); compMafTable = new JTable(); compMafTable.setColumnSelectionAllowed(true); compMafTable.setCellSelectionEnabled(true); compMafTable.setBorder(new LineBorder(new Color(0, 0, 0))); compMafTable.setRowHeight(RowHeight); compMafTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); compMafTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); compMafTable.setModel(new DefaultTableModel(1, MafTableColumnCount)); compMafTable.setTableHeader(null); Utils.initializeTable(compMafTable, ColumnWidth); NumberFormatRenderer numericRenderer = new NumberFormatRenderer(); numericRenderer.setFormatter(new DecimalFormat("0.000")); compMafTable.setDefaultRenderer(Object.class, numericRenderer); GridBagConstraints gbc_compMafTable = new GridBagConstraints(); gbc_compMafTable.anchor = GridBagConstraints.PAGE_START; gbc_compMafTable.insets = new Insets(0, 0, 0, 0); gbc_compMafTable.fill = GridBagConstraints.HORIZONTAL; gbc_compMafTable.weightx = 1.0; gbc_compMafTable.weighty = 0; gbc_compMafTable.gridx = 0; gbc_compMafTable.gridy = 2; tablesPanel.add(compMafTable, gbc_compMafTable); compExcelAdapter.addTable(compMafTable, false, true, false, false, false, true, true, false, true); TableModelListener origTableListener = new TableModelListener() { public void tableChanged(TableModelEvent tme) { if (tme.getType() == TableModelEvent.UPDATE) { int colCount = origMafTable.getColumnCount(); Utils.ensureColumnCount(colCount, newMafTable); Utils.ensureColumnCount(colCount, compMafTable); origMafData.clear(); String origY, origX, newY; for (int i = 0; i < colCount; ++i) { origY = origMafTable.getValueAt(1, i).toString(); if (Pattern.matches(Utils.fpRegex, origY)) { origX = origMafTable.getValueAt(0, i).toString(); if (Pattern.matches(Utils.fpRegex, origX)) origMafData.add(Double.valueOf(origX), Double.valueOf(origY), false); newY = newMafTable.getValueAt(1, i).toString(); if (Pattern.matches(Utils.fpRegex, newY)) compMafTable.setValueAt( ((Double.valueOf(newY) / Double.valueOf(origY)) - 1.0) * 100.0, 0, i); } else break; } origMafData.fireSeriesChanged(); } } }; TableModelListener newTableListener = new TableModelListener() { public void tableChanged(TableModelEvent tme) { if (tme.getType() == TableModelEvent.UPDATE) { int colCount = newMafTable.getColumnCount(); Utils.ensureColumnCount(colCount, origMafTable); Utils.ensureColumnCount(colCount, compMafTable); newMafData.clear(); String newY, newX, origY; for (int i = 0; i < colCount; ++i) { newY = newMafTable.getValueAt(1, i).toString(); if (Pattern.matches(Utils.fpRegex, newY)) { newX = newMafTable.getValueAt(0, i).toString(); if (Pattern.matches(Utils.fpRegex, newX)) newMafData.add(Double.valueOf(newX), Double.valueOf(newY), false); origY = origMafTable.getValueAt(1, i).toString(); if (Pattern.matches(Utils.fpRegex, origY)) compMafTable.setValueAt( ((Double.valueOf(newY) / Double.valueOf(origY)) - 1.0) * 100.0, 0, i); } else break; } newMafData.fireSeriesChanged(); } } }; origMafTable.getModel().addTableModelListener(origTableListener); newMafTable.getModel().addTableModelListener(newTableListener); Action action = new AbstractAction() { private static final long serialVersionUID = 8148393537657380215L; public void actionPerformed(ActionEvent e) { TableCellListener tcl = (TableCellListener) e.getSource(); if (Pattern.matches(Utils.fpRegex, compMafTable.getValueAt(0, tcl.getColumn()).toString())) { if (Pattern.matches(Utils.fpRegex, origMafTable.getValueAt(1, tcl.getColumn()).toString())) { double corr = Double.valueOf(compMafTable.getValueAt(0, tcl.getColumn()).toString()) / 100.0 + 1.0; newMafTable.setValueAt( Double.valueOf(origMafTable.getValueAt(1, tcl.getColumn()).toString()) * corr, 1, tcl.getColumn()); } } else compMafTable.setValueAt(tcl.getOldValue(), 0, tcl.getColumn()); } }; setCompMafCellListener(new TableCellListener(compMafTable, action)); // CHART JFreeChart chart = ChartFactory.createXYLineChart(null, null, null, null, PlotOrientation.VERTICAL, false, true, false); chart.setBorderVisible(true); chartPanel = new ChartPanel(chart, true, true, true, true, true); chartPanel.setAutoscrolls(true); GridBagConstraints gbl_chartPanel = new GridBagConstraints(); gbl_chartPanel.anchor = GridBagConstraints.PAGE_START; gbl_chartPanel.fill = GridBagConstraints.BOTH; gbl_chartPanel.insets = new Insets(1, 1, 1, 1); gbl_chartPanel.weightx = 1.0; gbl_chartPanel.weighty = 1.0; gbl_chartPanel.gridx = 0; gbl_chartPanel.gridy = 5; gbl_chartPanel.gridheight = 1; gbl_chartPanel.gridwidth = 3; dataPanel.add(chartPanel, gbl_chartPanel); XYSplineRenderer lineRenderer = new XYSplineRenderer(3); lineRenderer.setUseFillPaint(true); lineRenderer.setBaseToolTipGenerator( new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new DecimalFormat("0.00"), new DecimalFormat("0.00"))); Stroke stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, null, 0.0f); lineRenderer.setSeriesStroke(0, stroke); lineRenderer.setSeriesStroke(1, stroke); lineRenderer.setSeriesPaint(0, new Color(201, 0, 0)); lineRenderer.setSeriesPaint(1, new Color(0, 0, 255)); lineRenderer.setSeriesShape(0, ShapeUtilities.createDiamond((float) 2.5)); lineRenderer.setSeriesShape(1, ShapeUtilities.createDownTriangle((float) 2.5)); lineRenderer.setLegendItemLabelGenerator(new StandardXYSeriesLabelGenerator() { private static final long serialVersionUID = -4045338273187150888L; public String generateLabel(XYDataset dataset, int series) { XYSeries xys = ((XYSeriesCollection) dataset).getSeries(series); return xys.getDescription(); } }); NumberAxis mafvDomain = new NumberAxis(XAxisName); mafvDomain.setAutoRangeIncludesZero(false); mafvDomain.setAutoRange(true); mafvDomain.setAutoRangeStickyZero(false); NumberAxis mafgsRange = new NumberAxis(YAxisName); mafgsRange.setAutoRangeIncludesZero(false); mafgsRange.setAutoRange(true); mafgsRange.setAutoRangeStickyZero(false); XYSeriesCollection lineDataset = new XYSeriesCollection(); origMafData.setDescription(origMaf); newMafData.setDescription(newMaf); lineDataset.addSeries(origMafData); lineDataset.addSeries(newMafData); XYPlot plot = chart.getXYPlot(); plot.setRangePannable(true); plot.setDomainPannable(true); plot.setDomainGridlinePaint(Color.DARK_GRAY); plot.setRangeGridlinePaint(Color.DARK_GRAY); plot.setBackgroundPaint(new Color(224, 224, 224)); plot.setDataset(0, lineDataset); plot.setRenderer(0, lineRenderer); plot.setDomainAxis(0, mafvDomain); plot.setRangeAxis(0, mafgsRange); plot.mapDatasetToDomainAxis(0, 0); plot.mapDatasetToRangeAxis(0, 0); LegendTitle legend = new LegendTitle(plot.getRenderer()); legend.setItemFont(new Font("Arial", 0, 10)); legend.setPosition(RectangleEdge.TOP); chart.addLegend(legend); } catch (Exception e) { logger.error(e); } }
From source file:adams.flow.sink.JFreeChartPlot.java
/** * Displays the token (the panel and dialog have already been created at * this stage)./* www . ja v a 2 s .co m*/ * * @param token the token to display */ @Override protected void display(Token token) { SpreadSheet sheet; Dataset dataset; Shape shape; XYPlot plot; sheet = (SpreadSheet) token.getPayload(); dataset = m_Dataset.generate(sheet); m_JFreeChart = m_Chart.generate(dataset); m_JFreeChart.getPlot().setBackgroundPaint(Color.WHITE); if (m_JFreeChart.getPlot() instanceof XYPlot) { plot = (XYPlot) m_JFreeChart.getPlot(); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.GRAY); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.GRAY); plot.getRenderer().setSeriesPaint(0, m_PlotColor); if (plot.getSeriesCount() > 1) plot.getRenderer().setSeriesPaint(1, m_DiagonalColor); shape = m_Shape.generate(); if (shape != null) plot.getRenderer().setSeriesShape(0, shape); } m_PlotPanel = new ChartPanel(m_JFreeChart); m_Panel.removeAll(); m_Panel.add(m_PlotPanel, BorderLayout.CENTER); }
From source file:com.itemanalysis.jmetrik.swing.GraphPanel.java
/** * This method should be called after a chart dataset is updated. It * will iterate over all XYDatasets and provide the line color and lineStyle. * If it is called before a chart has a dataset, it will not have an effect. * * @param plot//from w w w . jav a2s. com */ public void setXYPlotRenderer(XYPlot plot) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); int n = plot.getSeriesCount(); for (int i = 0; i < n; i++) { Stroke stroke = new BasicStroke(lineWidth, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 10.0f, getLineStyle(i), 0.0f); renderer.setSeriesStroke(i, stroke); renderer.setSeriesPaint(i, getPaintColor(i)); } renderer.setLegendLine(new Line2D.Double(0, 5, 40, 5)); renderer.setBaseShapesFilled(false); renderer.setBaseShapesVisible(showMarkers); renderer.setDrawSeriesLineAsPath(true); plot.setBackgroundPaint(Color.WHITE); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRenderer(renderer); }
From source file:ucar.unidata.idv.control.chart.ChartHolder.java
/** * apply props/*from w ww .j a v a 2 s .c o m*/ */ protected void applyPlotProperties() { if (plot == null) { return; } if (dataAreaColor != null) { plot.setBackgroundPaint(dataAreaColor); } if (backgroundColor != null) { chart.setBackgroundPaint(backgroundColor); } if ((backgroundColor != null) && (chartPanel != null)) { chartPanel.setBackground(backgroundColor); } if (showTitle) { chart.setTitle(getName()); } else { chart.setTitle((String) null); } if (plot instanceof XYPlot) { final XYPlot p = (XYPlot) plot; p.setDomainGridlinesVisible(domainLineState.getVisible()); p.setRangeGridlinesVisible(rangeLineState.getVisible()); p.setDomainGridlinePaint(domainLineState.getColor()); p.setRangeGridlinePaint(rangeLineState.getColor()); p.setDomainGridlineStroke(domainLineState.getStroke()); p.setRangeGridlineStroke(rangeLineState.getStroke()); if (p.getDomainAxis() instanceof DateAxis && dateFormat != null) { final DateAxis ax = (DateAxis) p.getDomainAxis(); final TimeZone tz = getChartManager().getControl().getIdv().getPreferenceManager() .getDefaultTimeZone(); final DateFormat df = new SimpleDateFormat(dateFormat); df.setTimeZone(tz); ax.setDateFormatOverride(df); } } }
From source file:asl.util.PlotMaker.java
public void plotSpecAmp(double freq[], double[] amp, double[] phase, String plotString) { // plotTitle = "2012074.IU_ANMO.00-BHZ " + plotString final String plotTitle = String.format("%04d%03d.%s.%s %s", date.get(Calendar.YEAR), date.get(Calendar.DAY_OF_YEAR), station, channel, plotString); // plot filename = "2012074.IU_ANMO.00-BHZ" + plotString + ".png" final String pngName = String.format("%s/%04d%03d.%s.%s.%s.png", outputDir, date.get(Calendar.YEAR), date.get(Calendar.DAY_OF_YEAR), station, channel, plotString); File outputFile = new File(pngName); // Check that we will be able to output the file without problems and if not --> return if (!checkFileOut(outputFile)) { System.out.format("== plotSpecAmp: request to output plot=[%s] but we are unable to create it " + " --> skip plot\n", pngName); return;/* www. ja v a2s . c o m*/ } final XYSeries series1 = new XYSeries("Amplitude"); final XYSeries series2 = new XYSeries("Phase"); double maxdB = 0.; for (int k = 0; k < freq.length; k++) { double dB = 20. * Math.log10(amp[k]); series1.add(freq[k], dB); series2.add(freq[k], phase[k]); if (dB > maxdB) { maxdB = dB; } } //final XYItemRenderer renderer = new StandardXYItemRenderer(); final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); Rectangle rectangle = new Rectangle(3, 3); renderer.setSeriesShape(0, rectangle); //renderer.setSeriesShapesVisible(0, true); renderer.setSeriesShapesVisible(0, false); renderer.setSeriesLinesVisible(0, true); renderer.setSeriesShape(1, rectangle); renderer.setSeriesShapesVisible(1, true); renderer.setSeriesLinesVisible(1, false); Paint[] paints = new Paint[] { Color.red, Color.blue }; renderer.setSeriesPaint(0, paints[0]); //renderer.setSeriesPaint(1, paints[1]); final XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(); renderer2.setSeriesPaint(0, paints[1]); renderer2.setSeriesShapesVisible(0, false); renderer2.setSeriesLinesVisible(0, true); // Stroke is part of Java Swing ... //renderer2.setBaseStroke( new Stroke( ... ) ); double ymax; if (maxdB < 10) { ymax = 10.; } else { ymax = maxdB + 2; ; } final NumberAxis verticalAxis = new NumberAxis("Spec Amp (dB)"); verticalAxis.setRange(new Range(-40, ymax)); verticalAxis.setTickUnit(new NumberTickUnit(5)); //final LogarithmicAxis verticalAxis = new LogarithmicAxis("Amplitude Response"); //verticalAxis.setRange( new Range(0.01 , 10) ); final LogarithmicAxis horizontalAxis = new LogarithmicAxis("Frequency (Hz)"); //horizontalAxis.setRange( new Range(0.0001 , 100.5) ); horizontalAxis.setRange(new Range(0.00009, 110)); final XYSeriesCollection seriesCollection = new XYSeriesCollection(); seriesCollection.addSeries(series1); final XYPlot xyplot = new XYPlot((XYDataset) seriesCollection, null, verticalAxis, renderer); //final XYPlot xyplot = new XYPlot((XYDataset)seriesCollection, horizontalAxis, verticalAxis, renderer); xyplot.setDomainGridlinesVisible(true); xyplot.setRangeGridlinesVisible(true); xyplot.setRangeGridlinePaint(Color.black); xyplot.setDomainGridlinePaint(Color.black); final NumberAxis phaseAxis = new NumberAxis("Phase (Deg)"); phaseAxis.setRange(new Range(-180, 180)); phaseAxis.setTickUnit(new NumberTickUnit(30)); final XYSeriesCollection seriesCollection2 = new XYSeriesCollection(); seriesCollection2.addSeries(series2); final XYPlot xyplot2 = new XYPlot((XYDataset) seriesCollection2, null, phaseAxis, renderer2); //CombinedXYPlot combinedPlot = new CombinedXYPlot( horizontalAxis, CombinedXYPlot.VERTICAL ); CombinedDomainXYPlot combinedPlot = new CombinedDomainXYPlot(horizontalAxis); combinedPlot.add(xyplot, 1); combinedPlot.add(xyplot2, 1); combinedPlot.setGap(15.); //final JFreeChart chart = new JFreeChart(xyplot); final JFreeChart chart = new JFreeChart(combinedPlot); chart.setTitle(new TextTitle(plotTitle)); // Here we need to see if test dir exists and create it if necessary ... try { //ChartUtilities.saveChartAsJPEG(new File("chart.jpg"), chart, 500, 300); //ChartUtilities.saveChartAsPNG(outputFile, chart, 500, 300); ChartUtilities.saveChartAsPNG(outputFile, chart, 1000, 800); } catch (IOException e) { System.err.println("Problem occurred creating chart."); } }
From source file:csds60analyzer.csds60analyzerGUI.java
public BufferedImage creaImagen() { BufferedImage imagen = null;// w ww.j av a 2s . c om try { SAXBuilder builder = new SAXBuilder(false); Document doc = null; TimeSeriesCollection datos = new TimeSeriesCollection(); if (fichero != null) { doc = builder.build(fichero); Element raiz = doc.getRootElement(); List<Element> dias = raiz.getChildren("dia"); Iterator<Element> diasIT = dias.iterator(); TimeSeries desayunoAntes = new TimeSeries("Desayuno antes"); TimeSeries desayunoDespues = new TimeSeries("Desayuno despus"); TimeSeries almuerzoAntes = new TimeSeries("Almuerzo antes"); TimeSeries almuerzoDespues = new TimeSeries("Almuerzo despus"); TimeSeries cenaAntes = new TimeSeries("Cena antes"); TimeSeries cenaDespues = new TimeSeries("Cena despus"); pdesayuno = 0; pdesant = 0; pdesdes = 0; palmuerzo = 0; palmant = 0; palmdes = 0; pcena = 0; pcenant = 0; pcendes = 0; contdesant = 0; contdesdes = 0; contalmant = 0; contalmdes = 0; contcenant = 0; contcendes = 0; while (diasIT.hasNext()) { Element diaActual = diasIT.next(); Integer fechaActual = Integer.parseInt(diaActual.getChildText("fecha").substring(0, 10)); Calendar fad = GregorianCalendar.getInstance(); fad.setTimeInMillis(fechaActual.longValue() * 1000); int dia = fad.get(Calendar.DAY_OF_MONTH); int mes = fad.get(Calendar.MONTH) + 1; int ano = fad.get(Calendar.YEAR); if (diaActual.getChildren().toString().contains("desayunoantes")) { int desayunoAntesActual = Integer.parseInt(diaActual.getChildText("desayunoantes")); desayunoAntes.add(new Day(dia, mes, ano), desayunoAntesActual); pdesant = pdesant + desayunoAntesActual; contdesant++; } if (diaActual.getChildren().toString().contains("desayunodespues")) { int desayunoDespuesActual = Integer.parseInt(diaActual.getChildText("desayunodespues")); desayunoDespues.add(new Day(dia, mes, ano), desayunoDespuesActual); pdesdes = pdesdes + desayunoDespuesActual; contdesdes++; } if (diaActual.getChildren().toString().contains("almuerzoantes")) { int almuerzoAntesActual = Integer.parseInt(diaActual.getChildText("almuerzoantes")); almuerzoAntes.add(new Day(dia, mes, ano), almuerzoAntesActual); palmant = palmant + almuerzoAntesActual; contalmant++; } if (diaActual.getChildren().toString().contains("almuerzodespues")) { int almuerzoDespuesActual = Integer.parseInt(diaActual.getChildText("almuerzodespues")); almuerzoDespues.add(new Day(dia, mes, ano), almuerzoDespuesActual); palmdes = palmdes + almuerzoDespuesActual; contalmdes++; } if (diaActual.getChildren().toString().contains("cenaantes")) { int cenaAntesActual = Integer.parseInt(diaActual.getChildText("cenaantes")); cenaAntes.add(new Day(dia, mes, ano), cenaAntesActual); pcenant = pcenant + cenaAntesActual; contcenant++; } if (diaActual.getChildren().toString().contains("cenadespues")) { int cenaDespuesActual = Integer.parseInt(diaActual.getChildText("cenadespues")); cenaDespues.add(new Day(dia, mes, ano), cenaDespuesActual); pcendes = pcendes + cenaDespuesActual; contcendes++; } } //controlar la division por cero if ((contdesant + contdesdes) > 0) pdesayuno = (pdesant + pdesdes) / (contdesant + contdesdes); if (contdesant > 0) pdesant = pdesant / contdesant; if (contdesdes > 0) pdesdes = pdesdes / contdesdes; if ((contalmant + contalmdes) > 0) palmuerzo = (palmant + palmdes) / (contalmant + contalmdes); if (contalmant > 0) palmant = palmant / contalmant; if (contalmdes > 0) palmdes = palmdes / contalmdes; if ((contcenant + contcendes) > 0) pcena = (pcenant + pcendes) / (contcenant + contcendes); if (contcenant > 0) pcenant = pcenant / contcenant; if (contcendes > 0) pcendes = pcendes / contcendes; datos.addSeries(desayunoAntes); datos.addSeries(desayunoDespues); datos.addSeries(almuerzoAntes); datos.addSeries(almuerzoDespues); datos.addSeries(cenaAntes); datos.addSeries(cenaDespues); } JFreeChart graficaJfree = ChartFactory.createTimeSeriesChart("Anlisis", " ", "Glucosa (mg)", datos, true, true, false); XYPlot plot = (XYPlot) graficaJfree.getPlot(); plot.setBackgroundPaint(Color.getHSBColor(0f, 0f, .88f)); plot.setDomainGridlinePaint(Color.getHSBColor(0f, 0f, .35f)); plot.setDomainTickBandPaint(Color.getHSBColor(0f, 0f, .93f)); plot.setOutlinePaint(Color.getHSBColor(0f, 0f, 0.35f)); plot.setRangeGridlinePaint(Color.getHSBColor(0f, 0f, 0.35f)); XYLineAndShapeRenderer plot2 = (XYLineAndShapeRenderer) plot.getRenderer(); if (!CBdesayunoantes.getState()) plot2.setSeriesLinesVisible(0, false); plot2.setSeriesPaint(0, Color.getHSBColor(.3f, 1f, .5f)); //plot2.setSeriesStroke(0,new BasicStroke(2.0f,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND,1.0f)); if (!CBdesayunodespues.getState()) plot2.setSeriesLinesVisible(1, false); plot2.setSeriesPaint(1, Color.getHSBColor(.2f, 1f, .9f)); if (!CBalmuerzoantes.getState()) plot2.setSeriesLinesVisible(2, false); plot2.setSeriesPaint(2, Color.getHSBColor(.0f, 1f, .6f)); if (!CBalmuerzodespues.getState()) plot2.setSeriesLinesVisible(3, false); plot2.setSeriesPaint(3, Color.getHSBColor(.0f, 1f, .9f)); if (!CBcenaantes.getState()) plot2.setSeriesLinesVisible(4, false); plot2.setSeriesPaint(4, Color.getHSBColor(.6f, 1f, .4f)); if (!CBcenadespues.getState()) plot2.setSeriesLinesVisible(5, false); plot2.setSeriesPaint(5, Color.getHSBColor(.6f, 1f, 1f)); imagen = graficaJfree.createBufferedImage(800, 600); } catch (Exception e) { e.printStackTrace(); } return imagen; }