Java Code Examples for org.jfree.chart.title.LegendTitle#setPosition()

The following examples show how to use org.jfree.chart.title.LegendTitle#setPosition() . 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: GanttPanel.java    From openvisualtraceroute with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Update legend
 */
private void updateLegend() {
	_chart.removeLegend();
	final LegendTitle legend = new LegendTitle(() -> {
		final LegendItemCollection collection = new LegendItemCollection();
		if (_currentMode == DisplayMode.TIME) {
			collection.add(new LegendItem(Legend.LATENCY.label, null, null, null, new Rectangle(30, 20), Legend.LATENCY.color));
			if (_dnsLookup && _services.isEmbeddedTRAvailable() && !Env.INSTANCE.isUseOSTraceroute()) {
				collection.add(new LegendItem(Legend.DNS.label, null, null, null, new Rectangle(30, 20), Legend.DNS.color));
			}
		} else {
			collection.add(new LegendItem(Legend.DISTANCE.label, Legend.DISTANCE.color));
		}
		return collection;
	});
	legend.setPosition(RectangleEdge.BOTTOM);
	_chart.addLegend(legend);
}
 
Example 2
Source File: JFreeChartTest.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Some checks for the default legend firing change events.
 */
@Test
public void testLegendEvents() {
    DefaultPieDataset dataset = new DefaultPieDataset();
    JFreeChart chart = ChartFactory.createPieChart("title", dataset);
    chart.addChangeListener(this);
    this.lastChartChangeEvent = null;
    LegendTitle legend = chart.getLegend();
    legend.setPosition(RectangleEdge.TOP);
    assertNotNull(this.lastChartChangeEvent);
}
 
Example 3
Source File: JFreeChartPlotEngine.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Creates {@link LegendTitle}s for all dimensions from the PlotConfiguration of this Plotter2D.
 * Expects that all {@link ValueSource} s in the provided PlotConfiguration use the same
 * {@link DimensionConfig} s.
 */
private List<LegendTitle> createLegendTitles() {
	List<LegendTitle> legendTitles = new LinkedList<LegendTitle>();
	LegendConfiguration legendConfiguration = plotInstance.getCurrentPlotConfigurationClone().getLegendConfiguration();

	LegendTitle legendTitle = new SmartLegendTitle(this,
			new FlowArrangement(HorizontalAlignment.CENTER, VerticalAlignment.CENTER, 30, 2),
			new ColumnArrangement(HorizontalAlignment.LEFT, VerticalAlignment.CENTER, 0, 2));
	legendTitle.setItemPaint(legendConfiguration.getLegendFontColor());

	RectangleEdge position = legendConfiguration.getLegendPosition().getPosition();
	if (position == null) {
		return legendTitles;
	}
	legendTitle.setPosition(position);

	if (legendConfiguration.isShowLegendFrame()) {
		legendTitle.setFrame(new BlockBorder(legendConfiguration.getLegendFrameColor()));
	}
	ColoredBlockContainer wrapper = new ColoredBlockContainer(legendConfiguration.getLegendBackgroundColor());
	wrapper.add(legendTitle.getItemContainer());
	wrapper.setPadding(3, 3, 3, 3);
	legendTitle.setWrapper(wrapper);

	legendTitles.add(legendTitle);
	return legendTitles;
}
 
Example 4
Source File: JFreeChartTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some checks for the default legend firing change events.
 */
public void testLegendEvents() {
    DefaultPieDataset dataset = new DefaultPieDataset();
    JFreeChart chart = ChartFactory.createPieChart("title", dataset, true);
    chart.addChangeListener(this);
    this.lastChartChangeEvent = null;
    LegendTitle legend = chart.getLegend();
    legend.setPosition(RectangleEdge.TOP);
    assertNotNull(this.lastChartChangeEvent);
}
 
Example 5
Source File: AWSDeviceFarmGraph.java    From aws-device-farm-jenkins-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Create graph based on the given dataset and constraints.
 *
 * @return The JFreeChart graph.
 */
protected JFreeChart createGraph() {
    // Create chart.
    JFreeChart chart = ChartFactory.createStackedAreaChart(null, null, yLabel, dataset, PlotOrientation.VERTICAL, true, true, false);
    chart.setBackgroundPaint(Color.WHITE);

    // Create chart legend.
    LegendTitle legend = chart.getLegend();
    legend.setPosition(RectangleEdge.RIGHT);

    // Create chart plot.
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setForegroundAlpha(0.7f);
    plot.setBackgroundPaint(Color.WHITE);
    plot.setRangeGridlinePaint(Color.darkGray);

    // Create domain (x) axis.
    CategoryAxis domain = new ShiftedCategoryAxis(xLabel);
    domain.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    domain.setLowerMargin(0.0);
    domain.setUpperMargin(0.0);
    domain.setCategoryMargin(0.0);
    plot.setDomainAxis(domain);

    // Create range (y) axis.
    NumberAxis range = (NumberAxis) plot.getRangeAxis();
    range.setAutoRange(true);
    range.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // Create renderer and paint the chart.
    CategoryItemRenderer renderer = plot.getRenderer();
    plot.setInsets(new RectangleInsets(5.0, 0, 0, 5.0));

    // Set chart colors for sections.
    for (int i = 0; i < colors.length; i++) {
        renderer.setSeriesPaint(i, colors[i]);
    }
    return chart;
}
 
Example 6
Source File: JFreeChartTest.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some checks for the default legend firing change events.
 */
@Test
public void testLegendEvents() {
    DefaultPieDataset dataset = new DefaultPieDataset();
    JFreeChart chart = ChartFactory.createPieChart("title", dataset);
    chart.addChangeListener(this);
    this.lastChartChangeEvent = null;
    LegendTitle legend = chart.getLegend();
    legend.setPosition(RectangleEdge.TOP);
    assertNotNull(this.lastChartChangeEvent);
}
 
Example 7
Source File: BaseLineChart.java    From EdgeSim with MIT License 4 votes vote down vote up
protected void generateLineChart(String xAisTitle, String yAisTitle,
									 NumberTickUnit xAisSpace, NumberTickUnit yAisSpace, double yaisMinValue, double yAisMaxValue,
									 XYSeriesCollection collection) {
		this.chart = ChartFactory.createXYLineChart(null, xAisTitle, yAisTitle,
				collection, PlotOrientation.VERTICAL, true, true, false);

		this.chart.getPlot().setBackgroundPaint(SystemColor.white);

		LegendTitle legend = chart.getLegend();
		legend.setPosition(RectangleEdge.RIGHT);
		legend.setHorizontalAlignment(HorizontalAlignment.LEFT);

		XYPlot plot = (XYPlot) chart.getPlot();
		NumberAxis numberAxisX = (NumberAxis) chart.getXYPlot().getDomainAxis();
		numberAxisX.setAutoRangeIncludesZero(false);

		numberAxisX.setTickUnit(xAisSpace);
		numberAxisX.setAxisLineVisible(false);
		numberAxisX.setTickMarkInsideLength(4f);
		numberAxisX.setTickMarkOutsideLength(0);

		NumberAxis numberAxisY = (NumberAxis) chart.getXYPlot().getRangeAxis();
		numberAxisY.setTickUnit(yAisSpace);
		numberAxisY.setRangeWithMargins(yaisMinValue, yAisMaxValue);
		numberAxisY.setAutoRangeIncludesZero(true);
		numberAxisY.setAxisLineVisible(false);
		numberAxisY.setTickMarkInsideLength(4f);
		numberAxisY.setTickMarkOutsideLength(0);
		numberAxisY.setNumberFormatOverride(NumberFormat.getNumberInstance());

		XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot
				.getRenderer();
//		renderer.setBaseItemLabelsVisible(true);
		renderer.setDefaultItemLabelsVisible(true);
		renderer.setDefaultShapesVisible(true);
//		renderer.setBaseShapesVisible(true);
		renderer.setDrawOutlines(true);

		renderer.setSeriesOutlineStroke(0, new BasicStroke(5F));
		renderer.setSeriesOutlineStroke(1, new BasicStroke(5F));
		renderer.setSeriesOutlineStroke(2, new BasicStroke(5F));
		renderer.setSeriesOutlineStroke(3, new BasicStroke(5F));
		renderer.setSeriesOutlineStroke(4, new BasicStroke(5F));

		renderer.setSeriesPaint(0, Color.RED);
		renderer.setSeriesPaint(1, Color.BLUE);
		renderer.setSeriesPaint(2, new Color(255, 125, 11));
		renderer.setSeriesPaint(3, new Color(0, 161, 59));
		renderer.setSeriesPaint(4, new Color(148, 103, 189));

		renderer.setSeriesStroke(0, new BasicStroke(4.0F));
		renderer.setSeriesStroke(1, new BasicStroke(4.0F));
		renderer.setSeriesStroke(2, new BasicStroke(4.0F));
		renderer.setSeriesStroke(3, new BasicStroke(4.0F));
		renderer.setSeriesStroke(4, new BasicStroke(2.0F));
		renderer.setSeriesStroke(5, new BasicStroke(2.0F));

		// renderer.setUseFillPaint(true);

		this.chartFrame = new ChartFrame("Line Chart", chart);
		chartFrame.pack();
		chartFrame.setSize(800, 600);
		chartFrame.setLocation(300, 200);
		chartFrame.setVisible(true);
	}
 
Example 8
Source File: Cardumen_00241_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Creates a new chart with the given title and plot.  The 
 * <code>createLegend</code> argument specifies whether or not a legend
 * should be added to the chart.  
 * <br><br>
 * Note that the  {@link ChartFactory} class contains a range 
 * of static methods that will return ready-made charts, and often this
 * is a more convenient way to create charts than using this constructor.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param titleFont  the font for displaying the chart title 
 *                   (<code>null</code> permitted).
 * @param plot  controller of the visual representation of the data 
 *              (<code>null</code> not permitted).
 * @param createLegend  a flag indicating whether or not a legend should   
 *                      be created for the chart.
 */
public JFreeChart(String title, Font titleFont, Plot plot, 
                  boolean createLegend) {

    if (plot == null) {
        throw new NullPointerException("Null 'plot' argument.");
    }

    // create storage for listeners...
    this.progressListeners = new EventListenerList();
    this.changeListeners = new EventListenerList();
    this.notify = true;  // default is to notify listeners when the 
                         // chart changes

    this.renderingHints = new RenderingHints(
            RenderingHints.KEY_ANTIALIASING, 
            RenderingHints.VALUE_ANTIALIAS_ON);

    this.borderVisible = false;
    this.borderStroke = new BasicStroke(1.0f);
    this.borderPaint = Color.black;

    this.padding = RectangleInsets.ZERO_INSETS;
    
    this.plot = plot;
    plot.addChangeListener(this);

    this.subtitles = new ArrayList();

    // create a legend, if requested...
    if (createLegend) {
        LegendTitle legend = new LegendTitle(this.plot);
        legend.setMargin(new RectangleInsets(1.0, 1.0, 1.0, 1.0));
        legend.setFrame(new LineBorder());
        legend.setBackgroundPaint(Color.white);
        legend.setPosition(RectangleEdge.BOTTOM);
        this.subtitles.add(legend);
        legend.addChangeListener(this);
    }

    // add the chart title, if one has been specified...
    if (title != null) {
        if (titleFont == null) {
            titleFont = DEFAULT_TITLE_FONT;
        }
        this.title = new TextTitle(title, titleFont);
        this.title.addChangeListener(this);
    }

    this.backgroundPaint = DEFAULT_BACKGROUND_PAINT;

    this.backgroundImage = DEFAULT_BACKGROUND_IMAGE;
    this.backgroundImageAlignment = DEFAULT_BACKGROUND_IMAGE_ALIGNMENT;
    this.backgroundImageAlpha = DEFAULT_BACKGROUND_IMAGE_ALPHA;

}
 
Example 9
Source File: JFreeChart.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates a new chart with the given title and plot.  The
 * <code>createLegend</code> argument specifies whether or not a legend
 * should be added to the chart.
 * <br><br>
 * Note that the  {@link ChartFactory} class contains a range
 * of static methods that will return ready-made charts, and often this
 * is a more convenient way to create charts than using this constructor.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param titleFont  the font for displaying the chart title
 *                   (<code>null</code> permitted).
 * @param plot  controller of the visual representation of the data
 *              (<code>null</code> not permitted).
 * @param createLegend  a flag indicating whether or not a legend should
 *                      be created for the chart.
 */
public JFreeChart(String title, Font titleFont, Plot plot,
                  boolean createLegend) {

    ParamChecks.nullNotPermitted(plot, "plot");

    // create storage for listeners...
    this.progressListeners = new EventListenerList();
    this.changeListeners = new EventListenerList();
    this.notify = true;  // default is to notify listeners when the
                         // chart changes

    this.renderingHints = new RenderingHints(
            RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);
    // added the following hint because of 
    // http://stackoverflow.com/questions/7785082/
    this.renderingHints.put(RenderingHints.KEY_STROKE_CONTROL,
            RenderingHints.VALUE_STROKE_PURE);
    
    this.borderVisible = false;
    this.borderStroke = new BasicStroke(1.0f);
    this.borderPaint = Color.black;

    this.padding = RectangleInsets.ZERO_INSETS;

    this.plot = plot;
    plot.addChangeListener(this);

    this.subtitles = new ArrayList();

    // create a legend, if requested...
    if (createLegend) {
        LegendTitle legend = new LegendTitle(this.plot);
        legend.setMargin(new RectangleInsets(1.0, 1.0, 1.0, 1.0));
        legend.setFrame(new LineBorder());
        legend.setBackgroundPaint(Color.white);
        legend.setPosition(RectangleEdge.BOTTOM);
        this.subtitles.add(legend);
        legend.addChangeListener(this);
    }

    // add the chart title, if one has been specified...
    if (title != null) {
        if (titleFont == null) {
            titleFont = DEFAULT_TITLE_FONT;
        }
        this.title = new TextTitle(title, titleFont);
        this.title.addChangeListener(this);
    }

    this.backgroundPaint = DEFAULT_BACKGROUND_PAINT;

    this.backgroundImage = DEFAULT_BACKGROUND_IMAGE;
    this.backgroundImageAlignment = DEFAULT_BACKGROUND_IMAGE_ALIGNMENT;
    this.backgroundImageAlpha = DEFAULT_BACKGROUND_IMAGE_ALPHA;

}
 
Example 10
Source File: Chart.java    From freeacs with MIT License 4 votes vote down vote up
/**
 * All params can be null.
 *
 * @param min - the minimum number on the left range axis (must be set if max is set)
 * @param max - the maximum number on the left range axis (must be set if min is set)
 * @param method2 - the method to run out of Record, and populates a bar series (right range axis)
 * @param highLightIndex - the index to highlight
 * @return
 * @throws Exception
 */
public JFreeChart makeTimeChart(Double min, Double max, String method2, Integer highLightIndex)
    throws Exception {
  startTms = System.currentTimeMillis();
  endTms = 0;
  XYBarRenderer.setDefaultShadowsVisible(false);
  TimeSeriesCollection data = new TimeSeriesCollection();
  Map<String, TimeSeries> timeSeriesMap = makeTimeSeriesMap(method, recordMap, keyNames);
  for (TimeSeries timeSeries : timeSeriesMap.values()) {
    data.addSeries(timeSeries);
  }
  String yAxisLabel = method;
  String denominator = Record.getDenominator(report.getRecordClass(), method.toLowerCase());
  if (denominator != null) {
    yAxisLabel += " (" + denominator + ")";
  }
  chart = ChartFactory.createTimeSeriesChart(title, "Time", yAxisLabel, data, true, true, true);
  XYPlot plot = (XYPlot) chart.getPlot();
  if (method2 != null) {
    Map<Key, R> recordMap2 = recordMap;
    TimeSeriesCollection data2 = new TimeSeriesCollection();
    if (keyNames.length > 0) {
      recordMap2 = report.getMapAggregatedOn();
    }
    Map<String, TimeSeries> timeSeriesMap2 = makeTimeSeriesMap(method2, recordMap2);
    if (timeSeriesMap2.get("Total (" + method2 + ")") != null) {
      data2.addSeries(timeSeriesMap2.get("Total (" + method2 + ")"));
    }
    String y2AxisLabel = method2;
    String demoninator2 = Record.getDenominator(report.getRecordClass(), method2.toLowerCase());
    if (demoninator2 != null) {
      y2AxisLabel += " (" + demoninator2 + ")";
    }
    NumberAxis axis2 = new NumberAxis(y2AxisLabel);
    XYBarRenderer renderer2 = new XYBarRenderer(0.20);
    plot.setRangeAxis(1, axis2);
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);
    plot.setDataset(1, data2);
    plot.setRenderer(1, renderer2);
    plot.mapDatasetToRangeAxis(1, 1);
    renderer2.setBarPainter(new StandardXYBarPainter());
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE);
  }
  if (min != null && max != null) {
    plot.getRangeAxis(0).setRange(min, max);
  }

  if (highLightIndex != null) {
    chart.getXYPlot().getRenderer().setSeriesStroke(highLightIndex, new BasicStroke(5f));
  }

  XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
  renderer.setDefaultShapesVisible(true);
  renderer.setUseFillPaint(true);
  renderer.setDefaultFillPaint(Color.white);

  long diff = endTms - startTms;
  String format;
  if (diff > NINTY_DAYS) {
    format = "MMM-yyyy";
  } else if (diff > TWO_DAYS) {
    format = "dd-MMM";
  } else if (diff > TWO_MINUTES) {
    format = "HH:mm";
  } else {
    format = "HH:mm:ss";
  }
  DateAxis axis = (DateAxis) plot.getDomainAxis();
  axis.setDateFormatOverride(new SimpleDateFormat(format));

  LegendTitle lt = chart.getLegend(0);
  lt.setPosition(RectangleEdge.RIGHT);

  if (displayFrame) {
    ChartFrame frame = new ChartFrame(title, chart);
    frame.pack();
    frame.setVisible(true);
  }

  return chart;
}
 
Example 11
Source File: JGenProg2017_00106_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Creates a new chart with the given title and plot.  The 
 * <code>createLegend</code> argument specifies whether or not a legend
 * should be added to the chart.  
 * <br><br>
 * Note that the  {@link ChartFactory} class contains a range 
 * of static methods that will return ready-made charts, and often this
 * is a more convenient way to create charts than using this constructor.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param titleFont  the font for displaying the chart title 
 *                   (<code>null</code> permitted).
 * @param plot  controller of the visual representation of the data 
 *              (<code>null</code> not permitted).
 * @param createLegend  a flag indicating whether or not a legend should   
 *                      be created for the chart.
 */
public JFreeChart(String title, Font titleFont, Plot plot, 
                  boolean createLegend) {

    if (plot == null) {
        throw new NullPointerException("Null 'plot' argument.");
    }

    // create storage for listeners...
    this.progressListeners = new EventListenerList();
    this.changeListeners = new EventListenerList();
    this.notify = true;  // default is to notify listeners when the 
                         // chart changes

    this.renderingHints = new RenderingHints(
            RenderingHints.KEY_ANTIALIASING, 
            RenderingHints.VALUE_ANTIALIAS_ON);

    this.borderVisible = false;
    this.borderStroke = new BasicStroke(1.0f);
    this.borderPaint = Color.black;

    this.padding = RectangleInsets.ZERO_INSETS;
    
    this.plot = plot;
    plot.addChangeListener(this);

    this.subtitles = new ArrayList();

    // create a legend, if requested...
    if (createLegend) {
        LegendTitle legend = new LegendTitle(this.plot);
        legend.setMargin(new RectangleInsets(1.0, 1.0, 1.0, 1.0));
        legend.setFrame(new LineBorder());
        legend.setBackgroundPaint(Color.white);
        legend.setPosition(RectangleEdge.BOTTOM);
        this.subtitles.add(legend);
        legend.addChangeListener(this);
    }

    // add the chart title, if one has been specified...
    if (title != null) {
        if (titleFont == null) {
            titleFont = DEFAULT_TITLE_FONT;
        }
        this.title = new TextTitle(title, titleFont);
        this.title.addChangeListener(this);
    }

    this.backgroundPaint = DEFAULT_BACKGROUND_PAINT;

    this.backgroundImage = DEFAULT_BACKGROUND_IMAGE;
    this.backgroundImageAlignment = DEFAULT_BACKGROUND_IMAGE_ALIGNMENT;
    this.backgroundImageAlpha = DEFAULT_BACKGROUND_IMAGE_ALPHA;

}
 
Example 12
Source File: JFreeChart.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a new chart with the given title and plot.  The 
 * <code>createLegend</code> argument specifies whether or not a legend
 * should be added to the chart.  
 * <br><br>
 * Note that the  {@link ChartFactory} class contains a range 
 * of static methods that will return ready-made charts, and often this
 * is a more convenient way to create charts than using this constructor.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param titleFont  the font for displaying the chart title 
 *                   (<code>null</code> permitted).
 * @param plot  controller of the visual representation of the data 
 *              (<code>null</code> not permitted).
 * @param createLegend  a flag indicating whether or not a legend should   
 *                      be created for the chart.
 */
public JFreeChart(String title, Font titleFont, Plot plot, 
                  boolean createLegend) {

    if (plot == null) {
        throw new NullPointerException("Null 'plot' argument.");
    }

    // create storage for listeners...
    this.progressListeners = new EventListenerList();
    this.changeListeners = new EventListenerList();
    this.notify = true;  // default is to notify listeners when the 
                         // chart changes

    this.renderingHints = new RenderingHints(
            RenderingHints.KEY_ANTIALIASING, 
            RenderingHints.VALUE_ANTIALIAS_ON);

    this.borderVisible = false;
    this.borderStroke = new BasicStroke(1.0f);
    this.borderPaint = Color.black;

    this.padding = RectangleInsets.ZERO_INSETS;
    
    this.plot = plot;
    plot.addChangeListener(this);

    this.subtitles = new ArrayList();

    // create a legend, if requested...
    if (createLegend) {
        LegendTitle legend = new LegendTitle(this.plot);
        legend.setMargin(new RectangleInsets(1.0, 1.0, 1.0, 1.0));
        legend.setFrame(new LineBorder());
        legend.setBackgroundPaint(Color.white);
        legend.setPosition(RectangleEdge.BOTTOM);
        this.subtitles.add(legend);
        legend.addChangeListener(this);
    }

    // add the chart title, if one has been specified...
    if (title != null) {
        if (titleFont == null) {
            titleFont = DEFAULT_TITLE_FONT;
        }
        this.title = new TextTitle(title, titleFont);
        this.title.addChangeListener(this);
    }

    this.backgroundPaint = DEFAULT_BACKGROUND_PAINT;

    this.backgroundImage = DEFAULT_BACKGROUND_IMAGE;
    this.backgroundImageAlignment = DEFAULT_BACKGROUND_IMAGE_ALIGNMENT;
    this.backgroundImageAlpha = DEFAULT_BACKGROUND_IMAGE_ALPHA;

}
 
Example 13
Source File: JGenProg2017_00127_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Creates a new chart with the given title and plot.  The 
 * <code>createLegend</code> argument specifies whether or not a legend
 * should be added to the chart.  
 * <br><br>
 * Note that the  {@link ChartFactory} class contains a range 
 * of static methods that will return ready-made charts, and often this
 * is a more convenient way to create charts than using this constructor.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param titleFont  the font for displaying the chart title 
 *                   (<code>null</code> permitted).
 * @param plot  controller of the visual representation of the data 
 *              (<code>null</code> not permitted).
 * @param createLegend  a flag indicating whether or not a legend should   
 *                      be created for the chart.
 */
public JFreeChart(String title, Font titleFont, Plot plot, 
                  boolean createLegend) {

    if (plot == null) {
        throw new NullPointerException("Null 'plot' argument.");
    }

    // create storage for listeners...
    this.progressListeners = new EventListenerList();
    this.changeListeners = new EventListenerList();
    this.notify = true;  // default is to notify listeners when the 
                         // chart changes

    this.renderingHints = new RenderingHints(
            RenderingHints.KEY_ANTIALIASING, 
            RenderingHints.VALUE_ANTIALIAS_ON);

    this.borderVisible = false;
    this.borderStroke = new BasicStroke(1.0f);
    this.borderPaint = Color.black;

    this.padding = RectangleInsets.ZERO_INSETS;
    
    this.plot = plot;
    plot.addChangeListener(this);

    this.subtitles = new ArrayList();

    // create a legend, if requested...
    if (createLegend) {
        LegendTitle legend = new LegendTitle(this.plot);
        legend.setMargin(new RectangleInsets(1.0, 1.0, 1.0, 1.0));
        legend.setFrame(new LineBorder());
        legend.setBackgroundPaint(Color.white);
        legend.setPosition(RectangleEdge.BOTTOM);
        this.subtitles.add(legend);
        legend.addChangeListener(this);
    }

    // add the chart title, if one has been specified...
    if (title != null) {
        if (titleFont == null) {
            titleFont = DEFAULT_TITLE_FONT;
        }
        this.title = new TextTitle(title, titleFont);
        this.title.addChangeListener(this);
    }

    this.backgroundPaint = DEFAULT_BACKGROUND_PAINT;

    this.backgroundImage = DEFAULT_BACKGROUND_IMAGE;
    this.backgroundImageAlignment = DEFAULT_BACKGROUND_IMAGE_ALIGNMENT;
    this.backgroundImageAlpha = DEFAULT_BACKGROUND_IMAGE_ALPHA;

}
 
Example 14
Source File: jKali_0052_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Creates a new chart with the given title and plot.  The 
 * <code>createLegend</code> argument specifies whether or not a legend
 * should be added to the chart.  
 * <br><br>
 * Note that the  {@link ChartFactory} class contains a range 
 * of static methods that will return ready-made charts, and often this
 * is a more convenient way to create charts than using this constructor.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param titleFont  the font for displaying the chart title 
 *                   (<code>null</code> permitted).
 * @param plot  controller of the visual representation of the data 
 *              (<code>null</code> not permitted).
 * @param createLegend  a flag indicating whether or not a legend should   
 *                      be created for the chart.
 */
public JFreeChart(String title, Font titleFont, Plot plot, 
                  boolean createLegend) {

    if (plot == null) {
        throw new NullPointerException("Null 'plot' argument.");
    }

    // create storage for listeners...
    this.progressListeners = new EventListenerList();
    this.changeListeners = new EventListenerList();
    this.notify = true;  // default is to notify listeners when the 
                         // chart changes

    this.renderingHints = new RenderingHints(
            RenderingHints.KEY_ANTIALIASING, 
            RenderingHints.VALUE_ANTIALIAS_ON);

    this.borderVisible = false;
    this.borderStroke = new BasicStroke(1.0f);
    this.borderPaint = Color.black;

    this.padding = RectangleInsets.ZERO_INSETS;
    
    this.plot = plot;
    plot.addChangeListener(this);

    this.subtitles = new ArrayList();

    // create a legend, if requested...
    if (createLegend) {
        LegendTitle legend = new LegendTitle(this.plot);
        legend.setMargin(new RectangleInsets(1.0, 1.0, 1.0, 1.0));
        legend.setFrame(new LineBorder());
        legend.setBackgroundPaint(Color.white);
        legend.setPosition(RectangleEdge.BOTTOM);
        this.subtitles.add(legend);
        legend.addChangeListener(this);
    }

    // add the chart title, if one has been specified...
    if (title != null) {
        if (titleFont == null) {
            titleFont = DEFAULT_TITLE_FONT;
        }
        this.title = new TextTitle(title, titleFont);
        this.title.addChangeListener(this);
    }

    this.backgroundPaint = DEFAULT_BACKGROUND_PAINT;

    this.backgroundImage = DEFAULT_BACKGROUND_IMAGE;
    this.backgroundImageAlignment = DEFAULT_BACKGROUND_IMAGE_ALIGNMENT;
    this.backgroundImageAlpha = DEFAULT_BACKGROUND_IMAGE_ALPHA;

}
 
Example 15
Source File: SimpleChartTheme.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected void setChartLegend(JFreeChart jfreeChart)
{
	//The legend visibility is already taken into account in the jfreeChart object's constructor
	LegendTitle legend = jfreeChart.getLegend();
	if (legend != null)
	{
		LegendSettings legendSettings = getLegendSettings();
		JRBaseFont font = new JRBaseFont();
		FontUtil.copyNonNullOwnProperties(legendSettings.getFont(), font);
		FontUtil.copyNonNullOwnProperties(getChart().getLegendFont(), font);
		font = new JRBaseFont(getChart(), font);
		legend.setItemFont(getFontUtil().getAwtFont(font, getLocale()));

		Paint forePaint = getChart().getOwnLegendColor();
		if (forePaint == null && legendSettings.getForegroundPaint() != null)
		{
			forePaint = legendSettings.getForegroundPaint().getPaint();
		}
		if (forePaint == null)
		{
			forePaint = getChart().getLegendColor();
		}
		if (forePaint != null)
			legend.setItemPaint(forePaint);

		Paint backPaint = getChart().getOwnLegendBackgroundColor();
		if (backPaint == null && legendSettings.getBackgroundPaint() != null)
		{
			backPaint = legendSettings.getBackgroundPaint().getPaint();
		}
		if (backPaint == null)
		{
			backPaint = getChart().getLegendBackgroundColor();
		}
		if (backPaint != null)
			legend.setBackgroundPaint(backPaint);

		BlockFrame blockFrame = legendSettings.getBlockFrame();
		if (blockFrame != null)
			legend.setFrame(blockFrame);
		
		HorizontalAlignment hAlign = legendSettings.getHorizontalAlignment();
		if (hAlign != null)
			legend.setHorizontalAlignment(hAlign);
		
		VerticalAlignment vAlign = legendSettings.getVerticalAlignment();
		if (vAlign != null)
			legend.setVerticalAlignment(vAlign);
		
		RectangleInsets padding = legendSettings.getPadding();
		if (padding != null)
			legend.setPadding(padding);

		legend.setPosition(
			getEdge(
				getChart().getLegendPositionValue(), 
				getEdge(
					legendSettings.getPositionValue() , 
					RectangleEdge.BOTTOM
					)
				)
			);
	}
}
 
Example 16
Source File: JFreeChart.java    From ECG-Viewer with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a new chart with the given title and plot.  The
 * <code>createLegend</code> argument specifies whether or not a legend
 * should be added to the chart.
 * <br><br>
 * Note that the  {@link ChartFactory} class contains a range
 * of static methods that will return ready-made charts, and often this
 * is a more convenient way to create charts than using this constructor.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param titleFont  the font for displaying the chart title
 *                   (<code>null</code> permitted).
 * @param plot  controller of the visual representation of the data
 *              (<code>null</code> not permitted).
 * @param createLegend  a flag indicating whether or not a legend should
 *                      be created for the chart.
 */
public JFreeChart(String title, Font titleFont, Plot plot,
                  boolean createLegend) {

    ParamChecks.nullNotPermitted(plot, "plot");

    // create storage for listeners...
    this.progressListeners = new EventListenerList();
    this.changeListeners = new EventListenerList();
    this.notify = true;  // default is to notify listeners when the
                         // chart changes

    this.renderingHints = new RenderingHints(
            RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);
    // added the following hint because of 
    // http://stackoverflow.com/questions/7785082/
    this.renderingHints.put(RenderingHints.KEY_STROKE_CONTROL,
            RenderingHints.VALUE_STROKE_PURE);
    
    this.borderVisible = false;
    this.borderStroke = new BasicStroke(1.0f);
    this.borderPaint = Color.black;

    this.padding = RectangleInsets.ZERO_INSETS;

    this.plot = plot;
    plot.addChangeListener(this);

    this.subtitles = new ArrayList();

    // create a legend, if requested...
    if (createLegend) {
        LegendTitle legend = new LegendTitle(this.plot);
        legend.setMargin(new RectangleInsets(1.0, 1.0, 1.0, 1.0));
        legend.setFrame(new LineBorder());
        legend.setBackgroundPaint(Color.white);
        legend.setPosition(RectangleEdge.BOTTOM);
        this.subtitles.add(legend);
        legend.addChangeListener(this);
    }

    // add the chart title, if one has been specified...
    if (title != null) {
        if (titleFont == null) {
            titleFont = DEFAULT_TITLE_FONT;
        }
        this.title = new TextTitle(title, titleFont);
        this.title.addChangeListener(this);
    }

    this.backgroundPaint = DEFAULT_BACKGROUND_PAINT;

    this.backgroundImage = DEFAULT_BACKGROUND_IMAGE;
    this.backgroundImageAlignment = DEFAULT_BACKGROUND_IMAGE_ALIGNMENT;
    this.backgroundImageAlpha = DEFAULT_BACKGROUND_IMAGE_ALPHA;

}
 
Example 17
Source File: JGenProg2017_00104_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Creates a new chart with the given title and plot.  The 
 * <code>createLegend</code> argument specifies whether or not a legend
 * should be added to the chart.  
 * <br><br>
 * Note that the  {@link ChartFactory} class contains a range 
 * of static methods that will return ready-made charts, and often this
 * is a more convenient way to create charts than using this constructor.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param titleFont  the font for displaying the chart title 
 *                   (<code>null</code> permitted).
 * @param plot  controller of the visual representation of the data 
 *              (<code>null</code> not permitted).
 * @param createLegend  a flag indicating whether or not a legend should   
 *                      be created for the chart.
 */
public JFreeChart(String title, Font titleFont, Plot plot, 
                  boolean createLegend) {

    if (plot == null) {
        throw new NullPointerException("Null 'plot' argument.");
    }

    // create storage for listeners...
    this.progressListeners = new EventListenerList();
    this.changeListeners = new EventListenerList();
    this.notify = true;  // default is to notify listeners when the 
                         // chart changes

    this.renderingHints = new RenderingHints(
            RenderingHints.KEY_ANTIALIASING, 
            RenderingHints.VALUE_ANTIALIAS_ON);

    this.borderVisible = false;
    this.borderStroke = new BasicStroke(1.0f);
    this.borderPaint = Color.black;

    this.padding = RectangleInsets.ZERO_INSETS;
    
    this.plot = plot;
    plot.addChangeListener(this);

    this.subtitles = new ArrayList();

    // create a legend, if requested...
    if (createLegend) {
        LegendTitle legend = new LegendTitle(this.plot);
        legend.setMargin(new RectangleInsets(1.0, 1.0, 1.0, 1.0));
        legend.setFrame(new LineBorder());
        legend.setBackgroundPaint(Color.white);
        legend.setPosition(RectangleEdge.BOTTOM);
        this.subtitles.add(legend);
        legend.addChangeListener(this);
    }

    // add the chart title, if one has been specified...
    if (title != null) {
        if (titleFont == null) {
            titleFont = DEFAULT_TITLE_FONT;
        }
        this.title = new TextTitle(title, titleFont);
        this.title.addChangeListener(this);
    }

    this.backgroundPaint = DEFAULT_BACKGROUND_PAINT;

    this.backgroundImage = DEFAULT_BACKGROUND_IMAGE;
    this.backgroundImageAlignment = DEFAULT_BACKGROUND_IMAGE_ALIGNMENT;
    this.backgroundImageAlpha = DEFAULT_BACKGROUND_IMAGE_ALPHA;

}
 
Example 18
Source File: Cardumen_00241_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Creates a new chart with the given title and plot.  The 
 * <code>createLegend</code> argument specifies whether or not a legend
 * should be added to the chart.  
 * <br><br>
 * Note that the  {@link ChartFactory} class contains a range 
 * of static methods that will return ready-made charts, and often this
 * is a more convenient way to create charts than using this constructor.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param titleFont  the font for displaying the chart title 
 *                   (<code>null</code> permitted).
 * @param plot  controller of the visual representation of the data 
 *              (<code>null</code> not permitted).
 * @param createLegend  a flag indicating whether or not a legend should   
 *                      be created for the chart.
 */
public JFreeChart(String title, Font titleFont, Plot plot, 
                  boolean createLegend) {

    if (plot == null) {
        throw new NullPointerException("Null 'plot' argument.");
    }

    // create storage for listeners...
    this.progressListeners = new EventListenerList();
    this.changeListeners = new EventListenerList();
    this.notify = true;  // default is to notify listeners when the 
                         // chart changes

    this.renderingHints = new RenderingHints(
            RenderingHints.KEY_ANTIALIASING, 
            RenderingHints.VALUE_ANTIALIAS_ON);

    this.borderVisible = false;
    this.borderStroke = new BasicStroke(1.0f);
    this.borderPaint = Color.black;

    this.padding = RectangleInsets.ZERO_INSETS;
    
    this.plot = plot;
    plot.addChangeListener(this);

    this.subtitles = new ArrayList();

    // create a legend, if requested...
    if (createLegend) {
        LegendTitle legend = new LegendTitle(this.plot);
        legend.setMargin(new RectangleInsets(1.0, 1.0, 1.0, 1.0));
        legend.setFrame(new LineBorder());
        legend.setBackgroundPaint(Color.white);
        legend.setPosition(RectangleEdge.BOTTOM);
        this.subtitles.add(legend);
        legend.addChangeListener(this);
    }

    // add the chart title, if one has been specified...
    if (title != null) {
        if (titleFont == null) {
            titleFont = DEFAULT_TITLE_FONT;
        }
        this.title = new TextTitle(title, titleFont);
        this.title.addChangeListener(this);
    }

    this.backgroundPaint = DEFAULT_BACKGROUND_PAINT;

    this.backgroundImage = DEFAULT_BACKGROUND_IMAGE;
    this.backgroundImageAlignment = DEFAULT_BACKGROUND_IMAGE_ALIGNMENT;
    this.backgroundImageAlpha = DEFAULT_BACKGROUND_IMAGE_ALPHA;

}
 
Example 19
Source File: Cardumen_0077_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Creates a new chart with the given title and plot.  The 
 * <code>createLegend</code> argument specifies whether or not a legend
 * should be added to the chart.  
 * <br><br>
 * Note that the  {@link ChartFactory} class contains a range 
 * of static methods that will return ready-made charts, and often this
 * is a more convenient way to create charts than using this constructor.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param titleFont  the font for displaying the chart title 
 *                   (<code>null</code> permitted).
 * @param plot  controller of the visual representation of the data 
 *              (<code>null</code> not permitted).
 * @param createLegend  a flag indicating whether or not a legend should   
 *                      be created for the chart.
 */
public JFreeChart(String title, Font titleFont, Plot plot, 
                  boolean createLegend) {

    if (plot == null) {
        throw new NullPointerException("Null 'plot' argument.");
    }

    // create storage for listeners...
    this.progressListeners = new EventListenerList();
    this.changeListeners = new EventListenerList();
    this.notify = true;  // default is to notify listeners when the 
                         // chart changes

    this.renderingHints = new RenderingHints(
            RenderingHints.KEY_ANTIALIASING, 
            RenderingHints.VALUE_ANTIALIAS_ON);

    this.borderVisible = false;
    this.borderStroke = new BasicStroke(1.0f);
    this.borderPaint = Color.black;

    this.padding = RectangleInsets.ZERO_INSETS;
    
    this.plot = plot;
    plot.addChangeListener(this);

    this.subtitles = new ArrayList();

    // create a legend, if requested...
    if (createLegend) {
        LegendTitle legend = new LegendTitle(this.plot);
        legend.setMargin(new RectangleInsets(1.0, 1.0, 1.0, 1.0));
        legend.setFrame(new LineBorder());
        legend.setBackgroundPaint(Color.white);
        legend.setPosition(RectangleEdge.BOTTOM);
        this.subtitles.add(legend);
        legend.addChangeListener(this);
    }

    // add the chart title, if one has been specified...
    if (title != null) {
        if (titleFont == null) {
            titleFont = DEFAULT_TITLE_FONT;
        }
        this.title = new TextTitle(title, titleFont);
        this.title.addChangeListener(this);
    }

    this.backgroundPaint = DEFAULT_BACKGROUND_PAINT;

    this.backgroundImage = DEFAULT_BACKGROUND_IMAGE;
    this.backgroundImageAlignment = DEFAULT_BACKGROUND_IMAGE_ALIGNMENT;
    this.backgroundImageAlpha = DEFAULT_BACKGROUND_IMAGE_ALPHA;

}
 
Example 20
Source File: JFreeChart.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates a new chart with the given title and plot.  The
 * <code>createLegend</code> argument specifies whether or not a legend
 * should be added to the chart.
 * <br><br>
 * Note that the  {@link ChartFactory} class contains a range
 * of static methods that will return ready-made charts, and often this
 * is a more convenient way to create charts than using this constructor.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param titleFont  the font for displaying the chart title
 *                   (<code>null</code> permitted).
 * @param plot  controller of the visual representation of the data
 *              (<code>null</code> not permitted).
 * @param createLegend  a flag indicating whether or not a legend should
 *                      be created for the chart.
 */
public JFreeChart(String title, Font titleFont, Plot plot,
                  boolean createLegend) {

    ParamChecks.nullNotPermitted(plot, "plot");

    // create storage for listeners...
    this.progressListeners = new EventListenerList();
    this.changeListeners = new EventListenerList();
    this.notify = true;  // default is to notify listeners when the
                         // chart changes

    this.renderingHints = new RenderingHints(
            RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);
    // added the following hint because of 
    // http://stackoverflow.com/questions/7785082/
    this.renderingHints.put(RenderingHints.KEY_STROKE_CONTROL,
            RenderingHints.VALUE_STROKE_PURE);
    
    this.borderVisible = false;
    this.borderStroke = new BasicStroke(1.0f);
    this.borderPaint = Color.black;

    this.padding = RectangleInsets.ZERO_INSETS;

    this.plot = plot;
    plot.addChangeListener(this);

    this.subtitles = new ArrayList();

    // create a legend, if requested...
    if (createLegend) {
        LegendTitle legend = new LegendTitle(this.plot);
        legend.setMargin(new RectangleInsets(1.0, 1.0, 1.0, 1.0));
        legend.setFrame(new LineBorder());
        legend.setBackgroundPaint(Color.white);
        legend.setPosition(RectangleEdge.BOTTOM);
        this.subtitles.add(legend);
        legend.addChangeListener(this);
    }

    // add the chart title, if one has been specified...
    if (title != null) {
        if (titleFont == null) {
            titleFont = DEFAULT_TITLE_FONT;
        }
        this.title = new TextTitle(title, titleFont);
        this.title.addChangeListener(this);
    }

    this.backgroundPaint = DEFAULT_BACKGROUND_PAINT;

    this.backgroundImage = DEFAULT_BACKGROUND_IMAGE;
    this.backgroundImageAlignment = DEFAULT_BACKGROUND_IMAGE_ALIGNMENT;
    this.backgroundImageAlpha = DEFAULT_BACKGROUND_IMAGE_ALPHA;

}