How to use echarts visualMap to color Line depending on Y-Axis Value or category

0vvn1miw  于 2022-11-03  发布在  Echarts
关注(0)|答案(5)|浏览(259)

How can I use the visualMap correctly to higlight a Line or AreaChart depending on a certain Y Axis VAlue. How can I set up ranges?

Another question, how can I use the visualMap to change the behaviour (color) of certain data depending on the catergory. How could I give my dataseries a parameter like "red" or "green" and use that with the visualMap?

With the follwoing code I can change the color of the data points via a certain category:

<html>
<head>

    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/echarts/4.1.0/echarts.min.js"></script>
</head>
<body>
<div id="main_chart" style="width: 1200px;height:600px;"></div>

<script type="text/javascript">

    // based on prepared DOM, initialize echarts instance
    var myChart = echarts.init(document.getElementById('main_chart'));

    var app = {};
    option = null;
    option = {
        xAxis: {
            type: 'value'

        },
        yAxis: {
            type: 'value'
        },
        visualMap: {
        show: true,
        dimension: 2,
        categories: ['Test'],
        inRange: {

                color: 'red'
            },
            outOfRange: {
                color: 'green'

            }       
    },
        series: [{
            data: [[1,37,'Test'],[2,36,'Hallo'],[3,36,'Hallo']],

            type: 'line',
            areaStyle: {}    

        }]
    };

    if (option && typeof option === "object") {
        myChart.setOption(option, true);
    }
</script>

</body>
</html>

How can I use this to change the color of the connecting lines?

6jjcrrmo

6jjcrrmo1#

(1) Depending on Y axis value: https://ecomfe.github.io/echarts-examples/public/editor.html?c=line-aqi probably helps.

(2) Depending on categories: firstly, put category info into each iitem of series.data , and then use visualMap like https://ecomfe.github.io/echarts-examples/public/editor.html?c=parallel-nutrients .

pdsfdshx

pdsfdshx2#

None of the links work @100pah

n1bvdmb6

n1bvdmb63#

Was looking for the links as well, they don't work

gorkyyrv

gorkyyrv5#

currently visualMap over Y-axis seems buggy to me, see https://codesandbox.io/s/dreamy-neumann-b8iz9?file=/src/App.js

  1. if use the pieces around lines#47, it throws error, I have to hack it around by add lower bound and upper bound stops.
  2. Threshold value between stops have to depend on canvas size and line width, or else you will get a buggy "double color line". Try adjust the threshold range input in the example.

I wish there exists a lower level API to draw different line segment based on individual data item, instead of the current linear gradient solution.

相关问题