0

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.

Screenshot

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
amit gupta
  • 11
  • 1
  • 2
    Welcome 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 Answers1

2

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("");

image

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 valueVisible and draw conditionally; add mutators, invoking fireChangeEvent() 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
  • 203,806
  • 29
  • 246
  • 1,045