Java Code Examples for org.jfree.chart.title.TextTitle#setFont()

The following examples show how to use org.jfree.chart.title.TextTitle#setFont() . 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: StandardChartTheme.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Applies this theme to the supplied chart.
 *
 * @param chart  the chart (<code>null</code> not permitted).
 */
@Override
public void apply(JFreeChart chart) {
    ParamChecks.nullNotPermitted(chart, "chart");
    TextTitle title = chart.getTitle();
    if (title != null) {
        title.setFont(this.extraLargeFont);
        title.setPaint(this.titlePaint);
    }

    int subtitleCount = chart.getSubtitleCount();
    for (int i = 0; i < subtitleCount; i++) {
        applyToTitle(chart.getSubtitle(i));
    }

    chart.setBackgroundPaint(this.chartBackgroundPaint);

    // now process the plot if there is one
    Plot plot = chart.getPlot();
    if (plot != null) {
        applyToPlot(plot);
    }
}
 
Example 2
Source File: StandardChartTheme.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Applies the attributes of this theme to the specified title.
 *
 * @param title  the title.
 */
protected void applyToTitle(Title title) {
    if (title instanceof TextTitle) {
        TextTitle tt = (TextTitle) title;
        tt.setFont(this.largeFont);
        tt.setPaint(this.subtitlePaint);
    }
    else if (title instanceof LegendTitle) {
        LegendTitle lt = (LegendTitle) title;
        if (lt.getBackgroundPaint() != null) {
            lt.setBackgroundPaint(this.legendBackgroundPaint);
        }
        lt.setItemFont(this.regularFont);
        lt.setItemPaint(this.legendItemPaint);
        if (lt.getWrapper() != null) {
            applyToBlockContainer(lt.getWrapper());
        }
    }
    else if (title instanceof PaintScaleLegend) {
        PaintScaleLegend psl = (PaintScaleLegend) title;
        psl.setBackgroundPaint(this.legendBackgroundPaint);
        ValueAxis axis = psl.getAxis();
        if (axis != null) {
            applyToValueAxis(axis);
        }
    }
    else if (title instanceof CompositeTitle) {
        CompositeTitle ct = (CompositeTitle) title;
        BlockContainer bc = ct.getContainer();
        List blocks = bc.getBlocks();
        Iterator iterator = blocks.iterator();
        while (iterator.hasNext()) {
            Block b = (Block) iterator.next();
            if (b instanceof Title) {
                applyToTitle((Title) b);
            }
        }
    }
}
 
Example 3
Source File: StandardChartTheme.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Applies the attributes of this theme to the specified title.
 *
 * @param title  the title.
 */
protected void applyToTitle(Title title) {
    if (title instanceof TextTitle) {
        TextTitle tt = (TextTitle) title;
        tt.setFont(this.largeFont);
        tt.setPaint(this.subtitlePaint);
    }
    else if (title instanceof LegendTitle) {
        LegendTitle lt = (LegendTitle) title;
        if (lt.getBackgroundPaint() != null) {
            lt.setBackgroundPaint(this.legendBackgroundPaint);
        }
        lt.setItemFont(this.regularFont);
        lt.setItemPaint(this.legendItemPaint);
        if (lt.getWrapper() != null) {
            applyToBlockContainer(lt.getWrapper());
        }
    }
    else if (title instanceof PaintScaleLegend) {
        PaintScaleLegend psl = (PaintScaleLegend) title;
        psl.setBackgroundPaint(this.legendBackgroundPaint);
        ValueAxis axis = psl.getAxis();
        if (axis != null) {
            applyToValueAxis(axis);
        }
    }
    else if (title instanceof CompositeTitle) {
        CompositeTitle ct = (CompositeTitle) title;
        BlockContainer bc = ct.getContainer();
        List blocks = bc.getBlocks();
        Iterator iterator = blocks.iterator();
        while (iterator.hasNext()) {
            Block b = (Block) iterator.next();
            if (b instanceof Title) {
                applyToTitle((Title) b);
            }
        }
    }
}
 
Example 4
Source File: StandardChartTheme.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Applies the attributes of this theme to the specified title.
 *
 * @param title  the title.
 */
protected void applyToTitle(Title title) {
    if (title instanceof TextTitle) {
        TextTitle tt = (TextTitle) title;
        tt.setFont(this.largeFont);
        tt.setPaint(this.subtitlePaint);
    }
    else if (title instanceof LegendTitle) {
        LegendTitle lt = (LegendTitle) title;
        if (lt.getBackgroundPaint() != null) {
            lt.setBackgroundPaint(this.legendBackgroundPaint);
        }
        lt.setItemFont(this.regularFont);
        lt.setItemPaint(this.legendItemPaint);
        if (lt.getWrapper() != null) {
            applyToBlockContainer(lt.getWrapper());
        }
    }
    else if (title instanceof PaintScaleLegend) {
        PaintScaleLegend psl = (PaintScaleLegend) title;
        psl.setBackgroundPaint(this.legendBackgroundPaint);
        ValueAxis axis = psl.getAxis();
        if (axis != null) {
            applyToValueAxis(axis);
        }
    }
    else if (title instanceof CompositeTitle) {
        CompositeTitle ct = (CompositeTitle) title;
        BlockContainer bc = ct.getContainer();
        List blocks = bc.getBlocks();
        Iterator iterator = blocks.iterator();
        while (iterator.hasNext()) {
            Block b = (Block) iterator.next();
            if (b instanceof Title) {
                applyToTitle((Title) b);
            }
        }
    }
}
 
Example 5
Source File: JFreeChartTest.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Some checks for title changes and event notification.
 */
@Test
public void testTitleChangeEvent() {
    DefaultPieDataset dataset = new DefaultPieDataset();
    JFreeChart chart = ChartFactory.createPieChart("title", dataset);
    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: 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 7
Source File: DefaultChartService.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private TextTitle getSubTitle( BaseChart chart )
{
    TextTitle textTitle = new TextTitle();

    String title = chart.hasTitle() ? chart.getTitle() : chart.generateTitle();

    textTitle.setFont( SUB_TITLE_FONT );
    textTitle.setText( title );

    return textTitle;
}
 
Example 8
Source File: PieChartFXDemo1.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;

}
 
Example 9
Source File: MsMsPlot.java    From mzmine2 with GNU General Public License v2.0 4 votes vote down vote up
MsMsPlot(final ActionListener listener, RawDataFile rawDataFile, MsMsVisualizerWindow visualizer,
    MsMsDataSet dataset, Range<Double> rtRange, Range<Double> mzRange) {

  super(null, true);

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

  // initialize the chart by default time series chart from factory
  chart = ChartFactory.createXYLineChart("", // title
      "", // x-axis label
      "", // y-axis label
      null, // data set
      PlotOrientation.VERTICAL, // orientation
      true, // create legend
      false, // generate tooltips
      false // generate URLs
  );

  chart.setBackgroundPaint(Color.white);
  setChart(chart);

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

  // set the plot properties
  plot = chart.getXYPlot();
  plot.setBackgroundPaint(Color.white);
  plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
  plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
  plot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD);
  plot.setDomainGridlinePaint(gridColor);
  plot.setRangeGridlinePaint(gridColor);

  // Set the domain log axis
  xAxis = new NumberAxis("Retention time (min)");
  xAxis.setAutoRangeIncludesZero(false);
  xAxis.setNumberFormatOverride(rtFormat);
  xAxis.setUpperMargin(0.01);
  xAxis.setLowerMargin(0.01);
  plot.setDomainAxis(xAxis);

  // Set the range log axis
  yAxis = new NumberAxis("Precursor m/z");
  yAxis.setAutoRangeIncludesZero(false);
  yAxis.setNumberFormatOverride(mzFormat);
  yAxis.setUpperMargin(0.1);
  yAxis.setLowerMargin(0.1);
  plot.setRangeAxis(yAxis);

  // Set crosshair properties
  plot.setDomainCrosshairVisible(true);
  plot.setRangeCrosshairVisible(true);
  plot.setDomainCrosshairPaint(crossHairColor);
  plot.setRangeCrosshairPaint(crossHairColor);
  plot.setDomainCrosshairStroke(crossHairStroke);
  plot.setRangeCrosshairStroke(crossHairStroke);

  // Create renderers
  mainRenderer = new MsMsPlotRenderer();
  plot.setRenderer(0, mainRenderer);

  // 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);

  // Add data sets;
  plot.setDataset(0, dataset);

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

  peakDataRenderer = new PeakDataRenderer();

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

  // Register for mouse-wheel events
  addMouseWheelListener(this);

  // reset zoom history
  ZoomHistory history = getZoomHistory();
  if (history != null)
    history.clear();
}
 
Example 10
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;

}
 
Example 11
Source File: AbstractChartBuilder.java    From livingdoc-confluence with GNU General Public License v3.0 4 votes vote down vote up
protected void customizeTitle(TextTitle title, Font font) {
    title.setFont(font);
    title.setTextAlignment(HorizontalAlignment.LEFT);
    title.setPaint(Color.BLACK);
    title.setBackgroundPaint(TRANSPARENT_COLOR);
}
 
Example 12
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 13
Source File: RTMZPlot.java    From mzmine2 with GNU General Public License v2.0 4 votes vote down vote up
public RTMZPlot(RTMZAnalyzerWindow masterFrame, AbstractXYZDataset dataset,
    InterpolatingLookupPaintScale paintScale) {
  super(null);

  this.paintScale = paintScale;

  chart = ChartFactory.createXYAreaChart("", "Retention time", "m/z", dataset,
      PlotOrientation.VERTICAL, false, false, false);
  chart.setBackgroundPaint(Color.white);
  setChart(chart);

  // title

  TextTitle chartTitle = chart.getTitle();
  chartTitle.setMargin(5, 0, 0, 0);
  chartTitle.setFont(titleFont);
  chart.removeSubtitle(chartTitle);

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

  // set the plot properties
  plot = chart.getXYPlot();
  plot.setBackgroundPaint(Color.white);
  plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));

  // set grid properties
  plot.setDomainGridlinePaint(gridColor);
  plot.setRangeGridlinePaint(gridColor);

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

  NumberFormat rtFormat = MZmineCore.getConfiguration().getRTFormat();
  NumberFormat mzFormat = MZmineCore.getConfiguration().getMZFormat();

  // set the X axis (retention time) properties
  NumberAxis xAxis = (NumberAxis) plot.getDomainAxis();
  xAxis.setNumberFormatOverride(rtFormat);
  xAxis.setUpperMargin(0.001);
  xAxis.setLowerMargin(0.001);

  // set the Y axis (intensity) properties
  NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
  yAxis.setAutoRangeIncludesZero(false);
  yAxis.setNumberFormatOverride(mzFormat);

  plot.setDataset(dataset);
  spotRenderer = new RTMZRenderer(dataset, paintScale);
  plot.setRenderer(spotRenderer);
  spotRenderer.setDefaultToolTipGenerator(new RTMZToolTipGenerator());

  // Add a paintScaleLegend to chart

  paintScaleAxis = new NumberAxis("Logratio");
  paintScaleAxis.setRange(paintScale.getLowerBound(), paintScale.getUpperBound());

  paintScaleLegend = new PaintScaleLegend(paintScale, paintScaleAxis);
  paintScaleLegend.setPosition(plot.getDomainAxisEdge());
  paintScaleLegend.setMargin(5, 25, 5, 25);

  chart.addSubtitle(paintScaleLegend);


  // reset zoom history
  ZoomHistory history = getZoomHistory();
  if (history != null)
    history.clear();
}
 
Example 14
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 15
Source File: ProjectionPlotPanel.java    From mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
public ProjectionPlotPanel(ProjectionPlotWindow masterFrame, ProjectionPlotDataset dataset,
    ParameterSet parameters) {
  super(null);

  boolean createLegend = false;
  if ((dataset.getNumberOfGroups() > 1) && (dataset.getNumberOfGroups() < 20))
    createLegend = true;

  chart = ChartFactory.createXYAreaChart("", dataset.getXLabel(), dataset.getYLabel(), dataset,
      PlotOrientation.VERTICAL, createLegend, false, false);
  chart.setBackgroundPaint(Color.white);

  setChart(chart);

  // title

  TextTitle chartTitle = chart.getTitle();
  chartTitle.setMargin(5, 0, 0, 0);
  chartTitle.setFont(titleFont);
  chart.removeSubtitle(chartTitle);

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

  // set the plot properties
  plot = chart.getXYPlot();
  plot.setBackgroundPaint(Color.white);
  plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));

  // set grid properties
  plot.setDomainGridlinePaint(gridColor);
  plot.setRangeGridlinePaint(gridColor);

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

  plot.setForegroundAlpha(dataPointAlpha);

  NumberFormat numberFormat = NumberFormat.getNumberInstance();

  // set the X axis (component 1) properties
  NumberAxis xAxis = (NumberAxis) plot.getDomainAxis();
  xAxis.setNumberFormatOverride(numberFormat);

  // set the Y axis (component 2) properties
  NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
  yAxis.setNumberFormatOverride(numberFormat);

  plot.setDataset(dataset);

  spotRenderer = new ProjectionPlotRenderer(plot, dataset);
  itemLabelGenerator = new ProjectionPlotItemLabelGenerator(parameters);
  spotRenderer.setDefaultItemLabelGenerator(itemLabelGenerator);
  spotRenderer.setDefaultItemLabelsVisible(true);
  spotRenderer.setDefaultToolTipGenerator(new ProjectionPlotToolTipGenerator(parameters));
  plot.setRenderer(spotRenderer);

  // Setup legend
  if (createLegend) {
    LegendItemCollection legendItemsCollection = new LegendItemCollection();
    for (int groupNumber = 0; groupNumber < dataset.getNumberOfGroups(); groupNumber++) {
      Object paramValue = dataset.getGroupParameterValue(groupNumber);
      if (paramValue == null) {
        // No parameter value available: search for raw data files
        // within this group, and use their names as group's name
        String fileNames = new String();
        for (int itemNumber = 0; itemNumber < dataset.getItemCount(0); itemNumber++) {
          String rawDataFile = dataset.getRawDataFile(itemNumber);
          if (dataset.getGroupNumber(itemNumber) == groupNumber)
            fileNames = fileNames.concat(rawDataFile);
        }
        if (fileNames.length() == 0)
          fileNames = "Empty group";

        paramValue = fileNames;
      }
      Color nextColor = (Color) spotRenderer.getGroupPaint(groupNumber);
      Color groupColor = new Color(nextColor.getRed(), nextColor.getGreen(), nextColor.getBlue(),
          Math.round(255 * dataPointAlpha));
      legendItemsCollection.add(new LegendItem(paramValue.toString(), "-", null, null,
          spotRenderer.getDataPointsShape(), groupColor));
    }
    plot.setFixedLegendItems(legendItemsCollection);
  }

  // reset zoom history
  ZoomHistory history = getZoomHistory();
  if (history != null)
    history.clear();
}
 
Example 16
Source File: HistogramChart.java    From mzmine2 with GNU General Public License v2.0 4 votes vote down vote up
public HistogramChart() {
  super(null, true);

  // initialize the chart by default time series chart from factory
  chart = ChartFactory.createHistogram("", // title
      "", // x-axis label
      "", // y-axis label
      null, // data set
      PlotOrientation.VERTICAL, // orientation
      true, // create legend
      false, // generate tooltips
      false // generate URLs
  );

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

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

  // legend constructed by ChartFactory
  LegendTitle legend = chart.getLegend();
  legend.setItemFont(legendFont);
  legend.setFrame(BlockBorder.NONE);

  chart.setBackgroundPaint(Color.white);
  setChart(chart);

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

  // set the plot properties
  plot = chart.getXYPlot();
  plot.setBackgroundPaint(Color.white);
  plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
  plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE);
  plot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD);

  // set grid properties
  plot.setDomainGridlinePaint(gridColor);
  plot.setRangeGridlinePaint(gridColor);

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

  // set the logarithmic axis
  NumberAxis axisDomain = new HistogramDomainAxis();
  axisDomain.setMinorTickCount(1);
  axisDomain.setAutoRange(true);

  NumberAxis axisRange = new NumberAxis();
  axisRange.setMinorTickCount(1);
  axisRange.setAutoRange(true);

  plot.setDomainAxis(axisDomain);
  plot.setRangeAxis(axisRange);

  ClusteredXYBarRenderer renderer = new ClusteredXYBarRenderer();
  renderer.setMargin(marginSize);
  renderer.setShadowVisible(false);
  plot.setRenderer(renderer);

  this.setMinimumSize(new Dimension(400, 400));
  this.setDismissDelay(Integer.MAX_VALUE);
  this.setInitialDelay(0);


  // reset zoom history
  ZoomHistory history = getZoomHistory();
  if (history != null)
    history.clear();
}
 
Example 17
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 18
Source File: AbstractChartExpression.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
protected void configureChart( final JFreeChart chart ) {
  // Misc Properties
  final TextTitle chartTitle = chart.getTitle();
  if ( chartTitle != null ) {
    final Font titleFont = Font.decode( getTitleFont() );
    chartTitle.setFont( titleFont );
  }

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

  chart.setBorderVisible( isShowBorder() );

  final Color backgroundColor = parseColorFromString( getBackgroundColor() );
  if ( backgroundColor != null ) {
    chart.setBackgroundPaint( backgroundColor );
  }

  if ( plotBackgroundColor != null ) {
    chart.getPlot().setBackgroundPaint( plotBackgroundColor );
  }
  chart.getPlot().setBackgroundAlpha( plotBackgroundAlpha );
  chart.getPlot().setForegroundAlpha( plotForegroundAlpha );
  final Color borderCol = parseColorFromString( getBorderColor() );
  if ( borderCol != null ) {
    chart.setBorderPaint( borderCol );
  }

  //remove legend if showLegend = false
  if ( !isShowLegend() ) {
    chart.removeLegend();
  } else { //if true format legend
    final LegendTitle chLegend = chart.getLegend();
    if ( chLegend != null ) {
      final RectangleEdge loc = translateEdge( legendLocation.toLowerCase() );
      if ( loc != null ) {
        chLegend.setPosition( loc );
      }
      if ( getLegendFont() != null ) {
        chLegend.setItemFont( Font.decode( getLegendFont() ) );
      }
      if ( !isDrawLegendBorder() ) {
        chLegend.setBorder( BlockBorder.NONE );
      }
      if ( legendBackgroundColor != null ) {
        chLegend.setBackgroundPaint( legendBackgroundColor );
      }
      if ( legendTextColor != null ) {
        chLegend.setItemPaint( legendTextColor );
      }
    }

  }

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

  final String message = getNoDataMessage();
  if ( message != null ) {
    plot.setNoDataMessage( message );
  }

  plot.setOutlineVisible( isChartSectionOutline() );

  if ( backgroundImage != null ) {
    if ( plotImageCache != null ) {
      plot.setBackgroundImage( plotImageCache );
    } else {
      final ExpressionRuntime expressionRuntime = getRuntime();
      final ProcessingContext context = expressionRuntime.getProcessingContext();
      final ResourceKey contentBase = context.getContentBase();
      final ResourceManager manager = context.getResourceManager();
      try {
        final ResourceKey key = createKeyFromString( manager, contentBase, backgroundImage );
        final Resource resource = manager.create( key, null, Image.class );
        final Image image = (Image) resource.getResource();
        plot.setBackgroundImage( image );
        plotImageCache = image;
      } catch ( Exception e ) {
        logger.error( "ABSTRACTCHARTEXPRESSION.ERROR_0007_ERROR_RETRIEVING_PLOT_IMAGE", e ); //$NON-NLS-1$
        throw new IllegalStateException( "Failed to process chart" );
      }
    }
  }
}
 
Example 19
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 20
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);
  }
}