apache / echarts

Apache ECharts is a powerful, interactive charting and data visualization library for browser
https://echarts.apache.org
Apache License 2.0
60.66k stars 19.61k forks source link

Duplicate labels on a time(year format) xAxis #9896

Open Meldanen opened 5 years ago

Meldanen commented 5 years ago

General Questions

Issue Type

Issue Details

I want to use a year format on a timeAxis, but formatting the axisLabel ends up with duplicate labels.

Expected Behavior

duplicate_labels_fixed

There shouldn't be any duplicate labels if it's a time axis.

Current Behavior

duplicate_labels

The points seem to be plotted and formatted afterwards. This means that points in the same year, are all formatted to the same label.

Online Example

Fiddle link: https://jsfiddle.net/5jyu4t6w/5/

option = {
    "xAxis" : [
      {
        "type" : "time",
        "axisLabel" : {
            formatter : function(x) {
                return echarts.format.formatTime('yyyy', x);
            }
        },
        "splitLine" : {
          "show" : false
        },
        "max" : "dataMax",
        "scale" : true,
        "offset" : 0
      }
    ],
    "yAxis" : [
      {
        "type" : "value",
         "axisLabel" : {
            formatter : function(x) {
                return (x*100) + "%";
            }
        },
        "splitLine" : {
          "lineStyle" : {
            "type" : "dashed"
          }
        },
        "offset" : 0
      }
    ],
    "series" : [
      {
        "name" : "Example line",
        "type" : "line",
        "data" : [
          [
            1577829599999,
            0.01
          ],
          [
            1609451999999,
            0.02
          ],
          [
            1640987999999,
            0.3
          ]
        ]
      },
    ]
  }

Topics

Anything Else We Need to Know

Setting the axis type to 'category' is something we considered but it's not correct

Environment

Ovilia commented 5 years ago

This is not a bug. You should probably need to check if this is the first data of a different year in formatter.

Meldanen commented 5 years ago

Hi Ovilia,

Then assume that the format is in months. In this case if two data points are in the same month, why does it not display duplicate labels (as it does in the case of years)?

Cheers, Alex

Ovilia commented 5 years ago

I think it makes sense that ECharts do the enhancement to hide duplicate labels in the future. In the meanwhile, you may use something like this in your case: https://jsfiddle.net/ovilia/k1bsuteo/6/

Meldanen commented 5 years ago

I suppose it will have to do. Thank you for providing a temporary solution. Do you have an estimate of how long this enhancement will take to be implemented?

Thanks, Meldanen

MINDoSOFT commented 5 years ago

Hi there, this feature would be very helpful for me also.

Best regards, Sergios.

MINDoSOFT commented 4 years ago

Hi @100pah ,

regarding your comment on https://github.com/apache/incubator-echarts/pull/9977 do you have an update on this ?

Thank you for your time and effort.

Best regards, Sergios.

fplusf commented 1 year ago

is there any similar approach for Y axis value? the example from your sample seems not to work with Y axis