Search code examples
javaswingchartsweb-crawlerjfreechart

Hide Labels from JFree Spider Chart


I am trying to hide all labels on my Spider Chart using the JFree library.

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.


Solution

  • The setLabelGenerator() API is pretty clear: null not permitted. You can try using different numbers of spaces for the columnKey in your CategoryDataset.