List of usage examples for org.jfree.chart JFreeChart setBackgroundPaint
public void setBackgroundPaint(Paint paint)
From source file:com.waitwha.nessus.trendanalyzer.gui.TimeChartPanel.java
/** * Constructor// w w w . jav a 2 s . c o m * * @param title String title of the chart. * @param xaxisLabel String x-axis label of the chart. * @param yaxisLabel String y-axis label of the chart (time). * @param dataset XYDataset to use within the chart. */ public TimeChartPanel(String title, String xaxisLabel, String yaxisLabel, XYDataset dataset) { super(new BorderLayout()); JFreeChart chart = ChartFactory.createTimeSeriesChart(title, xaxisLabel, yaxisLabel, dataset, true, // create legend? true, // generate tooltips? false // generate URLs? ); chart.setBackgroundPaint(Color.white); 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); } DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("yyyy-MM-dd HH:mm")); ChartPanel panel = new ChartPanel(chart); panel.setMouseWheelEnabled(true); this.add(panel, BorderLayout.CENTER); this.validate(); }
From source file:ambit.ui.data.AmbitResultViewer.java
public void propertyChange(PropertyChangeEvent e) { result = e.getNewValue();/*from ww w .j av a 2 s . com*/ System.out.println(e.getPropertyName()); if (result == null) { image = null; return; } if (result instanceof FingerprintProfile) { String[] seriesNames = new String[] { ((FingerprintProfile) result).toString() }; FingerprintProfile fp = (FingerprintProfile) result; String[] categoryNames = new String[fp.getLength()]; DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (int i = 0; i < fp.getLength(); i++) { dataset.addValue(fp.getBitFrequency(i), seriesNames[0], new Integer(i)); } JFreeChart chart = ChartFactory.createBarChart3D("Consensus fingerprint", "Bits", "Frequency", dataset, PlotOrientation.VERTICAL, true, false, false); chart.setBackgroundPaint(Color.white); chart.setAntiAlias(true); image = chart.createBufferedImage(450, 200); chart = null; } if (result instanceof SimilarityMatrix) { image = ((SimilarityMatrix) result).toImage(); } if (image == null) label.setIcon(null); else label.setIcon(new ImageIcon(image)); }
From source file:net.pickapack.chart.LinePlotFrame.java
/** * Create a line plot frame.//from w ww. j a va 2 s . com * * @param linePlot the line plot * @param width the width * @param height the height */ public LinePlotFrame(LinePlot linePlot, int width, int height) { super(linePlot.getTitle()); this.linePlot = linePlot; this.numSubPlots = linePlot.getSubLinePlots().size(); CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new DateAxis("Time")); this.dataSets = new ArrayList<TimeSeriesCollection>(); this.dataSinks = new ArrayList<Map<SubLinePlotLine, Function<Double>>>(); for (SubLinePlot subLinePlot : linePlot.getSubLinePlots()) { TimeSeriesCollection dataSetsPerSubPlot = new TimeSeriesCollection(); this.dataSets.add(dataSetsPerSubPlot); HashMap<SubLinePlotLine, Function<Double>> dataSinksPerSubPlot = new HashMap<SubLinePlotLine, Function<Double>>(); this.dataSinks.add(dataSinksPerSubPlot); for (SubLinePlotLine subLinePlotLine : subLinePlot.getLines()) { TimeSeries timeSeries = new TimeSeries(subLinePlotLine.getTitle()); dataSetsPerSubPlot.addSeries(timeSeries); dataSinksPerSubPlot.put(subLinePlotLine, subLinePlotLine.getGetValueCallback()); } NumberAxis rangeAxis = new NumberAxis(subLinePlot.getTitleY()); rangeAxis.setAutoRangeIncludesZero(false); XYPlot subplot = new XYPlot(dataSetsPerSubPlot, null, rangeAxis, new StandardXYItemRenderer()); subplot.setBackgroundPaint(Color.lightGray); subplot.setDomainGridlinePaint(Color.white); subplot.setRangeGridlinePaint(Color.white); plot.add(subplot); } JFreeChart chart = new JFreeChart(linePlot.getTitle(), plot); chart.setBorderPaint(Color.black); chart.setBorderVisible(true); chart.setBackgroundPaint(Color.white); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); ValueAxis axis = plot.getDomainAxis(); axis.setAutoRange(true); axis.setFixedAutoRange(3600000.0); JPanel content = new JPanel(new BorderLayout()); ChartPanel chartPanel = new ChartPanel(chart); content.add(chartPanel); chartPanel.setPreferredSize(new java.awt.Dimension(width, height)); chartPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); setContentPane(content); DataSink dataSink = new DataSink(); new Thread(dataSink).start(); }
From source file:sernet.gs.ui.rcp.main.bsi.views.chart.SchichtenBarChart.java
protected JFreeChart createBarChart(Object dataset) { final float plotForegroundAlpha = 0.6f; JFreeChart chart = ChartFactory.createBarChart3D(null, Messages.SchichtenBarChart_1, Messages.SchichtenBarChart_2, (CategoryDataset) dataset, PlotOrientation.HORIZONTAL, false, true, false);//from www .j ava2s .c o m chart.setBackgroundPaint(Color.white); chart.getPlot().setForegroundAlpha(plotForegroundAlpha); chart.setBackgroundPaint(Color.white); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.STANDARD); return chart; }
From source file:edu.ucla.stat.SOCR.chart.demo.XYBarChartDemo2.java
protected JFreeChart createLegendChart(JFreeChart origchart) { JFreeChart legendChart = new JFreeChart("", null, new HiddenPlot(), false); legendChart.setBackgroundPaint(Color.white); XYPlot plot = (XYPlot) origchart.getPlot(); LegendTitle legendTitle = new LegendTitle(plot, new ColumnArrangement(HorizontalAlignment.LEFT, VerticalAlignment.CENTER, 0, 0), new ColumnArrangement(HorizontalAlignment.LEFT, VerticalAlignment.CENTER, 0, 0)); legendChart.addLegend(legendTitle);//from w w w. jav a2s . com return legendChart; }
From source file:org.jfree.chart.demo.PieChart3DDemo2.java
/** * Creates a new demo.//ww w .j a v a 2s. c o m * * @param title the frame title. */ public PieChart3DDemo2(final String title) { super(title); // create a dataset... final DefaultPieDataset data = new DefaultPieDataset(); data.setValue("Java", new Double(43.2)); data.setValue("Visual Basic", new Double(10.0)); data.setValue("C/C++", new Double(17.5)); data.setValue("PHP", new Double(32.5)); data.setValue("Perl", new Double(12.5)); // create the chart... final JFreeChart chart = ChartFactory.createPieChart3D("Pie Chart 3D Demo 2", // chart title data, // data true, // include legend true, false); chart.setBackgroundPaint(Color.yellow); final PiePlot3D plot = (PiePlot3D) chart.getPlot(); plot.setStartAngle(270); plot.setDirection(Rotation.ANTICLOCKWISE); plot.setForegroundAlpha(0.60f); plot.setInteriorGap(0.33); // add the chart to a panel... final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(chartPanel); final Rotator rotator = new Rotator(plot); rotator.start(); }
From source file:sernet.gs.ui.rcp.main.bsi.views.chart.MaturityBarChart.java
protected JFreeChart createBarChart(Object dataset) { final float plotForegroundAlpha = 0.6f; final int axisUpperBound = 9; JFreeChart chart = ChartFactory.createBarChart3D(null, Messages.MaturityBarChart_1, Messages.MaturityBarChart_2, (CategoryDataset) dataset, PlotOrientation.HORIZONTAL, false, true, false);/*from w ww . j a v a 2s .co m*/ chart.setBackgroundPaint(Color.white); chart.getPlot().setForegroundAlpha(plotForegroundAlpha); chart.setBackgroundPaint(Color.white); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.getRenderer().setSeriesPaint(0, ChartColor.LIGHT_BLUE); plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.STANDARD); NumberAxis axis = (NumberAxis) plot.getRangeAxis(); axis.setUpperBound(axisUpperBound); return chart; }
From source file:org.jfree.chart.demo.DifferenceChartDemo.java
/** * Creates a chart.//from w ww .j a v a 2 s. c o m * * @param dataset the dataset. * * @return The chart. */ private JFreeChart createChart(final XYDataset dataset) { final JFreeChart chart = ChartFactory.createTimeSeriesChart("Difference Chart Demo", "Time", "Value", dataset, true, // legend true, // tool tips false // URLs ); chart.setBackgroundPaint(Color.white); final XYPlot plot = chart.getXYPlot(); plot.setRenderer(new XYDifferenceRenderer(Color.green, Color.red, false)); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); final ValueAxis domainAxis = new DateAxis("Time"); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); plot.setDomainAxis(domainAxis); plot.setForegroundAlpha(0.5f); return chart; }
From source file:slash.navigation.converter.gui.elevationview.ElevationView.java
private JFreeChart createChart(XYDataset dataset) { JFreeChart chart = ChartFactory.createXYAreaChart(null, getBundle().getString("distance-axis"), getBundle().getString("elevation-axis"), dataset, PlotOrientation.VERTICAL, false, true, false); chart.setBackgroundPaint(new JPanel().getBackground()); return chart; }
From source file:com.polivoto.vistas.acciones.Datos.java
private JFreeChart createChartBar(CategoryDataset dataset) { JFreeChart chart = ChartFactory.createBarChart("Votacion", "Opciones", "Total de votos", dataset, PlotOrientation.VERTICAL, true, true, true); try {//from w w w . j a v a2 s.co m chart.addSubtitle(new TextTitle(ac.getPreguntas().getJSONObject(pox).getString("pregunta"))); chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.white)); CategoryPlot plot = chart.getCategoryPlot(); org.jfree.chart.axis.CategoryAxis axis = plot.getDomainAxis(); axis.setCategoryLabelPositions( CategoryLabelPositions.createUpRotationLabelPositions(0.39269908169872414D)); // final CategoryItemRenderer itemRenderer = new CustomRenderer( // new Paint[] {Color.green, Color.red, Color.blue, Color.yellow, Color.magenta, Color.cyan, Color.pink, Color.lightGray} // ); //// itemRenderer.setBaseItemLabelsVisible(true); //// BarRenderer barRenderer = (BarRenderer)itemRenderer; //// barRenderer.setItemMargin(0.2D); //// plot.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, new java.awt.Color(147, 60, 45))); //// // StandardCategoryToolTipGenerator toolTipGenerator = new StandardCategoryToolTipGenerator("{0}: {2} %", new DecimalFormat("0")); // // // plot.setNoDataMessage("SIN DATOS!"); // // //// renderer.setLabelGenerator(new StandardCategoryLabelGenerator()); // itemRenderer.setItemLabelsVisible(true); // final ItemLabelPosition p = new ItemLabelPosition( // ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, 45.0 // ); // itemRenderer.setPositiveItemLabelPosition(p); // plot.setRenderer(itemRenderer); // change the margin at the top of the range axis... final ValueAxis rangeAxis = plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setLowerMargin(0.15); rangeAxis.setUpperMargin(0.15); } catch (JSONException ex) { Logger.getLogger(Datos.class.getName()).log(Level.SEVERE, null, ex); } return chart; }