Search code examples
javascriptvisualizationecharts

Configuring an ECharts themeRiver type chart


I am having trouble with some advanced configuration of an ECharts themeRiver chart.

You can see my implementation here, and a codepen is attached below.

Here are my questions:

  1. How can I remove the legends that are are all bunched up on the left (because all initial values are 0 or small)?
  2. How can I increase the number of ticks (interval:0 seems to not have an effect).
  3. How can i format the number shown at the top of the axis tooltip (the year) so it has no decimal fraction and not thousands separator (same as I managed to do for the axis tick marks)?
  4. How can i apply the Decal Patern option shown in the demo?

Thanks you!

echarts option object(codepen here. The Data objects are abbreviated here but available in codepen):

option = {
  tooltip: {
    trigger: 'axis',
    axisPointer: {
      type: 'line',
      lineStyle: {
        color: 'rgba(0,0,0,0.2)',
        width: 5,
        type: 'solid'
      }
    }
  },
  legend: {
    data: [...]
  },
  singleAxis: {
    min: 1606,
    max: 2011,
    top: 50,
    bottom: 50,
    axisTick: {interval: 50},
    axisLabel: {
       formatter: function (value) {
            return value.toString().replace(/\B(?=(\d{3})+(?!\d))/g, "");
        }
    },
    type: 'value',
    axisPointer: {
        animation: true,
        label: {
            show: true
        }
    },
    splitLine: {
        show: true,
        lineStyle: {
            type: 'dashed',
            opacity: 0.2
        }
    }
  },
  series: [
    {
      type: 'themeRiver',
      emphasis: {
        itemStyle: {
          shadowBlur: 20,
          shadowColor: 'rgba(0, 0, 0, 0.8)'
        }
      },
      data: [...]
    }
  ]
};

Solution

    1. labels can be disabled via:
    series: [
       {
          label: {show: false}
       }
    ]
    
    1. set maximum gap between axis labels via:
    singleAxis: {
        maxInterval: 50,
    }
    
    1. tooltip can be formatted via tooltip formatter. I currently didnt manage to get line breaks into it but this is quite close:
    tooltip: {
        formatter: function(values) {
            const year = parseInt(values[0].data[0]);
            return year.toFixed() + "\n" + values.map(value => value.data[1] + " " + value.data[2]).join("\n");
        }
    }
    
    1. decal pattern can be activated via:
    myChart.setOption({
        aria: {
            enabled: true,
            decal: {show: true}
        }
    })
    

    Here is the adjusted Demo.