List of usage examples for org.jfree.chart JFreeChart setBackgroundPaint
public void setBackgroundPaint(Paint paint)
From source file:com.wattzap.view.graphs.MMPGraph.java
public MMPGraph(XYSeries series) { super();//from ww w. j a va 2 s . com NumberAxis yAxis = new NumberAxis(userPrefs.messages.getString("poWtt")); yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); double maxY = series.getMaxY(); yAxis.setRange(0, maxY + 20); yAxis.setTickLabelPaint(Color.white); yAxis.setLabelPaint(Color.white); LogAxis xAxis = new LogAxis(userPrefs.messages.getString("time")); xAxis.setTickLabelPaint(Color.white); xAxis.setBase(4); xAxis.setAutoRange(false); xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); xAxis.setRange(1, series.getMaxX() + 500); xAxis.setNumberFormatOverride(new NumberFormat() { @Override public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos) { long millis = (long) number * 1000; if (millis >= 60000) { return new StringBuffer(String.format("%d m %d s", TimeUnit.MILLISECONDS.toMinutes((long) millis), TimeUnit.MILLISECONDS.toSeconds((long) millis) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes((long) millis)))); } else { return new StringBuffer(String.format("%d s", TimeUnit.MILLISECONDS.toSeconds((long) millis) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes((long) millis)))); } } @Override public StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition pos) { return new StringBuffer(String.format("%s", number)); } @Override public Number parse(String source, ParsePosition parsePosition) { return null; } }); XYPlot plot = new XYPlot(new XYSeriesCollection(series), xAxis, yAxis, new XYLineAndShapeRenderer(true, false)); JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, false); chart.setBackgroundPaint(Color.gray); plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.darkGray); /*plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinePaint(Color.lightGray);*/ ValueAxis domainAxis = plot.getDomainAxis(); domainAxis.setTickLabelPaint(Color.white); domainAxis.setLabelPaint(Color.white); chartPanel = new ChartPanel(chart); chartPanel.setSize(100, 800); chartPanel.setFillZoomRectangle(true); chartPanel.setMouseWheelEnabled(true); chartPanel.setBackground(Color.gray); setLayout(new BorderLayout()); add(chartPanel, BorderLayout.CENTER); setBackground(Color.black); chartPanel.revalidate(); setVisible(true); }
From source file:org.jfree.chart.demo.XYBarChartDemo4.java
/** * Constructs the demo application.// w w w. j a v a 2 s .c o m * * @param title the frame title. */ public XYBarChartDemo4(final String title) { super(title); final IntervalXYDataset dataset = createDataset(); final JFreeChart chart = ChartFactory.createXYBarChart(title, "X", false, "Y", dataset, PlotOrientation.VERTICAL, true, false, false); // then customise it a little... chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 1000, 0, Color.blue)); final XYPlot plot = (XYPlot) chart.getPlot(); final NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // add the chart to a panel... final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 300)); setContentPane(chartPanel); }
From source file:org.sonar.api.charts.AbstractChart.java
private void improveChart(JFreeChart jfrechart, ChartParameters params) { Color background = Color .decode("#" + params.getValue(ChartParameters.PARAM_BACKGROUND_COLOR, "FFFFFF", false)); jfrechart.setBackgroundPaint(background); jfrechart.setBorderVisible(false);/*from w w w .ja va 2s . co m*/ jfrechart.setAntiAlias(true); jfrechart.setTextAntiAlias(true); jfrechart.removeLegend(); }
From source file:WeeklyReport.Sections.Bookings.java
private JFreeChart bookingsByPODChart() { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); Map<Double, Map<String, String>> map = new CargoQuoteType().bookingsByPOD(); map.entrySet().stream().forEach((mapEntry) -> { Map<String, String> m1 = mapEntry.getValue(); m1.entrySet().stream().forEach((pair) -> { dataset.setValue(mapEntry.getKey(), pair.getKey(), pair.getValue()); });//from w w w. java2s. c o m }); JFreeChart barChart = ChartFactory.createBarChart3D("Bookings by POD", "Company", "Cubic Meters", dataset, PlotOrientation.HORIZONTAL, true, true, false); barChart.setBackgroundPaint(Color.WHITE); CategoryPlot categoryPlot = barChart.getCategoryPlot(); CategoryAxis domainAxis = categoryPlot.getDomainAxis(); BarRenderer br = (BarRenderer) categoryPlot.getRenderer(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45); categoryPlot.setBackgroundPaint(Color.WHITE); categoryPlot.setRangeGridlinePaint(Color.BLACK); return barChart; }
From source file:org.jfree.chart.demo.XYBarChartDemo.java
/** * Constructs the demo application.//from w ww . ja v a 2 s . co m * * @param title the frame title. */ public XYBarChartDemo(final String title) { super(title); final TimeSeriesCollection data = DemoDatasetFactory.createTimeSeriesCollection1(); data.setDomainIsPointsInTime(false); final JFreeChart chart = ChartFactory.createXYBarChart(title, "X", true, "Y", data, PlotOrientation.VERTICAL, true, false, false); // then customise it a little... chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 1000, 0, Color.blue)); final XYItemRenderer renderer = chart.getXYPlot().getRenderer(); final StandardXYToolTipGenerator generator = new StandardXYToolTipGenerator("{1} = {2}", new SimpleDateFormat("yyyy"), new DecimalFormat("0.00")); renderer.setToolTipGenerator(generator); final XYPlot plot = chart.getXYPlot(); final DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); // add the chart to a panel... final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 300)); setContentPane(chartPanel); }
From source file:org.mili.jmibs.jfree.JFreeChartBarIterationIntervalBenchmarkSuiteResultRenderer.java
private JFreeChart createChart(String title, CategoryDataset dataset) { JFreeChart chart = ChartFactory.createBarChart(title, "Benchmark (Iteration/Interval)", "Time in ns", dataset, PlotOrientation.HORIZONTAL, true, true, false); chart.setBackgroundPaint(Color.white); CategoryPlot plot = (CategoryPlot) chart.getPlot(); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false);//from w w w . j a v a2s. c o m GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64)); GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0)); GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0)); renderer.setSeriesPaint(0, gp0); renderer.setSeriesPaint(1, gp1); renderer.setSeriesPaint(2, gp2); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); return chart; }
From source file:ws.moor.bt.gui.charts.DownloadRatePerPeer.java
private JFreeChart createChart() { JFreeChart chart = ChartFactory.createBarChart("Top 20 Download Rates", "Remote IP", "KB/s", createDataset(), PlotOrientation.VERTICAL, false, false, false); chart.setBackgroundPaint(Color.white); CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 2.0)); return chart; }
From source file:org.wsm.database.tools.editor.ui.GraphPane.java
public GraphPane() { GridBagLayout gbl = new GridBagLayout(); this.setLayout(gbl); this.qesi = new QueryExecStatsInfo(); this.qesi.addPropertyChangeListener(this); dcd = new DefaultCategoryDataset(); JFreeChart chart = getChart(CHART_TYPE_BAR_3D); chart.setBackgroundPaint(Color.white); cp = new ChartPanel(chart); cp.setBorder(BorderFactory.createTitledBorder(null, "Graph", TitledBorder.LEADING, TitledBorder.TOP, UIConstants.LABEL_FONT));//ww w . j a v a 2 s .c om cp.setMouseZoomable(true, true); //cp.setPreferredSize(new Dimension(700, 500)); gbl.setConstraints(cp, SwingUtils.getGridBagConstraints(0, 0, 2, 1)); this.add(cp); JPanel graphTypeSelectionPanel = new JPanel(); viewBarGraph = new JRadioButton("View Bar Graph", true); viewLineGraph = new JRadioButton("View Line Graph", false); viewLineGraph.setEnabled(false); ButtonGroup bg = new ButtonGroup(); bg.add(viewBarGraph); bg.add(viewLineGraph); GridBagLayout graphTypeGBL = new GridBagLayout(); graphTypeSelectionPanel.setLayout(graphTypeGBL); graphTypeGBL.setConstraints(viewBarGraph, SwingUtils.getGridBagConstraints(0, 0)); graphTypeGBL.setConstraints(viewLineGraph, SwingUtils.getGridBagConstraints(1, 0)); graphTypeSelectionPanel.add(viewBarGraph); graphTypeSelectionPanel.add(viewLineGraph); viewBarGraph.addActionListener(this); viewLineGraph.addActionListener(this); graphTypeSelectionPanel.setBorder(BorderFactory.createTitledBorder(null, "Graph Type", TitledBorder.LEADING, TitledBorder.TOP, UIConstants.LABEL_FONT)); gbl.setConstraints(graphTypeSelectionPanel, SwingUtils.getGridBagConstraints(0, 1, 2, 1)); this.add(graphTypeSelectionPanel); //this.setBounds(50, 100, 100, 200); this.setBackground(Color.WHITE); }
From source file:uk.ac.lkl.cram.ui.chart.AbstractChartMaker.java
/** * Apply some defaults to a chart, including background paint * and font.//from w ww . jav a 2 s.c o m * @param chart the chart to which defaults should be applied */ private void setChartDefaults(JFreeChart chart) { Paint backgroundPaint = UIManager.getColor("InternalFrame.background"); //Set the background colour of the chart chart.setBackgroundPaint(backgroundPaint); //Set the background colour of the plot to be the same as the chart Plot plot = chart.getPlot(); plot.setBackgroundPaint(backgroundPaint); //No outline around the bars plot.setOutlineVisible(false); //Get the legend LegendTitle legend = chart.getLegend(); //Set the font of the legend to be the same as the platform legend.setItemFont(UIManager.getFont("Label.font")); //Set the background colour of the legend to be the same as the platform legend.setBackgroundPaint(backgroundPaint); //No frame around the legend legend.setFrame(BlockBorder.NONE); //Locate the legend to the right of the chart legend.setPosition(RectangleEdge.RIGHT); }
From source file:gsn.charts.GsnChartJfreechart.java
public JFreeChart createChart(Collection<Data> datas) { TimeSeries t1 = new TimeSeries("S1"); Iterator<Data> iter = datas.iterator(); Data data;/*from w w w. j a v a2 s.c o m*/ while (iter.hasNext()) { data = iter.next(); t1.addOrUpdate(RegularTimePeriod.createInstance(Millisecond.class, new Date((Long) data.getP2()), TimeZone.getDefault()), data.getValue()); } XYDataset dataset = new TimeSeriesCollection(t1); JFreeChart chart = ChartFactory.createTimeSeriesChart(null, null, null, dataset, false, false, false); chart.setAntiAlias(true); chart.setTextAntiAlias(true); chart.setBackgroundPaint(Color.WHITE); // XYPlot plot = (XYPlot) chart.getPlot(); plot.setNoDataMessage("No Data to Display"); plot.setDomainGridlinesVisible(true); plot.setBackgroundPaint(Color.WHITE); plot.setInsets(new RectangleInsets(5, 14, 0, 5)); // DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(ssdf); axis.setTickLabelFont(TICK_FONT); ValueAxis rangeAxis = plot.getRangeAxis(); rangeAxis.setTickLabelFont(TICK_FONT); // return chart; }