org.jfree.chart.JFreeChart.getLegend()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(8.7k)|赞(0)|评价(0)|浏览(163)

本文整理了Java中org.jfree.chart.JFreeChart.getLegend()方法的一些代码示例,展示了JFreeChart.getLegend()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JFreeChart.getLegend()方法的具体详情如下:
包路径:org.jfree.chart.JFreeChart
类名称:JFreeChart
方法名:getLegend

JFreeChart.getLegend介绍

[英]Returns the legend for the chart, if there is one. Note that a chart can have more than one legend - this method returns the first.
[中]返回图表的图例(如果有)。请注意,图表可以有多个图例-此方法返回第一个图例。

代码示例

代码示例来源:origin: jenkinsci/jenkins

/**
 * Draws a chart into {@link JFreeChart}.
 */
public JFreeChart createChart() {
  final JFreeChart chart = ChartFactory.createLineChart(null, // chart title
      null, // unused
      null, // range axis label
      dataset, // data
      PlotOrientation.VERTICAL, // orientation
      true, // include legend
      true, // tooltips
      false // urls
      );
  chart.setBackgroundPaint(Color.white);
  chart.getLegend().setItemFont(CHART_FONT);
  final CategoryPlot plot = chart.getCategoryPlot();
  configurePlot(plot);
  configureRangeAxis((NumberAxis) plot.getRangeAxis());
  crop(plot);
  return chart;
}

代码示例来源:origin: jfree/jfreechart

/**
 * Returns the legend for the chart, if there is one.  Note that a chart
 * can have more than one legend - this method returns the first.
 *
 * @return The legend (possibly {@code null}).
 *
 * @see #getLegend(int)
 */
public LegendTitle getLegend() {
  return getLegend(0);
}

代码示例来源:origin: org.codehaus.jtstand/jtstand-chart

/**
 * Returns the legend for the chart, if there is one.  Note that a chart
 * can have more than one legend - this method returns the first.
 *
 * @return The legend (possibly <code>null</code>).
 *
 * @see #getLegend(int)
 */
public LegendTitle getLegend() {
  return getLegend(0);
}

代码示例来源:origin: jfree/jfreechart

/**
 * Removes the first legend in the chart and sends a
 * {@link ChartChangeEvent} to all registered listeners.
 *
 * @see #getLegend()
 */
public void removeLegend() {
  removeSubtitle(getLegend());
}

代码示例来源:origin: org.codehaus.jtstand/jtstand-chart

/**
 * Removes the first legend in the chart and sends a
 * {@link ChartChangeEvent} to all registered listeners.
 *
 * @see #getLegend()
 */
public void removeLegend() {
  removeSubtitle(getLegend());
}

代码示例来源:origin: matsim-org/matsim

/**
 * Adds default formatting options for the charts, like a white background etc.
 * Requires the member {@link #chart} to be set by the overriding class!
 */
protected void addDefaultFormatting() {
  this.chart.setBackgroundPaint(new Color(1.0f, 1.0f, 1.0f, 1.0f));
  this.chart.getLegend().setBorder(0.0, 0.0, 0.0, 0.0);
}

代码示例来源:origin: stackoverflow.com

private void createChartPanel() {
  …
  JFreeChart chart = new JFreeChart("BoxAndWhiskerDemo", plot);
  LegendTitle legend = chart.getLegend();
  legend.setFrame(new LineBorder(Color.white, new BasicStroke(1.0f),
    new RectangleInsets(1.0, 1.0, 1.0, 1.0)));
  legend.setItemFont(legend.getItemFont().deriveFont(16f));
  chartPanel = new ChartPanel(chart);
}

代码示例来源:origin: MegaMek/mekhq

private JFreeChart createMonthlyChart(CategoryDataset dataset) {
  JFreeChart chart = ChartFactory.createBarChart(
    "", // title
    resourceMap.getString("graphDate.text"), // x-axis label
    resourceMap.getString("graphCBills.text"), // y-axis label
    dataset);
  chart.setBackgroundPaint(Color.WHITE);
  
  chart.getLegend().setPosition(RectangleEdge.TOP);
  return chart;
}

代码示例来源:origin: afranken/jmeter-analysis-maven-plugin

public static JFreeChart createJFreeChart(String title, XYPlot result, int imageHeight) {
    JFreeChart chart = new JFreeChart(title, result);
    chart.getLegend().setPosition(RectangleEdge.TOP);
    chart.getLegend().setHorizontalAlignment(HorizontalAlignment.LEFT);
    chart.getLegend().setFrame(BlockBorder.NONE);
    chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, imageHeight, new Color(229, 236, 246)));
    chart.getTitle().setFont(new Font("SansSerif", Font.PLAIN | Font.BOLD, 16));
    chart.getTitle().setPaint(Color.GRAY);
    return chart;
  }
}

代码示例来源:origin: stackoverflow.com

public class CustomFontCategoryChartCustomizer implements JRChartCustomizer  {
  @Override
  public void customize(JFreeChart chart, JRChart jasperChart) {
    Font customFont = new Font("DejaVu Serif", Font.PLAIN, 9);
    CategoryPlot plot = chart.getCategoryPlot();

    // Set legend's font        
    chart.getLegend().setItemFont(customFont);
    // Set categories label's font
    plot.getDomainAxis().setTickLabelFont(customFont);
    // Set amounts label's font 
    plot.getRangeAxis().setTickLabelFont(customFont);
  }
}

代码示例来源:origin: org.n52.sensorweb/timeseries-io

private BufferedImage drawChartToImage() {
  int width = getChartStyleDefinitions().getWidth();
  int height = getChartStyleDefinitions().getHeight();
  BufferedImage chartImage = new BufferedImage(width, height, TYPE_INT_RGB);
  Graphics2D chartGraphics = chartImage.createGraphics();
  chartGraphics.fillRect(0, 0, width, height);
  chartGraphics.setColor(WHITE);
  chart.setTextAntiAlias(true);
  chart.setAntiAlias(true);
  if (chart.getLegend() != null) {
    chart.getLegend()
       .setFrame(BlockBorder.NONE);
  }
  chart.draw(chartGraphics, new Rectangle2D.Float(0, 0, width, height));
  return chartImage;
}

代码示例来源:origin: mikaelhg/openblocks

public ChartPanel getOutputPanel() {
  //we return a copy of the chart because we only want to show the
  //legend in the larger view of the graph
  //not the small runtime graph block view
  JFreeChart newChart = new JFreeChart(chart.getPlot());
  newChart.getLegend().setPosition(RectangleEdge.TOP);
  newChart.getLegend().setPadding(5, 5, 5, 5);
  newChart.setBackgroundPaint(background);
  output = new ChartPanel(newChart);
  return output;
}

代码示例来源:origin: mikaelhg/openblocks

public ChartPanel getOutputPanel() {
  //we return a copy of the chart because we only want to show the
  //legend in the larger view of the graph
  //not the small runtime graph block view
  JFreeChart newChart = new JFreeChart(chart.getPlot());
  newChart.getLegend().setPosition(RectangleEdge.TOP);
  newChart.getLegend().setPadding(5, 5, 5, 5);
  newChart.setBackgroundPaint(background);
  output = new ChartPanel(newChart);
  return output;
}

代码示例来源:origin: com.atlassian.confluence.extra.chart/chart-plugin

public static void setDefaults(JFreeChart chart)
{
  chart.setBackgroundPaint(ChartDefaults.transparent);
  chart.setBorderVisible(false);
  chart.getPlot().setNoDataMessage("No Data Available");
  setupPlot(chart.getPlot());
  ChartUtil.setupTextTitle(chart.getTitle());
  ChartUtil.setupLegendTitle(chart.getLegend());
}

代码示例来源:origin: bcdev/beam

private void setPlotMessage(String messageText) {
  chart.getXYPlot().clearAnnotations();
  TextTitle tt = new TextTitle(messageText);
  tt.setTextAlignment(HorizontalAlignment.RIGHT);
  tt.setFont(chart.getLegend().getItemFont());
  tt.setBackgroundPaint(new Color(200, 200, 255, 50));
  tt.setFrame(new BlockBorder(Color.white));
  tt.setPosition(RectangleEdge.BOTTOM);
  XYTitleAnnotation message = new XYTitleAnnotation(0.5, 0.5, tt, RectangleAnchor.CENTER);
  chart.getXYPlot().addAnnotation(message);
}

代码示例来源:origin: senbox-org/snap-desktop

private void setPlotMessage(String messageText) {
  chart.getXYPlot().clearAnnotations();
  TextTitle tt = new TextTitle(messageText);
  tt.setTextAlignment(HorizontalAlignment.RIGHT);
  tt.setFont(chart.getLegend().getItemFont());
  tt.setBackgroundPaint(new Color(200, 200, 255, 50));
  tt.setFrame(new BlockBorder(Color.white));
  tt.setPosition(RectangleEdge.BOTTOM);
  XYTitleAnnotation message = new XYTitleAnnotation(0.5, 0.5, tt, RectangleAnchor.CENTER);
  chart.getXYPlot().addAnnotation(message);
}

代码示例来源:origin: com.atlassian.jira/jira-api

public static void setDefaults(JFreeChart chart, final I18nHelper i18nHelper)
{
  chart.setBackgroundPaint(Color.WHITE);
  chart.setBorderVisible(false);
  chart.getPlot().setNoDataMessage(i18nHelper.getText("gadget.charts.no.data"));
  setupPlot(chart.getPlot());
  ChartUtil.setupTextTitle(chart.getTitle());
  ChartUtil.setupLegendTitle(chart.getLegend());
}

代码示例来源:origin: tflobbe/solrmeter

private Component createChartPanel() {
  PiePlot plot = new PiePlot(pieDataset);
  
  JFreeChart chart = new JFreeChart(
      I18n.get("statistic.pieChartPanel.title"),
      null, plot, true);
  chart.getLegend().setPosition(RectangleEdge.RIGHT);
  
  ChartPanel chartPanel = new ChartPanel(chart);
  
  chartPanel.setBorder(CHART_BORDER);
  chartPanel.setMinimumDrawHeight(0);
  chartPanel.setMinimumDrawWidth(0);
  chartPanel.setMaximumDrawHeight(Integer.MAX_VALUE);
  chartPanel.setMaximumDrawWidth(Integer.MAX_VALUE);
  
  return chartPanel;
}

代码示例来源:origin: superad/pdf-kit

private  void  initDefaultPlot(JFreeChart  chart,DefaultCategoryDataset dataSet){
  //设置公共颜色
  chart.getTitle().setFont(FontUtil.getFont(Font.PLAIN, 15)); // 设置标题字体
  chart.getLegend().setItemFont(FontUtil.getFont(Font.PLAIN, 13));// 设置图例类别字体
  chart.setBackgroundPaint(Color.white);// 设置背景色
  CategoryPlot plot = chart.getCategoryPlot();
  plot.setNoDataMessage("无对应的数据。");
  plot.setNoDataMessageFont(FontUtil.getFont(Font.PLAIN, 13));//字体的大小
  plot.setNoDataMessagePaint(Color.RED);//字体颜色
  //设置自定义颜色
  initPlot(chart,dataSet);
}

代码示例来源:origin: org.jboss.seam/jboss-seam-pdf

@Override
public JFreeChart createChart(FacesContext context)
{
 JFreeChart chart;
 if (!getIs3D())
 {
   chart = ChartFactory.createLineChart(getTitle(), getDomainAxisLabel(), getRangeAxisLabel(), (CategoryDataset) dataset, plotOrientation(getOrientation()), getLegend(), false, false);
 }
 else
 {
   chart = ChartFactory.createLineChart3D(getTitle(), getDomainAxisLabel(), getRangeAxisLabel(), (CategoryDataset) dataset, plotOrientation(getOrientation()), getLegend(), false, false);
 }
 configureTitle(chart.getTitle());
 configureLegend(chart.getLegend());
 return chart;
}

相关文章