Question

I'm trying to set the font of my chart's x-axis in this manner:

CategoryPlot plotCat =  (CategoryPlot) chart.getPlot();
CategoryAxis xAxis = plotCat.getDomainAxis();
Font font = new Font("SanSerif", Font.STRIKETHRU, 3);
//or Font font = new Font(Font.FontFamily.HELVETICA, 3, Font.BOLD);
xAxis.setTickLabelFont(font);
//or xAxis.setLabelFont(font);

This is the solution that I keep reading about but it doesn't work for me. I keep getting the messages: The method setTickLabelFont(Font) in the type Axis is not applicable for the arguments (Font) and The method setLabelFont(Font) in the type Axis is not applicable for the arguments (Font).

What is going on that is not allowing me to apply a different font to these labels?

It's possible that it's because I'm importing com.itextpdf.text.Font instead of java.awt.Font, but com.itextpdf.text.Font is necessary to set the font of other elements in the PDF. How do I resolve these differences if this is indeed the cause of the problem?

Was it helpful?

Solution

JFreeChart requires java.awt.Font. If you are already importing com.itextpdf.text.Font in your source file, then you'll have to use the fully qualified class name to create a Font for JFreeChart, for example:

java.awt.Font font = new java.awt.Font(Font.SERIF, Font.PLAIN, 10);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top