Skip to content
Advertisement

Unable to display center text in ring chart

I am trying to generate a donut or ring chart using jfree chart library. Ringchart was generated successfully but only the problem is centered text inside ring was not displaying. The following is the sample snippet. chart generation code

JavaScript

And centered text related code is like below

JavaScript

I am using jfreechart verison 1.5.0

Advertisement

Answer

It’s not clear where your fragment is going awry, but this minimal complete example gives the expected result. As an aside, note the use of Font.BOLD for clarity and the use of deriveFont() to minimize the risk of an unfortunate font substitution; see also *Initial Threads*.

JavaScript

ring plot with value

I tried pie.setCenterText("Vijay");

Instead of CenterTextMode.VALUE; specify CenterTextMode.FIXED:

JavaScript

ring plot with fixed text

The above code is not setting any value if the first dataset value is zero.

Correct. RingPlot::drawItem() ignores center text unless values exceed the rendering threshold; you can specify a value that passes the threshold yet displays correctly when formatted:

JavaScript

ring plot zero

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement