I want to know is there any way or method to hide or disable the value in MeterPlot using JFreeChart in Java. Here's the screenshot from this example, with the value circled in yellow.
Asked
Active
Viewed 68 times
0
trashgod
- 200,320
- 28
- 229
- 974
amit gupta
- 11
- 1
-
2Welcome to Stack Overflow. Please take the [tour] to learn how Stack Overflow works and read [ask] on how to improve the quality of your question. Then [edit] your question to include the full source code you have as a [mcve], which can be compiled and tested by others. Please see: [Why is “Can someone help me?” not an actual question?](https://meta.stackoverflow.com/q/284236). Please show your attempts you have tried and the problems/error messages you get from your attempts. – Progman Jun 09 '21 at 17:17
-
I've edited the question to cite the corresponding example. – trashgod Jun 09 '21 at 19:20
1 Answers
1
As shown here, one approach is to specify a zero-sized font with an empty units string:
meterplot.setValueFont(new Font(Font.SERIF, Font.PLAIN, 0));
meterplot.setUnits("");
Alternatively, subclass MeterPlot and then either
Override
drawValueLabel()to omit rendering:MeterPlot meterplot = new MeterPlot(valuedataset){ @Override protected void drawValueLabel(Graphics2D g2, Rectangle2D area) { } };Add an attribute such as
valueVisibleand draw conditionally; add mutators, invokingfireChangeEvent()as warranted:private class MyMeterPlot extends MeterPlot { private boolean valueVisible; public MyMeterPlot(ValueDataset dataset) { super(dataset); } @Override protected void drawValueLabel(Graphics2D g2, Rectangle2D area) { if (valueVisible) { super.drawValueLabel(g2, area); } } public void setValueVisible(boolean valueVisible) { this.valueVisible = valueVisible; fireChangeEvent(); } public boolean isValueVisible() { return valueVisible; } }
For reference, changes to support value visibility have been added to version 2.0 here and back ported to the upcoming version 1.5.4 here.
trashgod
- 200,320
- 28
- 229
- 974
-
Excellent. Going forward, you can accept this answer by clicking on the [empty check mark](http://meta.stackoverflow.com/a/5235/163188) at the left. – trashgod Jun 10 '21 at 12:23