0

I have 3 variables in Y axis and I am trying to get the name of the axis according to value which I look for.

enter image description here.

Variables are attached here. I can get the value of the variable with label, but I can't get the name of variable.

enter image description here.

I want to write the name of the variable in front of the label. How can I find it? My code looks like:

public void chartMouseMoved(ChartMouseEvent event){
   ChartEntity chartEntity = event.getEntity();
   if ( chartEntity instanceof XYItemEntity) {
      XYItemEntity xyItemEntity = (XYItemEntity) chartEntity;
      XYDataSet xyDataSet = xyItemEntity.getDataset();

      double xValue = xyDataSet .getXValue(xyItemEntity.getSeriesIndex(), xyItemEntity.getItem());
      double yValue = xyDataSet .getYValue(xyItemEntity.getSeriesIndex(), xyItemEntity.getItem());

      this.xCrosshair.setValue(xValue);
      this.yCrosshair.setValue(yValue);


      label.setText(String.format("%.2f, yValue));
      label.setSize(label.getPreferredSize());

      }
   }
}
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
shnnens
  • 11
  • 2
  • Your question is confusing, at least to me. Please consider giving us a more and clear explanation of your code and your problem. – Hovercraft Full Of Eels Feb 09 '22 at 13:06
  • The first picture is about the axis of Y, and the second picture is the value of one of these axis. I can get the value of the axis but I can't get the variable name of the axis. How can I get it? When I click on the graph line on the chart, I want to get the X and Y axises labels. – shnnens Feb 09 '22 at 13:08
  • See also [How can I get mouse cursor value in Java Chart?_](https://stackoverflow.com/q/71018827/230513) – trashgod Feb 09 '22 at 23:27

1 Answers1

1

An XYPlot has methods to access the axes used to construct the chart. Starting from this complete, two-axis example, the following loop prints the names of the range axes to the console:

for (int i = 0; i < plot.getRangeAxisCount(); i++) {
    System.out.println(plot.getRangeAxis(i).getLabel());
}

Console:

Meters
Feet

image

trashgod
  • 203,806
  • 29
  • 246
  • 1,045