Notification texts go here Contact Us Buy Now!

How to have line labels on both sides of a Y-axis?

How to have line labels on both sides of a Y-axis?

In echarts, there seems to be no inbuilt support for this but the following methods can be used to achieve this:

  • Example 1:

    Use the regular endLabel for the end of the series and a markPoint with symbolSize 0 on top of the first datapoint as start label.

    const dataset = [[150, 230, 224, 218, 135, 147, 260], [230, 160, 70, 135, 147, 140, 110], [135, 147, 260, 340, 290, 110, 90]];
    const entity = ['Mangolia', 'Mitzerland','Torsica'];
    
    const seriesList = [];
    for (const index in dataset) {
      const row = dataset[index];
      seriesList.push({
        type: 'line',
        data: row,
        endLabel: {
          show: true,
          formatter: () => 'end label = ' + row[row.length - 1]
        },
        markPoint: {
          symbolSize: 0,
          label: {position: 'left'},
          data: [{coord: [0, row[0]], value: entity[index]}]
        }
      });
    }
    
    option = {
      xAxis: {
        type: 'category',
        data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
      },
      yAxis: {
        type: 'value'
      },
      series: seriesList
    };
    
  • Example 2:

    You can use endLabel to show label at end and Markpoint with formatter to show series name and start value.

    markPoint: {
      symbolSize: 0,
      label: {
        position: 'left', 
        formatter: (params)=> `${params.value} = ${params.data.coord[1]}`
      },
      data: [{coord: [0, row[0]], value: entity[index]}]
    }
    endLabel: {
      show: true,
      formatter: (params) => 'end label = ' + row[row.length - 1]
    }
    

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.