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

The following examples show how to use org.jfree.chart.JFreeChart#getTitle() . 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: EyeCandySixtiesChartTheme.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected void configureChart(JFreeChart jfreeChart, JRChartPlot jrPlot) throws JRException
{
	super.configureChart(jfreeChart, jrPlot);

	TextTitle title = jfreeChart.getTitle();
	if (title != null)
	{
		RectangleInsets padding = title.getPadding();
		double bottomPadding = Math.max(padding.getBottom(), 15d);
		title.setPadding(padding.getTop(), padding.getLeft(), bottomPadding, padding.getRight());
	}

	GradientPaint gp = (GradientPaint)getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.BACKGROUND_PAINT);

	jfreeChart.setBackgroundPaint(new GradientPaint(0f, 0f, gp.getColor1(), 0f, getChart().getHeight() * 0.7f, gp.getColor2(), false));
}
 
Example 2
Source File: Visualisation.java    From chipster with MIT License 5 votes vote down vote up
public static ChartPanel makePanel(JFreeChart chart) {

		ChartPanel panel = new ChartPanel(chart);
		if(chart.getTitle() != null){
			chart.getTitle().setFont(VisualConstants.VISUALISATION_TITLE_FONT);
		}
		return panel;
	}
 
Example 3
Source File: Visualisation.java    From chipster with MIT License 5 votes vote down vote up
public static ChartPanel makenNonScalablePanel(JFreeChart chart) {

		ChartPanel panel = new NonScalableChartPanel(chart);
		if(chart.getTitle() != null){
			chart.getTitle().setFont(VisualConstants.VISUALISATION_TITLE_FONT);
		}
		return panel;
	}
 
Example 4
Source File: SimpleChartTheme.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void setChartTitle(JFreeChart jfreeChart)
{
	TitleSettings titleSettings =  getTitleSettings();
	Boolean showTitle = titleSettings.getShowTitle();
	if (showTitle == null || showTitle)
	{
		TextTitle title = jfreeChart.getTitle();
				
		if (title != null)
		{
			Paint forePaint = getChart().getOwnTitleColor();
			if (forePaint == null && titleSettings.getForegroundPaint() != null)
			{
				forePaint = titleSettings.getForegroundPaint().getPaint();
			}
			if (forePaint == null)
			{
				forePaint = getChart().getTitleColor();
			}
			RectangleEdge titleEdge = getEdge(
					getChart().getTitlePositionValue(), 
					getEdge(
						titleSettings.getPositionValue(), 
						RectangleEdge.TOP
						)
					);
			
			handleTitleSettings(title, titleSettings, getChart().getTitleFont(), forePaint, titleEdge);
		}
	}
	else
	{
		jfreeChart.setTitle((TextTitle)null);
	}
}
 
Example 5
Source File: JFreeChartTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some checks for title changes and event notification.
 */
public void testTitleChangeEvent() {
    DefaultPieDataset dataset = new DefaultPieDataset();
    JFreeChart chart = ChartFactory.createPieChart("title", dataset, true);
    chart.addChangeListener(this);
    this.lastChartChangeEvent = null;
    TextTitle t = chart.getTitle();
    t.setFont(new Font("Dialog", Font.BOLD, 9));
    assertNotNull(this.lastChartChangeEvent);
    this.lastChartChangeEvent = null;

    // now create a new title and replace the existing title, several
    // things should happen:
    // (1) Adding the new title should trigger an immediate
    //     ChartChangeEvent;
    // (2) Modifying the new title should trigger a ChartChangeEvent;
    // (3) Modifying the old title should NOT trigger a ChartChangeEvent
    TextTitle t2 = new TextTitle("T2");
    chart.setTitle(t2);
    assertNotNull(this.lastChartChangeEvent);
    this.lastChartChangeEvent = null;

    t2.setFont(new Font("Dialog", Font.BOLD, 9));
    assertNotNull(this.lastChartChangeEvent);
    this.lastChartChangeEvent = null;

    t.setFont(new Font("Dialog", Font.BOLD, 9));
    assertNull(this.lastChartChangeEvent);
    this.lastChartChangeEvent = null;
}
 
Example 6
Source File: PlotUtils.java    From Scripts with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Exports the specified JFreeChart to a SVG or PDF file. Destination file
 * is specified by the user in a save dialog prompt. An error message is
 * displayed if the file could not be saved. Does nothing if {@code chart}
 * is {@code null}.
 *
 * @param chart
 *            the <a href="http://javadoc.imagej.net/JFreeChart/" target=
 *            "_blank">JFreeChart </a> to export.
 * @param bounds
 *            the Rectangle delimiting the boundaries within which the chart
 *            should be drawn.
 * @param extension
 *            The file extension. Either ".svg" or ".pdf"
 * @see #exportChartAsSVG(JFreeChart, Rectangle)
 * @see #exportChartAsPDF(JFreeChart, Rectangle)
 */
static void exportChart(final JFreeChart chart, final Rectangle bounds, final String extension) {
	if (chart == null)
		return;
	final String defaultName = (chart.getTitle() == null) ? "Chart" : chart.getTitle().getText();
	final SaveDialog sd = new SaveDialog("Export graph as...", defaultName, extension);
	if (sd.getFileName() == null)
		return;
	final File saveFile = new File(sd.getDirectory(), sd.getFileName());
	if ((saveFile != null) && saveFile.exists()) {
		if (!IJ.showMessageWithCancel("Export graph...",
				saveFile.getAbsolutePath() + " already exists.\nReplace it?"))
			return;
	}
	try {
		if (extension.toLowerCase().endsWith(".svg"))
			exportChartAsSVG(chart, bounds, saveFile);
		else if (extension.toLowerCase().endsWith(".pdf"))
			exportChartAsPDF(chart, bounds, saveFile);
		IJ.showStatus("Graph saved, " + saveFile.getAbsolutePath());
	} catch (final Exception e) {
		IJ.error("Error", "Saving to " + saveFile.getAbsolutePath() + " failed");
		if (IJ.debugMode)
			IJ.handleException(e);
		return;
	}
}
 
Example 7
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 8
Source File: PieChartDemo1.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 9
Source File: DefaultChartTheme.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 *
 */
protected void configureChart(JFreeChart jfreeChart) throws JRException
{
	if (getChart().getModeValue() == ModeEnum.OPAQUE)
	{
		jfreeChart.setBackgroundPaint(getChart().getBackcolor());
	}
	else
	{
		jfreeChart.setBackgroundPaint(null);
	}
	
	RectangleEdge titleEdge = getEdge(getChart().getTitlePositionValue(), RectangleEdge.TOP);
	
	if (jfreeChart.getTitle() != null)
	{
		TextTitle title = jfreeChart.getTitle();
		title.setPaint(getChart().getTitleColor());

		title.setFont(fontUtil.getAwtFont(getFont(getChart().getTitleFont()), getLocale()));
		title.setPosition(titleEdge);
	}

	String subtitleText = evaluateTextExpression(getChart().getSubtitleExpression());
	if (subtitleText != null)
	{
		TextTitle subtitle = new TextTitle(subtitleText);
		subtitle.setPaint(getChart().getSubtitleColor());

		subtitle.setFont(fontUtil.getAwtFont(getFont(getChart().getSubtitleFont()), getLocale()));
		subtitle.setPosition(titleEdge);

		jfreeChart.addSubtitle(subtitle);
	}

	// Apply all of the legend formatting options
	LegendTitle legend = jfreeChart.getLegend();
	if (legend != null)
	{
		legend.setItemPaint(getChart().getLegendColor());

		if (getChart().getOwnLegendBackgroundColor() == null)// in a way, legend backcolor inheritance from chart is useless
		{
			legend.setBackgroundPaint(null);
		}
		else
		{
			legend.setBackgroundPaint(getChart().getLegendBackgroundColor());
		}

		legend.setItemFont(fontUtil.getAwtFont(getFont(getChart().getLegendFont()), getLocale()));
		legend.setPosition(getEdge(getChart().getLegendPositionValue(), RectangleEdge.BOTTOM));
	}
	
	configurePlot(jfreeChart.getPlot());
}
 
Example 10
Source File: PieChartFXDemo1.java    From jfree-fxdemos with BSD 3-Clause "New" or "Revised" License 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", dataset);

    // 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.setDefaultSectionOutlinePaint(Color.WHITE);
    plot.setSectionOutlinesVisible(true);
    plot.setDefaultSectionOutlineStroke(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 11
Source File: TwoDPlot.java    From mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
TwoDPlot(RawDataFile rawDataFile, TwoDVisualizerWindow visualizer, TwoDDataSet dataset,
    Range<Double> rtRange, Range<Double> mzRange, String whichPlotTypeStr) {

  super(null);

  this.rawDataFile = rawDataFile;
  this.rtRange = rtRange;
  this.mzRange = mzRange;

  // setBackground(Color.white);
  setCursor(Cursor.CROSSHAIR);

  // set the X axis (retention time) properties
  xAxis = new NumberAxis("Retention time");
  xAxis.setAutoRangeIncludesZero(false);
  xAxis.setNumberFormatOverride(rtFormat);
  xAxis.setUpperMargin(0);
  xAxis.setLowerMargin(0);

  // set the Y axis (intensity) properties
  yAxis = new NumberAxis("m/z");
  yAxis.setAutoRangeIncludesZero(false);
  yAxis.setNumberFormatOverride(mzFormat);
  yAxis.setUpperMargin(0);
  yAxis.setLowerMargin(0);

  // set the plot properties
  if (whichPlotTypeStr == "default") {
    plot = new TwoDXYPlot(dataset, rtRange, mzRange, xAxis, yAxis);
  } else if (whichPlotTypeStr == "point2D") {
    plot = new PointTwoDXYPlot(dataset, rtRange, mzRange, xAxis, yAxis);
  }
  plot.setBackgroundPaint(Color.white);
  plot.setDomainGridlinesVisible(false);
  plot.setRangeGridlinesVisible(false);

  // chart properties
  chart = new JFreeChart("", titleFont, plot, false);
  chart.setBackgroundPaint(Color.white);

  setChart(chart);

  // title
  chartTitle = chart.getTitle();
  chartTitle.setMargin(5, 0, 0, 0);
  chartTitle.setFont(titleFont);

  chartSubTitle = new TextTitle();
  chartSubTitle.setFont(subTitleFont);
  chartSubTitle.setMargin(5, 0, 0, 0);
  chart.addSubtitle(chartSubTitle);

  // disable maximum size (we don't want scaling)
  // setMaximumDrawWidth(Integer.MAX_VALUE);
  // setMaximumDrawHeight(Integer.MAX_VALUE);

  // set crosshair (selection) properties
  plot.setRangeCrosshairVisible(false);
  plot.setDomainCrosshairVisible(true);
  plot.setDomainCrosshairPaint(crossHairColor);
  plot.setDomainCrosshairStroke(crossHairStroke);

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

  peakDataRenderer = new PeakDataRenderer();

  // reset zoom history
  ZoomHistory history = getZoomHistory();
  if (history != null)
    history.clear();
}
 
Example 12
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 13
Source File: PieChartDemo1.java    From SIMVA-SoS with Apache License 2.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: LinearExecutionChartBuilder.java    From livingdoc-confluence with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
private void customizeChart(JFreeChart chart) {
    chart.setBackgroundPaint(Color.white);
    chart.setBorderVisible(settings.isBorder());

    TextTitle chartTitle = chart.getTitle();
    customizeTitle(chartTitle, DEFAULT_TITLE_FONT);

    addSubTitle(chart, settings.getSubTitle(), DEFAULT_SUBTITLE_FONT);
    addSubTitle(chart, settings.getSubTitle2(), DEFAULT_SUBTITLE2_FONT);

    CategoryPlot plot = ( CategoryPlot ) chart.getPlot();
    plot.setNoDataMessage(ldUtil.getText("livingdoc.historic.nodata"));

    CategoryItemRenderer renderer = plot.getRenderer();

    int index = 0;
    renderer.setSeriesPaint(index ++ , GREEN_COLOR);
    if (settings.isShowIgnored()) {
        renderer.setSeriesPaint(index ++ , Color.yellow);
    }
    renderer.setSeriesPaint(index, Color.red);

    renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator());
    renderer.setItemURLGenerator(new CategoryURLGenerator() {

        @Override
        public String generateURL(CategoryDataset data, int series, int category) {
            Comparable< ? > valueKey = data.getColumnKey(category);
            ChartLongValue value = ( ChartLongValue ) valueKey;
            return "javascript:" + settings.getExecutionUID() + "_showExecutionResult('" + value.getId() + "');";
        }
    });

    CategoryAxis domainAxis = plot.getDomainAxis();
    customizeAxis(domainAxis);
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90);

    ValueAxis rangeAxis = plot.getRangeAxis();
    customizeAxis(rangeAxis);
    rangeAxis.setLowerBound(0);

    if (rangeAxis instanceof NumberAxis) {
        ( ( NumberAxis ) rangeAxis ).setTickUnit(new NumberTickUnit(1));
    }

    plot.setForegroundAlpha(0.8f);
}
 
Example 15
Source File: AggregationExecutionChartBuilder.java    From livingdoc-confluence with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
private void customizeChart(JFreeChart chart) throws IOException {
    chart.setBackgroundPaint(Color.white);
    chart.setBorderVisible(settings.isBorder());

    TextTitle chartTitle = chart.getTitle();
    customizeTitle(chartTitle, DEFAULT_TITLE_FONT);

    addSubTitle(chart, settings.getSubTitle(), DEFAULT_SUBTITLE_FONT);
    addSubTitle(chart, settings.getSubTitle2(), DEFAULT_SUBTITLE2_FONT);

    CategoryPlot plot = ( CategoryPlot ) chart.getPlot();
    plot.setNoDataMessage(ldUtil.getText("livingdoc.historic.nodata"));

    StackedBarRenderer renderer = new StackedBarRenderer(true);
    plot.setRenderer(renderer);

    int index = 0;
    renderer.setSeriesPaint(index ++ , GREEN_COLOR);
    if (settings.isShowIgnored()) {
        renderer.setSeriesPaint(index ++ , Color.yellow);
    }
    renderer.setSeriesPaint(index, Color.red);

    renderer.setToolTipGenerator(new DefaultTooltipGenerator());
    renderer.setItemURLGenerator(new CategoryURLGenerator() {

        @Override
        public String generateURL(CategoryDataset data, int series, int category) {
            Comparable< ? > valueKey = data.getColumnKey(category);
            ChartLongValue value = ( ChartLongValue ) valueKey;
            return "javascript:" + settings.getExecutionUID() + "_showHistoricChart('" + value.getId() + "');";
        }
    });

    CategoryAxis domainAxis = plot.getDomainAxis();
    customizeAxis(domainAxis);
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    domainAxis.setCategoryMargin(0.01);

    ValueAxis rangeAxis = plot.getRangeAxis();
    customizeAxis(rangeAxis);
    rangeAxis.setLowerBound(0);
    rangeAxis.setUpperBound(1.0);

    if (rangeAxis instanceof NumberAxis) {
        NumberAxis numberAxis = ( NumberAxis ) rangeAxis;
        numberAxis.setTickUnit(new NumberTickUnit(.10));
        numberAxis.setNumberFormatOverride(PERCENT_FORMATTER);
    }

    plot.setForegroundAlpha(0.8f);
}
 
Example 16
Source File: KendrickMassPlotTask.java    From mzmine2 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void run() {
  setStatus(TaskStatus.PROCESSING);
  logger.info("Create Kendrick mass plot of " + peakList);
  // Task canceled?
  if (isCanceled())
    return;

  JFreeChart chart = null;
  // 2D, if no third dimension was selected
  if (zAxisLabel.equals("none")) {
    chart = create2DKendrickMassPlot();
  }
  // 3D, if a third dimension was selected
  else {
    chart = create3DKendrickMassPlot();
  }
  chart.setBackgroundPaint(Color.white);

  // create chart JPanel
  EChartPanel chartPanel = new EChartPanel(chart, true, true, true, true, false);

  // Create Kendrick mass plot Window
  KendrickMassPlotWindow frame = new KendrickMassPlotWindow(chart, parameters, chartPanel);
  frame.add(chartPanel, BorderLayout.CENTER);

  // set title properties
  TextTitle chartTitle = chart.getTitle();
  chartTitle.setMargin(5, 0, 0, 0);
  chartTitle.setFont(titleFont);
  LegendTitle legend = chart.getLegend();
  legend.setVisible(false);
  frame.setTitle(title);
  frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
  frame.setBackground(Color.white);
  frame.setVisible(true);
  frame.pack();

  setStatus(TaskStatus.FINISHED);
  logger.info("Finished creating Kendrick mass plot of " + peakList);
}
 
Example 17
Source File: VanKrevelenDiagramTask.java    From mzmine2 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void run() {
  try {
    setStatus(TaskStatus.PROCESSING);
    logger.info("Create Van Krevelen diagram of " + peakList);
    // Task canceled?
    if (isCanceled())
      return;
    JFreeChart chart = null;
    // 2D, if no third dimension was selected
    if (zAxisLabel.equals("none")) {
      chart = create2DVanKrevelenDiagram();
    }
    // 3D, if a third dimension was selected
    else {
      chart = create3DVanKrevelenDiagram();
    }

    chart.setBackgroundPaint(Color.white);

    // create chart JPanel
    EChartPanel chartPanel = new EChartPanel(chart, true, true, true, true, false);

    // Create Van Krevelen Diagram window
    VanKrevelenDiagramWindow frame =
        new VanKrevelenDiagramWindow(chart, chartPanel, filteredRows);

    // create chart JPanel
    frame.add(chartPanel, BorderLayout.CENTER);

    // set title properties
    TextTitle chartTitle = chart.getTitle();
    chartTitle.setMargin(5, 0, 0, 0);
    chartTitle.setFont(titleFont);
    LegendTitle legend = chart.getLegend();
    legend.setVisible(false);
    frame.setTitle(title);
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frame.setBackground(Color.white);
    frame.setVisible(true);
    frame.pack();
    logger.info("Finished creating van Krevelen diagram of " + peakList);
    JOptionPane.showMessageDialog(frame, "Results summary:\n" + displayedFeatures
        + " feature list rows are displayed in the Van Krevelen diagram.\n"
        + featuresWithFormulasWithoutCHO
        + " feature list rows are not displayed, because the annotated molecular formula does not contain the elements C, H, and O.\n"
        + featuresWithoutFormula
        + " feature list rows are not displayed, because no molecular formula was assigned.");
    setStatus(TaskStatus.FINISHED);
  } catch (Throwable t) {
    setErrorMessage(
        "Nothing to plot here or some peaks have other identities than molecular formulas.\n"
            + "Have you annotated your features with molecular formulas?\n"
            + "You can use the feature list method \"Formula prediction\" to handle the task.");
    setStatus(TaskStatus.ERROR);
  }
}
 
Example 18
Source File: TwoDPlot.java    From mzmine2 with GNU General Public License v2.0 4 votes vote down vote up
TwoDPlot(RawDataFile rawDataFile, TwoDVisualizerWindow visualizer, TwoDDataSet dataset,
    Range<Double> rtRange, Range<Double> mzRange, String whichPlotTypeStr) {

  super(null, true);

  this.rawDataFile = rawDataFile;
  this.rtRange = rtRange;
  this.mzRange = mzRange;

  setBackground(Color.white);
  setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));

  // set the X axis (retention time) properties
  xAxis = new NumberAxis("Retention time");
  xAxis.setAutoRangeIncludesZero(false);
  xAxis.setNumberFormatOverride(rtFormat);
  xAxis.setUpperMargin(0);
  xAxis.setLowerMargin(0);

  // set the Y axis (intensity) properties
  yAxis = new NumberAxis("m/z");
  yAxis.setAutoRangeIncludesZero(false);
  yAxis.setNumberFormatOverride(mzFormat);
  yAxis.setUpperMargin(0);
  yAxis.setLowerMargin(0);

  // set the plot properties
  if (whichPlotTypeStr == "default") {
    plot = new TwoDXYPlot(dataset, rtRange, mzRange, xAxis, yAxis);
  } else if (whichPlotTypeStr == "point2D") {
    plot = new PointTwoDXYPlot(dataset, rtRange, mzRange, xAxis, yAxis);
  }
  plot.setBackgroundPaint(Color.white);
  plot.setDomainGridlinesVisible(false);
  plot.setRangeGridlinesVisible(false);

  // chart properties
  chart = new JFreeChart("", titleFont, plot, false);
  chart.setBackgroundPaint(Color.white);

  setChart(chart);

  // title
  chartTitle = chart.getTitle();
  chartTitle.setMargin(5, 0, 0, 0);
  chartTitle.setFont(titleFont);

  chartSubTitle = new TextTitle();
  chartSubTitle.setFont(subTitleFont);
  chartSubTitle.setMargin(5, 0, 0, 0);
  chart.addSubtitle(chartSubTitle);

  // disable maximum size (we don't want scaling)
  setMaximumDrawWidth(Integer.MAX_VALUE);
  setMaximumDrawHeight(Integer.MAX_VALUE);

  // set crosshair (selection) properties
  plot.setRangeCrosshairVisible(false);
  plot.setDomainCrosshairVisible(true);
  plot.setDomainCrosshairPaint(crossHairColor);
  plot.setDomainCrosshairStroke(crossHairStroke);

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

  peakDataRenderer = new PeakDataRenderer();

  JMenuItem plotTypeMenuItem = new JMenuItem("Toggle centroid/continuous mode");
  plotTypeMenuItem.addActionListener(visualizer);
  plotTypeMenuItem.setActionCommand("SWITCH_PLOTMODE");
  add(plotTypeMenuItem);

  JPopupMenu popupMenu = getPopupMenu();
  popupMenu.addSeparator();
  popupMenu.add(plotTypeMenuItem);

  // Add EMF and EPS options to the save as menu
  JMenuItem saveAsMenu = (JMenuItem) popupMenu.getComponent(3);
  GUIUtils.addMenuItem(saveAsMenu, "EMF...", this, "SAVE_EMF");
  GUIUtils.addMenuItem(saveAsMenu, "EPS...", this, "SAVE_EPS");


  // reset zoom history
  ZoomHistory history = getZoomHistory();
  if (history != null)
    history.clear();
}
 
Example 19
Source File: MultiPieChartExpression.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
protected void configureSubChart( final JFreeChart chart ) {
  final TextTitle chartTitle = chart.getTitle();
  if ( chartTitle != null ) {
    if ( getPieTitleFont() != null ) {
      chartTitle.setFont( getPieTitleFont() );
    } else {
      final Font titleFont = Font.decode( getTitleFont() );
      chartTitle.setFont( titleFont );
    }
  }

  if ( isAntiAlias() == false ) {
    chart.setAntiAlias( false );
  }

  final LegendTitle chLegend = chart.getLegend();
  if ( chLegend != null ) {
    final RectangleEdge loc = translateEdge( getLegendLocation().toLowerCase() );
    if ( loc != null ) {
      chLegend.setPosition( loc );
    }
    if ( getLegendFont() != null ) {
      chLegend.setItemFont( Font.decode( getLegendFont() ) );
    }
    if ( !isDrawLegendBorder() ) {
      chLegend.setBorder( BlockBorder.NONE );
    }
    if ( getLegendBackgroundColor() != null ) {
      chLegend.setBackgroundPaint( getLegendBackgroundColor() );
    }
    if ( getLegendTextColor() != null ) {
      chLegend.setItemPaint( getLegendTextColor() );
    }
  }

  final Plot plot = chart.getPlot();
  plot.setNoDataMessageFont( Font.decode( getLabelFont() ) );

  final String pieNoData = getPieNoDataMessage();
  if ( pieNoData != null ) {
    plot.setNoDataMessage( pieNoData );
  } else {
    final String message = getNoDataMessage();
    if ( message != null ) {
      plot.setNoDataMessage( message );
    }
  }
}
 
Example 20
Source File: PieChartDemo1.java    From ECG-Viewer with GNU General Public License v2.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;

}