List of usage examples for org.jfree.chart JFreeChart setBackgroundPaint
public void setBackgroundPaint(Paint paint)
From source file:de.rbs90.fwdisp.settingsgui.gui.tabs.statistics.TypeStatisticsPanel.java
public TypeStatisticsPanel() { setName("EinsatzTyp"); setLayout(new BorderLayout()); DefaultPieDataset dataset = new DefaultPieDataset(); HashMap<String, Integer> alarmCount = new HashMap<>(); try {/*www. j a va 2 s.c o m*/ ResultSet resultSet = Starter.getDatabase().getStatement() .executeQuery("SELECT TYPE, COUNT(*) AS COUNT FROM ALARMHISTORY GROUP BY TYPE"); while (resultSet.next()) { String type = resultSet.getString("TYPE"); if (type.isEmpty()) type = "unbekannt"; int count = resultSet.getInt("COUNT"); type += " (" + count + ")"; alarmCount.put(type, count); } } catch (SQLException e) { e.printStackTrace(); } for (String key : alarmCount.keySet()) { dataset.setValue(key, alarmCount.get(key)); } JFreeChart chart = ChartFactory.createPieChart3D("Einsatztypen", dataset, false, false, false); chart.setBackgroundPaint(getBackground()); ChartPanel panel = new ChartPanel(chart); panel.setPopupMenu(null); panel.setBackground(getBackground()); add(panel, BorderLayout.CENTER); }
From source file:playground.dgrether.analysis.charts.DgAvgDeltaUtilsModeQuantilesChart.java
@Override public JFreeChart createChart() { XYPlot plot = new XYPlot(); ValueAxis xAxis = this.axisBuilder.createValueAxis("% of Population Sorted by Income"); xAxis.setRange(0.0, 102.0);//from w w w .j ava 2 s . co m ValueAxis yAxis = this.axisBuilder.createValueAxis("Delta Utils [Utils]"); yAxis.setRange(-0.05, 0.3); plot.setDomainAxis(xAxis); plot.setRangeAxis(yAxis); DgColorScheme colorScheme = new DgColorScheme(); XYItemRenderer renderer2; renderer2 = new XYLineAndShapeRenderer(true, true); plot.setDataset(0, this.dataset); for (int i = 0; i <= 3; i++) { renderer2.setSeriesStroke(i, new BasicStroke(2.0f)); renderer2.setSeriesOutlineStroke(i, new BasicStroke(3.0f)); renderer2.setSeriesPaint(i, colorScheme.getColor(i + 1, "a")); } plot.setRenderer(0, renderer2); JFreeChart chart = new JFreeChart("", plot); chart.setBackgroundPaint(ChartColor.WHITE); chart.getLegend().setItemFont(this.axisBuilder.getAxisFont()); chart.setTextAntiAlias(true); return chart; }
From source file:dinamica.ChartOutput.java
public void print(GenericTransaction t) throws Throwable { //get chart parameters Recordset chartinfo = t.getRecordset("chartinfo"); //get chart data String id = chartinfo.getString("data"); Recordset data = (Recordset) getSession().getAttribute(id); if (data == null) throw new Throwable( "Invalid Recordset ID:" + id + " - The session does not contain an attribute with this ID."); //general chart params Integer width = (Integer) chartinfo.getValue("width"); Integer height = (Integer) chartinfo.getValue("height"); //load chart plugin String plugin = (String) chartinfo.getValue("chart-plugin"); AbstractChartPlugin obj = (AbstractChartPlugin) Thread.currentThread().getContextClassLoader() .loadClass(plugin).newInstance(); JFreeChart chart = obj.getChart(chartinfo, data); //set gradient chart.setBackgroundPaint(getGradient()); //set border and legend params chart.setBorderPaint(Color.LIGHT_GRAY); chart.setBorderVisible(true);// w ww .j av a2 s . co m if (chart.getLegend() != null) { chart.getLegend().setBorder(0.2, 0.2, 0.2, 0.2); chart.getLegend().setPadding(5, 5, 5, 5); chart.getLegend().setMargin(4, 5, 4, 4); } //render chart in memory BufferedImage img = chart.createBufferedImage(width.intValue(), height.intValue()); ByteArrayOutputStream b = new ByteArrayOutputStream(32768); //encode as PNG ImageIO.write(img, "png", b); //send bitmap via servlet output byte image[] = b.toByteArray(); getResponse().setContentType("image/png"); getResponse().setContentLength(image.length); OutputStream out = getResponse().getOutputStream(); out.write(image); out.close(); //save image bytes in session attribute if requested if (chartinfo.containsField("session")) { String session = chartinfo.getString("session"); if (session != null && session.equals("true")) getSession().setAttribute(chartinfo.getString("image-id"), image); } }
From source file:com.rcp.wbw.demo.editor.SWTOtherEditor.java
/** * Updates the chart.// w w w . ja va2s. c o m * * @param chart * the chart. */ public void updateChartProperties(JFreeChart chart) { chart.setAntiAlias(this.antialias.getSelection()); chart.setBackgroundPaint(SWTUtils.toAwtColor(this.backgroundPaintCanvas.getColor())); }
From source file:edu.cmu.sv.modelinference.eventtool.charting.DataChart.java
private JFreeChart createChart(String yLabel) { //Create the chart final JFreeChart chart = ChartFactory.createXYLineChart("Chart", "Time", yLabel, null); chart.setBackgroundPaint(Color.white); XYPlot plot = chart.getXYPlot();/*from w w w.ja v a 2s.c om*/ plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); plot.setRenderer(renderer); // change the auto tick unit selection to integer units only... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); return chart; }
From source file:sanger.team16.gui.genevar.eqtl.gene.RegionalPlot.java
public RegionalPlot(String geneChromosome, int geneStart, int distance, double threshold, List<QTL> significances, List<QTL> insignificances) throws ArrayIndexOutOfBoundsException { XYDataset dataset = this.createDataset(significances, insignificances); JFreeChart chart = createChart(geneChromosome, geneStart, distance, threshold, dataset); chart.setBackgroundPaint(Color.white); ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new Dimension(680, 175)); this.add(chartPanel); }
From source file:fr.ensimag.biblio.controllers.StatImg.java
/** * Handles the HTTP <code>GET</code> method. * * @param request servlet request/*from ww w . ja va 2s. c om*/ * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { OutputStream out = response.getOutputStream(); response.setContentType("image/png"); //int val1 = 40; //int val2 = 60; try { DefaultPieDataset dataset = new DefaultPieDataset(); String title = "Statistiques"; boolean legend = true; Map<String, String[]> params = request.getParameterMap(); for (Map.Entry<String, String[]> param : params.entrySet()) { String key = param.getKey(); String[] value = param.getValue(); System.out.println("key : " + key + "value : " + value[0]); if (key.equals("legend")) legend = Boolean.parseBoolean(value[0]); else dataset.setValue(key, Double.parseDouble(value[0])); } //dataset.setValue("Valeur 1", val1); //dataset.setValue("Valeur 2", val2); JFreeChart chart = ChartFactory.createPieChart(title, dataset, legend, false, false); chart.setBackgroundPaint(Color.WHITE); ChartUtilities.writeChartAsPNG(out, chart, 500, 300); } finally { out.close(); } }
From source file:fr.paris.lutece.plugins.form.utils.FormUtils.java
/** * create a JFreeChart Graph function of the statistic form submit * @param listStatistic the list of statistic of form submit * @param strLabelX the label of axis x/*from w w w . j av a2s . c om*/ * @param strLableY the label of axis x * @param strTimesUnit the times unit of axis x(Day,Week,Month) * @return a JFreeChart Graph function of the statistic form submit */ public static JFreeChart createXYGraph(List<StatisticFormSubmit> listStatistic, String strLabelX, String strLableY, String strTimesUnit) { XYDataset xyDataset = createDataset(listStatistic, strTimesUnit); JFreeChart jfreechart = ChartFactory.createTimeSeriesChart(EMPTY_STRING, strLabelX, strLableY, xyDataset, false, false, false); jfreechart.setBackgroundPaint(Color.white); XYPlot xyplot = jfreechart.getXYPlot(); //xyplot.setBackgroundPaint(Color.gray); //xyplot.setRangeGridlinesVisible(true); xyplot.setBackgroundPaint(Color.white); xyplot.setBackgroundPaint(Color.lightGray); xyplot.setDomainGridlinePaint(Color.white); xyplot.setRangeGridlinePaint(Color.white); // DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis( ); // dateaxis.setLowerMargin(0); // DateFormat formatter = new SimpleDateFormat("d-MMM-yyyy"); // dateaxis.setTickUnit(new DateTickUnit(DateTickUnit.DAY,7,formatter)); //dateaxis.setTickUnit(new DateTickUnit(DateTickUnit.DAY,7)); //dateaxis.setTickUnit(new DateTickUnit(DateTickUnit.DAY,7)); //dateaxis.setMinimumDate((Date)listStatistic.get(0).getTimesUnit()); //dateaxis.setMaximumDate((Date)listStatistic.get(listStatistic.size()-1).getTimesUnit()); //dateaxis.setTickUnit(new DateTickUnit(DateTickUnit.MONTH,1)); //dateaxis.setTickUnit(new DateTickUnit(1, 1, DateFormat.getDateInstance(DateFormat.SHORT, Locale.FRENCH))); //dateaxis.setTickUnit(new DateTickUnit(DateTickUnit.MONTH, 1, new SimpleDateFormat("MM/YY"))); //dateaxis.setVerticalTickLabels( true ); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) xyplot.getRenderer(); renderer.setBaseShapesVisible(true); renderer.setSeriesFillPaint(0, Color.RED); renderer.setUseFillPaint(true); // renderer.setToolTipGenerator( new StandardXYToolTipGenerator( "{0} {1} {2}", // DateFormat.getDateInstance( DateFormat.SHORT, Locale.FRENCH ), NumberFormat.getInstance( ) ) ); // // ChartRenderingInfo info = new ChartRenderingInfo( new StandardEntityCollection( ) ); return jfreechart; }
From source file:org.amanzi.awe.charts.builder.CategoryChartBuilder.java
@Override protected JFreeChart finishUp(JFreeChart chart) { chart = new JFreeChart(getModel().getName(), getPlot()); chart.setBackgroundPaint(Color.WHITE); chart.addSubtitle(getSubTitle(Messages.clickItemToDrillDown)); return chart; }
From source file:net.sf.profiler4j.console.MemoryPlotPanel.java
public MemoryPlotPanel(int maxAge, String title) { super(new BorderLayout()); totalSeries = new TimeSeries("Committed Memory", Millisecond.class); totalSeries.setMaximumItemAge(maxAge); usedSeries = new TimeSeries("Used Memory", Millisecond.class); usedSeries.setMaximumItemAge(maxAge); TimeSeriesCollection seriesCollection = new TimeSeriesCollection(); seriesCollection.addSeries(totalSeries); seriesCollection.addSeries(usedSeries); NumberAxis numberAxis = new NumberAxis("Memory (KB)"); numberAxis.setLabelFont(new Font("SansSerif", 0, 14)); numberAxis.setTickLabelFont(new Font("SansSerif", 0, 12)); numberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); DateAxis dateAxis = new DateAxis("Time"); dateAxis.setTickLabelFont(new Font("SansSerif", 0, 12)); dateAxis.setLabelFont(new Font("SansSerif", 0, 14)); dateAxis.setAutoRange(true);//w w w. j a va2 s. c o m dateAxis.setLowerMargin(0); dateAxis.setUpperMargin(0); dateAxis.setTickLabelsVisible(true); dateAxis.setDateFormatOverride(new SimpleDateFormat("HH:mm:ss")); XYLineAndShapeRenderer lineRenderer = new XYLineAndShapeRenderer(true, false); lineRenderer.setSeriesPaint(0, Color.RED); lineRenderer.setSeriesPaint(1, Color.GREEN.darker()); lineRenderer.setStroke(new BasicStroke(2F, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); XYPlot xyplot = new XYPlot(seriesCollection, dateAxis, numberAxis, lineRenderer); xyplot.setBackgroundPaint(Color.WHITE); xyplot.setDomainGridlinePaint(Color.LIGHT_GRAY); xyplot.setRangeGridlinePaint(Color.LIGHT_GRAY); xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D)); JFreeChart chart = new JFreeChart(title, new Font("SansSerif", Font.PLAIN, 14), xyplot, true); chart.setBackgroundPaint(Color.white); ChartPanel panel = new ChartPanel(chart); panel.setBorder(createCompoundBorder(createEmptyBorder(8, 8, 8, 8), createLineBorder(Color.LIGHT_GRAY))); add(panel); setBorder(createEmptyBorder(8, 8, 8, 8)); }