简体   繁体   English

隐藏JFree蜘蛛图表中的标签

[英]Hide Labels from JFree Spider Chart

I am trying to hide all labels on my Spider Chart using the JFree library. 我试图使用JFree库隐藏蜘蛛图表上的所有标签。

I was lead to believe that the following line would work but I am getting an error when I add it. 我一直认为以下行会起作用,但是当我添加它时我收到错误。

webPlot.setLabelGenerator(null);

My code: 我的代码:

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;       
}

My Error: 我的错误:

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)

Any ideas and Thanks in advance. 任何想法和提前谢谢。

The setLabelGenerator() API is pretty clear: null not permitted . setLabelGenerator() API非常清楚: null not permitted You can try using different numbers of spaces for the columnKey in your CategoryDataset . 您可以尝试在CategoryDatasetcolumnKey使用不同数量的空格。

Works for me (JFreeChart 1.5.0): 适合我(JFreeChart 1.5.0):

webplot.setLabelGenerator(new StandardCategoryItemLabelGenerator() {
  @Override
  public String generateColumnLabel(CategoryDataset dataset, int column) {
    return "";
  }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM