Java Code Examples for org.jfree.chart.JFreeChart#setBackgroundPaint()

The following examples show how to use org.jfree.chart.JFreeChart#setBackgroundPaint() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HistogramChartFactory.java    From mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
public static JFreeChart createHistogramOld(double[] data, int bin, String yAxisLabel, double min,
    double max) {
  if (data != null && data.length > 0) {
    HistogramDataset dataset = new HistogramDataset();
    dataset.addSeries("histo", data, bin, min, max);

    JFreeChart chart = ChartFactory.createHistogram("", yAxisLabel, "n", dataset,
        PlotOrientation.VERTICAL, true, false, false);

    chart.setBackgroundPaint(new Color(230, 230, 230));
    chart.getLegend().setVisible(false);
    XYPlot xyplot = chart.getXYPlot();
    xyplot.setForegroundAlpha(0.7F);
    xyplot.setBackgroundPaint(Color.WHITE);
    xyplot.setDomainGridlinePaint(new Color(150, 150, 150));
    xyplot.setRangeGridlinePaint(new Color(150, 150, 150));
    xyplot.getDomainAxis().setVisible(true);
    xyplot.getRangeAxis().setVisible(yAxisLabel != null);
    XYBarRenderer xybarrenderer = (XYBarRenderer) xyplot.getRenderer();
    xybarrenderer.setShadowVisible(false);
    xybarrenderer.setBarPainter(new StandardXYBarPainter());
    // xybarrenderer.setDrawBarOutline(false);
    return chart;
  } else
    return null;
}
 
Example 2
Source File: BarChartDemo1.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a sample chart.
 *
 * @param dataset  the dataset.
 *
 * @return The chart.
 */
private static JFreeChart createChart(CategoryDataset dataset) {
    JFreeChart chart = ChartFactory.createBarChart(
        "Performance: JFreeSVG vs Batik", null /* x-axis label*/, 
            "Milliseconds" /* y-axis label */, dataset);
    chart.addSubtitle(new TextTitle("Time to generate 1000 charts in SVG " 
            + "format (lower bars = better performance)"));
    chart.setBackgroundPaint(Color.white);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();

    // ******************************************************************
    //  More than 150 demo applications are included with the JFreeChart
    //  Developer Guide...for more information, see:
    //
    //  >   http://www.object-refinery.com/jfreechart/guide.html
    //
    // ******************************************************************

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);
    chart.getLegend().setFrame(BlockBorder.NONE);
    return chart;
}
 
Example 3
Source File: PerformanceChart.java    From jFuzzyLogic with GNU Lesser General Public License v3.0 6 votes vote down vote up
void display(String windowTitle) {
	//		 Create plot and show it
	JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, "No. of Fuzzy Inference Cycles", "Time (ms)", xyDataset, PlotOrientation.VERTICAL, true, true, true);
	chart.setBackgroundPaint(Color.white);
	final XYPlot xyPlot = chart.getXYPlot();
	final XYItemRenderer renderer = xyPlot.getRenderer();

	if( renderer instanceof XYLineAndShapeRenderer ) {
		final XYLineAndShapeRenderer rr = (XYLineAndShapeRenderer) renderer;
		//rr.setShapesVisible(true);
		// rr.setDefaultShapesFilled(false);
		rr.setSeriesStroke(1, new BasicStroke(1.2f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 6f, 3f }, 0.0f));
		rr.setSeriesStroke(2, new BasicStroke(1.2f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 10f, 6f }, 0.0f));
		rr.setSeriesStroke(3, new BasicStroke(1.2f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 5f, 5f }, 0.0f));
		rr.setSeriesPaint(0, Color.BLACK);
		rr.setSeriesPaint(1, Color.GREEN);
		rr.setSeriesPaint(2, Color.RED);
		rr.setSeriesPaint(3, Color.BLUE);
		rr.setLinesVisible(true);
		//rr.setSeriesShape(0, ShapeUtilities.createDiamond(5));
	}

	PlotWindow.showIt(windowTitle, chart);
}
 
Example 4
Source File: BarChartFXDemo1.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a sample chart.
 *
 * @param dataset  the dataset.
 *
 * @return The chart.
 */
private static JFreeChart createChart(CategoryDataset dataset) {
    JFreeChart chart = ChartFactory.createBarChart(
        "Performance: JFreeSVG vs Batik", null /* x-axis label*/, 
            "Milliseconds" /* y-axis label */, dataset);
    chart.addSubtitle(new TextTitle("Time to generate 1000 charts in SVG " 
            + "format (lower bars = better performance)"));
    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);
    chart.getLegend().setFrame(BlockBorder.NONE);
    return chart;
}
 
Example 5
Source File: DefaultChartService.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Returns a basic JFreeChart.
 */
private JFreeChart getBasicJFreeChart( CategoryPlot plot )
{
    JFreeChart jFreeChart = new JFreeChart( null, TITLE_FONT, plot, false );

    jFreeChart.setBackgroundPaint( Color.WHITE );
    jFreeChart.setAntiAlias( true );

    return jFreeChart;
}
 
Example 6
Source File: TimeSeriesChartDemo1.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a chart.
 * 
 * @param dataset  a dataset.
 * 
 * @return A chart.
 */
private static JFreeChart createChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart(
        "Legal & General Unit Trust Prices",  // title
        "Date",             // x-axis label
        "Price Per Unit",   // y-axis label
        dataset,            // data
        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);
    }
    
    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));
    
    return chart;

}
 
Example 7
Source File: DefaultChartEditor.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Updates the properties of a chart to match the properties defined on the
 * panel.
 *
 * @param chart  the chart.
 */
@Override
public void updateChart(JFreeChart chart) {
    this.titleEditor.setTitleProperties(chart);
    this.plotEditor.updatePlotProperties(chart.getPlot());
    chart.setAntiAlias(getAntiAlias());
    chart.setBackgroundPaint(getBackgroundPaint());
}
 
Example 8
Source File: PieChartFXDemo1.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates a chart.
 *
 * @param dataset  the dataset.
 *
 * @return A chart.
 */
private static JFreeChart createChart(PieDataset dataset) {

    JFreeChart chart = ChartFactory.createPieChart(
        "Smart Phones Manufactured / Q3 2011",  // chart title
        dataset,            // data
        false,              // no legend
        true,               // tooltips
        false               // no URL generation
    );

    // set a custom background for the chart
    chart.setBackgroundPaint(new GradientPaint(new Point(0, 0), 
            new Color(20, 20, 20), new Point(400, 200), Color.DARK_GRAY));

    // customise the title position and font
    TextTitle t = chart.getTitle();
    t.setHorizontalAlignment(HorizontalAlignment.LEFT);
    t.setPaint(new Color(240, 240, 240));
    t.setFont(new Font("Arial", Font.BOLD, 26));

    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setBackgroundPaint(null);
    plot.setInteriorGap(0.04);
    plot.setOutlineVisible(false);

    // use gradients and white borders for the section colours
    plot.setSectionPaint("Others", createGradientPaint(new Color(200, 200, 255), Color.BLUE));
    plot.setSectionPaint("Samsung", createGradientPaint(new Color(255, 200, 200), Color.RED));
    plot.setSectionPaint("Apple", createGradientPaint(new Color(200, 255, 200), Color.GREEN));
    plot.setSectionPaint("Nokia", createGradientPaint(new Color(200, 255, 200), Color.YELLOW));
    plot.setBaseSectionOutlinePaint(Color.WHITE);
    plot.setSectionOutlinesVisible(true);
    plot.setBaseSectionOutlineStroke(new BasicStroke(2.0f));

    // customise the section label appearance
    plot.setLabelFont(new Font("Courier New", Font.BOLD, 20));
    plot.setLabelLinkPaint(Color.WHITE);
    plot.setLabelLinkStroke(new BasicStroke(2.0f));
    plot.setLabelOutlineStroke(null);
    plot.setLabelPaint(Color.WHITE);
    plot.setLabelBackgroundPaint(null);
    
    // add a subtitle giving the data source
    TextTitle source = new TextTitle("Source: http://www.bbc.co.uk/news/business-15489523", 
            new Font("Courier New", Font.PLAIN, 12));
    source.setPaint(Color.WHITE);
    source.setPosition(RectangleEdge.BOTTOM);
    source.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    chart.addSubtitle(source);
    return chart;

}
 
Example 9
Source File: StatsGraphServlet.java    From document-management-system with GNU General Public License v2.0 4 votes vote down vote up
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException,
		ServletException {
	String action = WebUtils.getString(request, "action", "graph");
	String type = WebUtils.getString(request, "t");
	JFreeChart chart = null;
	updateSessionManager(request);

	try {
		if ("refresh".equals(action)) {
			new RepositoryInfo().runAs(null);
			ServletContext sc = getServletContext();
			sc.getRequestDispatcher("/admin/stats.jsp").forward(request, response);
		} else {
			response.setContentType("image/png");
			OutputStream out = response.getOutputStream();

			if (DOCUMENTS.equals(type) || DOCUMENTS_SIZE.equals(type) || FOLDERS.equals(type)) {
				chart = repoStats(type);
			} else if (DISK.equals(type)) {
				chart = diskStats();
			} else if (JVM_MEMORY.equals(type)) {
				chart = jvmMemStats();
			} else if (OS_MEMORY.equals(type)) {
				chart = osMemStats();
			}

			if (chart != null) {
				// Customize title font
				chart.getTitle().setFont(new Font("Tahoma", Font.BOLD, 16));

				// Match body {	background-color:#F6F6EE; }
				chart.setBackgroundPaint(new Color(246, 246, 238));

				// Customize no data
				PiePlot plot = (PiePlot) chart.getPlot();
				plot.setNoDataMessage("No data to display");

				// Customize labels
				plot.setLabelGenerator(null);

				// Customize legend
				LegendTitle legend = new LegendTitle(plot, new ColumnArrangement(), new ColumnArrangement());
				legend.setPosition(RectangleEdge.BOTTOM);
				legend.setFrame(BlockBorder.NONE);
				legend.setItemFont(new Font("Tahoma", Font.PLAIN, 12));
				chart.removeLegend();
				chart.addLegend(legend);

				if (DISK.equals(type) || JVM_MEMORY.equals(type) || OS_MEMORY.equals(type)) {
					ChartUtilities.writeChartAsPNG(out, chart, 225, 225);
				} else {
					ChartUtilities.writeChartAsPNG(out, chart, 250, 250);
				}
			}

			out.flush();
			out.close();
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example 10
Source File: ChartExportUtil.java    From mzmine2 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This method is used to save all image formats. it uses the specific methods for each file
 * format
 * 
 * @param chart
 * @param sett
 * @param chartRenderingInfo
 */
private static void writeChartToImage(JFreeChart chart, GraphicsExportParameters sett,
    ChartRenderingInfo info) throws Exception {
  // Background color
  Paint saved = chart.getBackgroundPaint();
  chart.setBackgroundPaint(sett.getColorWithAlpha());
  chart.setBackgroundImageAlpha((float) sett.getTransparency());
  if (chart.getLegend() != null)
    chart.getLegend().setBackgroundPaint(sett.getColorWithAlpha());
  // legends and stuff
  for (int i = 0; i < chart.getSubtitleCount(); i++)
    if (PaintScaleLegend.class.isAssignableFrom(chart.getSubtitle(i).getClass()))
      ((PaintScaleLegend) chart.getSubtitle(i)).setBackgroundPaint(sett.getColorWithAlpha());

  // apply bg
  chart.getPlot().setBackgroundPaint(sett.getColorWithAlpha());

  // create folder
  File f = sett.getFullpath();
  if (!f.exists()) {
    if (f.getParentFile() != null)
      f.getParentFile().mkdirs();
    // f.createNewFile();
  }

  Dimension size = sett.getPixelSize();
  // Format
  switch (sett.getFormat()) {
    case "PDF":
      writeChartToPDF(chart, size.width, size.height, f);
      break;
    case "PNG":
      writeChartToPNG(chart, info, size.width, size.height, f, (int) sett.getDPI());
      break;
    case "JPG":
      writeChartToJPEG(chart, info, size.width, size.height, f, (int) sett.getDPI());
      break;
    case "EPS":
      writeChartToEPS(chart, size.width, size.height, f);
      break;
    case "SVG":
      writeChartToSVG(chart, size.width, size.height, f);
      break;
    case "EMF":
      writeChartToEMF(chart, size.width, size.height, f);
      break;
  }
  //
  chart.setBackgroundPaint(saved);
  chart.setBackgroundImageAlpha(255);
  if (chart.getLegend() != null)
    chart.getLegend().setBackgroundPaint(saved);
  // legends and stuff
  for (int i = 0; i < chart.getSubtitleCount(); i++)
    if (PaintScaleLegend.class.isAssignableFrom(chart.getSubtitle(i).getClass()))
      ((PaintScaleLegend) chart.getSubtitle(i)).setBackgroundPaint(saved);

  // apply bg
  chart.getPlot().setBackgroundPaint(saved);
}
 
Example 11
Source File: MirrorChartFactory.java    From mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
private static JFreeChart createMirrorChart(String labelA, double precursorMZA, double rtA,
    DataPoint[] dpsA, String labelB, double precursorMZB, double rtB, DataPoint[] dpsB,
    boolean showTitle, boolean showLegend) {
  PseudoSpectrumDataSet data =
      dpsA == null ? null : createMSMSDataSet(precursorMZA, rtA, dpsA, labelA);
  PseudoSpectrumDataSet dataMirror =
      dpsB == null ? null : createMSMSDataSet(precursorMZB, rtB, dpsB, labelB);

  NumberFormat mzForm = MZmineCore.getConfiguration().getMZFormat();
  NumberFormat intensityFormat = new DecimalFormat("0.#");

  // set the X axis (retention time) properties
  NumberAxis xAxis = new NumberAxis("m/z");
  xAxis.setNumberFormatOverride(mzForm);
  xAxis.setUpperMargin(0.08);
  xAxis.setLowerMargin(0.00);
  xAxis.setTickLabelInsets(new RectangleInsets(0, 0, 20, 20));
  xAxis.setAutoRangeIncludesZero(false);
  xAxis.setMinorTickCount(5);

  PseudoSpectraRenderer renderer1 = new PseudoSpectraRenderer(Color.BLACK, false);
  PseudoSpectraRenderer renderer2 = new PseudoSpectraRenderer(Color.BLACK, false);

  // create subplot 1...
  final NumberAxis rangeAxis1 = new NumberAxis("rel. intensity [%]");
  final XYPlot subplot1 = new XYPlot(data, null, rangeAxis1, renderer1);
  subplot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
  rangeAxis1.setNumberFormatOverride(intensityFormat);
  rangeAxis1.setAutoRangeIncludesZero(true);
  rangeAxis1.setAutoRangeStickyZero(true);

  // create subplot 2...
  final NumberAxis rangeAxis2 = new NumberAxis("rel. intensity [%]");
  rangeAxis2.setNumberFormatOverride(intensityFormat);
  rangeAxis2.setAutoRangeIncludesZero(true);
  rangeAxis2.setAutoRangeStickyZero(true);
  rangeAxis2.setInverted(true);
  final XYPlot subplot2 = new XYPlot(dataMirror, null, rangeAxis2, renderer2);
  subplot2.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT);

  // parent plot...
  final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(xAxis);
  plot.setGap(0);

  // add the subplots...
  plot.add(subplot1, 1);
  plot.add(subplot2, 1);
  plot.setOrientation(PlotOrientation.VERTICAL);

  // set the plot properties
  plot.setBackgroundPaint(Color.white);
  plot.setAxisOffset(RectangleInsets.ZERO_INSETS);

  // set rendering order
  plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

  // set crosshair (selection) properties
  plot.setDomainCrosshairVisible(false);
  plot.setRangeCrosshairVisible(false);

  // return a new chart containing the overlaid plot...
  JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
  chart.setBackgroundPaint(Color.white);
  chart.getTitle().setVisible(false);

  chart.getXYPlot().setRangeZeroBaselineVisible(true);
  chart.getTitle().setVisible(showTitle);
  chart.getLegend().setVisible(showLegend);

  return chart;
}
 
Example 12
Source File: SWTMultipleAxisDemo1.java    From SIMVA-SoS with Apache License 2.0 4 votes vote down vote up
/**
 * Creates the demo chart.
 *
 * @return The chart.
 */
private static JFreeChart createChart() {

    XYDataset dataset1 = createDataset("Series 1", 100.0, new Minute(),
            200);

    JFreeChart chart = ChartFactory.createTimeSeriesChart(
        "Multiple Axis Demo 3",
        "Time of Day",
        "Primary Range Axis",
        dataset1,
        true,
        true,
        false
    );

    chart.setBackgroundPaint(Color.white);
    chart.setBorderVisible(true);
    chart.setBorderPaint(Color.BLACK);
    TextTitle subtitle = new TextTitle("Four datasets and four range axes.");
    chart.addSubtitle(subtitle);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    XYItemRenderer renderer = plot.getRenderer();
    renderer.setSeriesPaint(0, Color.black);

    // AXIS 2
    NumberAxis axis2 = new NumberAxis("Range Axis 2");
    axis2.setAutoRangeIncludesZero(false);
    axis2.setLabelPaint(Color.red);
    axis2.setTickLabelPaint(Color.red);
    plot.setRangeAxis(1, axis2);
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_LEFT);

    XYDataset dataset2 = createDataset("Series 2", 1000.0, new Minute(),
            170);
    plot.setDataset(1, dataset2);
    plot.mapDatasetToRangeAxis(1, 1);
    XYItemRenderer renderer2 = new StandardXYItemRenderer();
    renderer2.setSeriesPaint(0, Color.red);
    plot.setRenderer(1, renderer2);

    // AXIS 3
    NumberAxis axis3 = new NumberAxis("Range Axis 3");
    axis3.setLabelPaint(Color.blue);
    axis3.setTickLabelPaint(Color.blue);
    //axis3.setPositiveArrowVisible(true);
    plot.setRangeAxis(2, axis3);

    XYDataset dataset3 = createDataset("Series 3", 10000.0, new Minute(),
            170);
    plot.setDataset(2, dataset3);
    plot.mapDatasetToRangeAxis(2, 2);
    XYItemRenderer renderer3 = new StandardXYItemRenderer();
    renderer3.setSeriesPaint(0, Color.blue);
    plot.setRenderer(2, renderer3);

    // AXIS 4
    NumberAxis axis4 = new NumberAxis("Range Axis 4");
    axis4.setLabelPaint(Color.green);
    axis4.setTickLabelPaint(Color.green);
    plot.setRangeAxis(3, axis4);

    XYDataset dataset4 = createDataset("Series 4", 25.0, new Minute(), 200);
    plot.setDataset(3, dataset4);
    plot.mapDatasetToRangeAxis(3, 3);

    XYItemRenderer renderer4 = new StandardXYItemRenderer();
    renderer4.setSeriesPaint(0, Color.green);
    plot.setRenderer(3, renderer4);

    return chart;
}
 
Example 13
Source File: PieChartFXDemo1.java    From ccu-historian with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates a chart.
 *
 * @param dataset  the dataset.
 *
 * @return A chart.
 */
private static JFreeChart createChart(PieDataset dataset) {

    JFreeChart chart = ChartFactory.createPieChart(
        "Smart Phones Manufactured / Q3 2011",  // chart title
        dataset,            // data
        false,              // no legend
        true,               // tooltips
        false               // no URL generation
    );

    // set a custom background for the chart
    chart.setBackgroundPaint(new GradientPaint(new Point(0, 0), 
            new Color(20, 20, 20), new Point(400, 200), Color.DARK_GRAY));

    // customise the title position and font
    TextTitle t = chart.getTitle();
    t.setHorizontalAlignment(HorizontalAlignment.LEFT);
    t.setPaint(new Color(240, 240, 240));
    t.setFont(new Font("Arial", Font.BOLD, 26));

    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setBackgroundPaint(null);
    plot.setInteriorGap(0.04);
    plot.setOutlineVisible(false);

    // use gradients and white borders for the section colours
    plot.setSectionPaint("Others", createGradientPaint(new Color(200, 200, 255), Color.BLUE));
    plot.setSectionPaint("Samsung", createGradientPaint(new Color(255, 200, 200), Color.RED));
    plot.setSectionPaint("Apple", createGradientPaint(new Color(200, 255, 200), Color.GREEN));
    plot.setSectionPaint("Nokia", createGradientPaint(new Color(200, 255, 200), Color.YELLOW));
    plot.setBaseSectionOutlinePaint(Color.WHITE);
    plot.setSectionOutlinesVisible(true);
    plot.setBaseSectionOutlineStroke(new BasicStroke(2.0f));

    // customise the section label appearance
    plot.setLabelFont(new Font("Courier New", Font.BOLD, 20));
    plot.setLabelLinkPaint(Color.WHITE);
    plot.setLabelLinkStroke(new BasicStroke(2.0f));
    plot.setLabelOutlineStroke(null);
    plot.setLabelPaint(Color.WHITE);
    plot.setLabelBackgroundPaint(null);
    
    // add a subtitle giving the data source
    TextTitle source = new TextTitle("Source: http://www.bbc.co.uk/news/business-15489523", 
            new Font("Courier New", Font.PLAIN, 12));
    source.setPaint(Color.WHITE);
    source.setPosition(RectangleEdge.BOTTOM);
    source.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    chart.addSubtitle(source);
    return chart;

}
 
Example 14
Source File: SWTTimeSeriesDemo.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a chart.
 * 
 * @param dataset  a dataset.
 * 
 * @return A chart.
 */
private static JFreeChart createChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart(
        "Legal & General Unit Trust Prices",  // title
        "Date",             // x-axis label
        "Price Per Unit",   // y-axis label
        dataset,            // data
        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);
    //plot.setForegroundAlpha(0.5f);

    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
    }
    
    // code to test the alpha channel
    IntervalMarker interv = new IntervalMarker(120, 150,
    		Color.blue, new BasicStroke(5.0f),null,null,0.2f);
    plot.addRangeMarker(interv);
    
    // code to test the alpha channel within awt colors
    XYDifferenceRenderer differenceRenderer= new XYDifferenceRenderer(new Color(255,0,0,128),new Color(0,255,0,128),false);
    plot.setRenderer(differenceRenderer);
    
    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));
    
    return chart;

}
 
Example 15
Source File: PieChartDemo1.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates a chart.
 *
 * @param dataset  the dataset.
 *
 * @return A chart.
 */
private static JFreeChart createChart(PieDataset dataset) {

    JFreeChart chart = ChartFactory.createPieChart(
        "Smart Phones Manufactured / Q3 2011",  // chart title
        dataset,            // data
        false,              // no legend
        true,               // tooltips
        false               // no URL generation
    );

    // set a custom background for the chart
    chart.setBackgroundPaint(new GradientPaint(new Point(0, 0), 
            new Color(20, 20, 20), new Point(400, 200), Color.DARK_GRAY));

    // customise the title position and font
    TextTitle t = chart.getTitle();
    t.setHorizontalAlignment(HorizontalAlignment.LEFT);
    t.setPaint(new Color(240, 240, 240));
    t.setFont(new Font("Arial", Font.BOLD, 26));

    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setBackgroundPaint(null);
    plot.setInteriorGap(0.04);
    plot.setOutlineVisible(false);

    // use gradients and white borders for the section colours
    plot.setSectionPaint("Others", createGradientPaint(new Color(200, 200, 255), Color.BLUE));
    plot.setSectionPaint("Samsung", createGradientPaint(new Color(255, 200, 200), Color.RED));
    plot.setSectionPaint("Apple", createGradientPaint(new Color(200, 255, 200), Color.GREEN));
    plot.setSectionPaint("Nokia", createGradientPaint(new Color(200, 255, 200), Color.YELLOW));
    plot.setBaseSectionOutlinePaint(Color.WHITE);
    plot.setSectionOutlinesVisible(true);
    plot.setBaseSectionOutlineStroke(new BasicStroke(2.0f));

    // customise the section label appearance
    plot.setLabelFont(new Font("Courier New", Font.BOLD, 20));
    plot.setLabelLinkPaint(Color.WHITE);
    plot.setLabelLinkStroke(new BasicStroke(2.0f));
    plot.setLabelOutlineStroke(null);
    plot.setLabelPaint(Color.WHITE);
    plot.setLabelBackgroundPaint(null);
    
    // add a subtitle giving the data source
    TextTitle source = new TextTitle("Source: http://www.bbc.co.uk/news/business-15489523", 
            new Font("Courier New", Font.PLAIN, 12));
    source.setPaint(Color.WHITE);
    source.setPosition(RectangleEdge.BOTTOM);
    source.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    chart.addSubtitle(source);
    return chart;

}
 
Example 16
Source File: Meter.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Creates the chart .
 * 
 * @param chartTitle  the chart title.
 * @param dataset  the dataset.
 * 
 * @return A chart .
 */

public JFreeChart createChart(DatasetMap datasets) {

	Dataset dataset=(Dataset)datasets.getDatasets().get("1");

	MeterPlot plot = new MeterPlot((ValueDataset)dataset);
	plot.setRange(new Range(lower, upper));


	for (Iterator iterator = intervals.iterator(); iterator.hasNext();) {
		KpiInterval interval = (KpiInterval) iterator.next();

		plot.addInterval(new MeterInterval(interval.getLabel(), new Range(interval.getMin(), interval.getMax()), 
				Color.lightGray, new BasicStroke(2.0f), 
				interval.getColor()));
	}

	plot.setNeedlePaint(Color.darkGray);
	plot.setDialBackgroundPaint(Color.white);
	plot.setDialOutlinePaint(Color.gray);
	plot.setDialShape(DialShape.CHORD);
	plot.setMeterAngle(260);
	plot.setTickLabelsVisible(true);
	//set tick label style
	Font tickLabelsFont = new Font(labelsTickStyle.getFontName(), Font.PLAIN, labelsTickStyle.getSize());
	plot.setTickLabelFont(tickLabelsFont);
	plot.setTickLabelPaint(labelsTickStyle.getColor());
	plot.setTickSize(5.0);
	plot.setTickPaint(Color.lightGray);
	if(units!=null){
		plot.setUnits(units);
	}

	plot.setValuePaint(labelsValueStyle.getColor());
	plot.setValueFont(new Font(labelsValueStyle.getFontName(), Font.PLAIN, labelsValueStyle.getSize()));

	JFreeChart chart = new JFreeChart(name, 
			JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
	chart.setBackgroundPaint(color);
	
	TextTitle title = setStyleTitle(name, styleTitle);
	chart.setTitle(title);
	if(subName!= null && !subName.equals("")){
		TextTitle subTitle =setStyleTitle(subName, styleSubTitle);
		chart.addSubtitle(subTitle);
	}

	return chart;
}
 
Example 17
Source File: MotivationalViewer.java    From cst with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public synchronized void run() {

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    final JFreeChart chart = ChartFactory.createBarChart(
            getTitle(),
            getEntity(),
            "Value",
            dataset,
            PlotOrientation.VERTICAL,
            true,
            true,
            false
    );

    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    chart.setBackgroundPaint(Color.lightGray);

    ChartFrame frame= new ChartFrame(getTitle(), chart);
    frame.pack();
    frame.setVisible(true);

    while (true) {
        ArrayList<Codelet> tempCodeletsList = new ArrayList<Codelet>();
        tempCodeletsList.addAll(this.getListOfMotivationalEntities());

        synchronized (tempCodeletsList) {

            for (Codelet co : tempCodeletsList) {
                dataset.addValue(co.getActivation(), co.getName(), "activation");
            }
            try {
                Thread.currentThread().sleep(getRefreshPeriod());
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }
    }
}
 
Example 18
Source File: LineChart.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
public JFreeChart createChart(){
	
	logger.debug("IN");
	CategoryPlot plot = new CategoryPlot();

	
	NumberAxis rangeAxis = new NumberAxis("Kpi Values");
	rangeAxis.setLabelFont(new Font("Arial", Font.PLAIN, 12 ));
	Color colorLabel= Color.decode("#000000");
	rangeAxis.setLabelPaint(colorLabel);
	rangeAxis.setTickLabelFont(new Font("Arial", Font.PLAIN, 10 ));
	rangeAxis.setTickLabelPaint(colorLabel);
	plot.setRangeAxis(rangeAxis);
	
	CategoryAxis domainAxis = new CategoryAxis();
	domainAxis.setLabelFont(new Font("Arial", Font.PLAIN, 10 ));
       domainAxis.setLabelPaint(colorLabel);
       domainAxis.setTickLabelFont(new Font("Arial", Font.PLAIN, 10 ));
       domainAxis.setTickLabelPaint(colorLabel);
	plot.setDomainAxis(domainAxis);

	plot.setOrientation(PlotOrientation.VERTICAL);
	plot.setRangeGridlinesVisible(true);
	plot.setDomainGridlinesVisible(true);


	//I create a line renderer 
	MyStandardCategoryItemLabelGenerator generator=null;

		LineAndShapeRenderer lineRenderer = new LineAndShapeRenderer();
		lineRenderer.setShapesFilled(true);
		lineRenderer.setBaseItemLabelGenerator(generator);
		lineRenderer.setBaseItemLabelFont(new Font("Arial", Font.PLAIN, 12 ));
		lineRenderer.setBaseItemLabelPaint(colorLabel);
		lineRenderer.setBaseItemLabelsVisible(true);

		DefaultCategoryDataset datasetLine=(DefaultCategoryDataset)datasetMap.getDatasets().get("line");

			for (Iterator iterator = datasetLine.getRowKeys().iterator(); iterator.hasNext();) {
				String serName = (String) iterator.next();
				String labelName = "";
				int index=-1;
				index=datasetLine.getRowIndex(serName);
				
				Color color=Color.decode("#990200");
				lineRenderer.setSeriesPaint(index, color);	
			}

		plot.setDataset(0,datasetLine);
		plot.setRenderer(0,lineRenderer);

	plot.getDomainAxis().setCategoryLabelPositions(
			CategoryLabelPositions.UP_45);
	JFreeChart chart = new JFreeChart(plot);
	logger.debug("Chart created");
	TextTitle title=new TextTitle(name,new Font("Arial", Font.BOLD, 16 ),Color.decode("#990200"), RectangleEdge.TOP, HorizontalAlignment.CENTER, VerticalAlignment.TOP, RectangleInsets.ZERO_INSETS);
	chart.setTitle(title);
	TextTitle subTitle =new TextTitle(subName,new Font("Arial", Font.PLAIN, 12 ),Color.decode("#000000"), RectangleEdge.TOP, HorizontalAlignment.CENTER, VerticalAlignment.TOP, RectangleInsets.ZERO_INSETS);
	chart.addSubtitle(subTitle);
	TextTitle subTitle2 =new TextTitle(subName,new Font("Arial", Font.PLAIN, 8 ),Color.decode("#FFFFFF"), RectangleEdge.TOP, HorizontalAlignment.CENTER, VerticalAlignment.TOP, RectangleInsets.ZERO_INSETS);
	chart.addSubtitle(subTitle2);
	chart.removeLegend();
	
	chart.setBackgroundPaint(Color.white);
	logger.debug("OUT");
	return chart;
}
 
Example 19
Source File: SWTMultipleAxisDemo1.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates the demo chart.
 *
 * @return The chart.
 */
private static JFreeChart createChart() {

    XYDataset dataset1 = createDataset("Series 1", 100.0, new Minute(),
            200);

    JFreeChart chart = ChartFactory.createTimeSeriesChart(
        "Multiple Axis Demo 3",
        "Time of Day",
        "Primary Range Axis",
        dataset1,
        true,
        true,
        false
    );

    chart.setBackgroundPaint(Color.white);
    chart.setBorderVisible(true);
    chart.setBorderPaint(Color.BLACK);
    TextTitle subtitle = new TextTitle("Four datasets and four range axes.");
    chart.addSubtitle(subtitle);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    XYItemRenderer renderer = plot.getRenderer();
    renderer.setSeriesPaint(0, Color.black);

    // AXIS 2
    NumberAxis axis2 = new NumberAxis("Range Axis 2");
    axis2.setAutoRangeIncludesZero(false);
    axis2.setLabelPaint(Color.red);
    axis2.setTickLabelPaint(Color.red);
    plot.setRangeAxis(1, axis2);
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_LEFT);

    XYDataset dataset2 = createDataset("Series 2", 1000.0, new Minute(),
            170);
    plot.setDataset(1, dataset2);
    plot.mapDatasetToRangeAxis(1, 1);
    XYItemRenderer renderer2 = new StandardXYItemRenderer();
    renderer2.setSeriesPaint(0, Color.red);
    plot.setRenderer(1, renderer2);

    // AXIS 3
    NumberAxis axis3 = new NumberAxis("Range Axis 3");
    axis3.setLabelPaint(Color.blue);
    axis3.setTickLabelPaint(Color.blue);
    //axis3.setPositiveArrowVisible(true);
    plot.setRangeAxis(2, axis3);

    XYDataset dataset3 = createDataset("Series 3", 10000.0, new Minute(),
            170);
    plot.setDataset(2, dataset3);
    plot.mapDatasetToRangeAxis(2, 2);
    XYItemRenderer renderer3 = new StandardXYItemRenderer();
    renderer3.setSeriesPaint(0, Color.blue);
    plot.setRenderer(2, renderer3);

    // AXIS 4
    NumberAxis axis4 = new NumberAxis("Range Axis 4");
    axis4.setLabelPaint(Color.green);
    axis4.setTickLabelPaint(Color.green);
    plot.setRangeAxis(3, axis4);

    XYDataset dataset4 = createDataset("Series 4", 25.0, new Minute(), 200);
    plot.setDataset(3, dataset4);
    plot.mapDatasetToRangeAxis(3, 3);

    XYItemRenderer renderer4 = new StandardXYItemRenderer();
    renderer4.setSeriesPaint(0, Color.green);
    plot.setRenderer(3, renderer4);

    return chart;
}
 
Example 20
Source File: SWTChartEditor.java    From gama with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Updates the chart.
 *
 * @param chart
 *            the chart.
 */
public void updateChartProperties(final JFreeChart chart) {
	chart.setAntiAlias(this.antialias.getSelection());
	chart.setBackgroundPaint(GamaColors.toAwtColor(this.backgroundPaintCanvas.getColor()));
}