XChart icon indicating copy to clipboard operation
XChart copied to clipboard

Format Y axis labels

Open johannescarlen opened this issue 6 years ago • 4 comments

It is possible to change the decimal pattern format of the y-axis, however it would be great if it also was possible to override the whole label formatting. This could also help solving the use of time / date in the y-axis

johannescarlen avatar Mar 27 '18 12:03 johannescarlen

You can use custom axis tick calculator. See #217

hakantkn avatar May 24 '18 11:05 hakantkn

Yeah, we have setYAxisDecimalPattern() but no setYAxisDatePattern() like we have for the X-Axis. Why would you want dates in the y-axis though?

You can always use something like this:

      Map<Object, Object> customYAxisTickLabelsMap = new HashMap<>();
      customYAxisTickLabelsMap.put(1.0, "max c");
      customYAxisTickLabelsMap.put(6.0, "max b");
      customYAxisTickLabelsMap.put(9.0, "max a");

      chart.setCustomYAxisTickLabelsMap(customYAxisTickLabelsMap);

or

      double[] xData = xySeries.getXData();
      Map<Object, Object> customTickLabelsMap = new HashMap<>();
      SimpleDateFormat sdf = new SimpleDateFormat("MM-dd");

      for (double d : xData) {
        Date date = new Date((long) d);
        String label = sdf.format(date);
        customTickLabelsMap.put(d, label);
      }

      chart.setCustomXAxisTickLabelsMap(customTickLabelsMap);

but for the y-axis of course.

timmolter avatar Dec 27 '19 08:12 timmolter

the new packet version 3.6.1 has no method setYAxisDecimalPattern() , which version we can use it

limitlesslive avatar Mar 11 '20 08:03 limitlesslive

Yeah, we have setYAxisDecimalPattern() but no setYAxisDatePattern() like we have for the X-Axis. Why would you want dates in the y-axis though?

You can always use something like this:

      Map<Object, Object> customYAxisTickLabelsMap = new HashMap<>();
      customYAxisTickLabelsMap.put(1.0, "max c");
      customYAxisTickLabelsMap.put(6.0, "max b");
      customYAxisTickLabelsMap.put(9.0, "max a");

      chart.setCustomYAxisTickLabelsMap(customYAxisTickLabelsMap);

or

      double[] xData = xySeries.getXData();
      Map<Object, Object> customTickLabelsMap = new HashMap<>();
      SimpleDateFormat sdf = new SimpleDateFormat("MM-dd");

      for (double d : xData) {
        Date date = new Date((long) d);
        String label = sdf.format(date);
        customTickLabelsMap.put(d, label);
      }

      chart.setCustomXAxisTickLabelsMap(customTickLabelsMap);

but for the y-axis of course.

the new packet version 3.6.1 has no method setYAxisDecimalPattern() , which version we can use it

limitlesslive avatar Mar 11 '20 08:03 limitlesslive