隐藏JFree蜘蛛图表中的标签

问题描述 投票:3回答:2

我试图使用JFree库隐藏蜘蛛图表上的所有标签。

我一直认为以下行会起作用,但是当我添加它时我收到错误。

webPlot.setLabelGenerator(null);

我的代码:

private static JFreeChart createSpiderChart(DefaultCategoryDataset dataset) {
    SpiderWebPlot webPlot = new SpiderWebPlot(dataset);

    Font labelFont = new Font("Arial", Font.BOLD, 10);

    CategoryToolTipGenerator tooltipGenerator = new StandardCategoryToolTipGenerator();

    tooltipGenerator.generateToolTip(dataset, 1, 0);       

    Color back_color = new Color(255,255,255,0);
    webPlot.setOutlineVisible(false);
    webPlot.setLabelFont(labelFont);       

    webPlot.setSeriesPaint(0, java.awt.Color.decode("#000000"));
    webPlot.setSeriesPaint(1, java.awt.Color.decode("#209ad4"));
    webPlot.setBackgroundPaint(back_color);

    webPlot.setLabelGenerator(null); /** THIS THROWS AN ERROR **/

    JFreeChart chart = new JFreeChart("", null /* JFreeChart.DEFAULT_TITLE_FONT */, webPlot, false);
    chart.setBorderVisible(false);

    ImageIcon icon = new ImageIcon("C:\\TestCharts\\report-assets\\chart-bg.gif");
    chart.setBackgroundImage(icon.getImage());

    return chart;       
}

我的错误:

java.lang.IllegalArgumentException: Null 'generator' argument.
    at org.jfree.chart.util.ParamChecks.nullNotPermitted(ParamChecks.java:65)
    at org.jfree.chart.plot.SpiderWebPlot.setLabelGenerator(SpiderWebPlot.java:993)
    at JavaAgent.createSpiderChart(Unknown Source)
    at JavaAgent.NotesMain(Unknown Source)
    at lotus.domino.AgentBase.runNotes(Unknown Source)
    at lotus.domino.NotesThread.run(Unknown Source)

任何想法和提前谢谢。

java swing charts web-crawler jfreechart
2个回答
1
投票

setLabelGenerator() API非常清楚:null not permitted。您可以尝试在columnKey中为CategoryDataset使用不同数量的空格。


1
投票

适合我(JFreeChart 1.5.0):

webplot.setLabelGenerator(new StandardCategoryItemLabelGenerator() {
  @Override
  public String generateColumnLabel(CategoryDataset dataset, int column) {
    return "";
  }
});
© www.soinside.com 2019 - 2024. All rights reserved.