Notification texts go here Contact Us Buy Now!

Echarts3 (baidu) colored round in tooltip

  • One way to solve this problem is to return custom HTML in your tooltip formatter:
    var formatTooltipLine = function(color) {
        return "<span style='display:inline-block;width:10px;height:10px;border-radius:50%;background-color:" + color + ";margin-right:5px;'></span><span>line text</span>";
    }
    
    var formatter = function() {
        // custom title
        var lines = ["<b>2016</b>"];
    
        // custom lines
        ["red", "orange"].forEach(function(color) {
            lines.push(formatTooltipLine(color));
        });
    
        return lines.join("<br>");
    }
    
  • Another approach is to use ECharts' user-defined tooltip feature:
    tooltip : {
        trigger: 'axis',
        axisPointer: {
            animation: true
        },
        formatter: function (params) {
            var colorSpan = color => '<span style="display:inline-block;margin-right:5px;border-radius:10px;width:9px;height:9px;background-color:' + color + '"></span>';
            let rez = '<p>' + params[0].axisValue + '</p>';
            //console.log(params); //quite useful for debug
            params.forEach(item => {
                //console.log(item); //quite useful for debug
                var xx = '<p>' + colorSpan(item.color) + ' ' + item.seriesName + ': ' + item.data + '%' + '</p>'
                rez += xx;
            });
    
            return rez;
        }
    },
    
  • ECharts already sends the marker html in params of each series with specific color. Here's an example for a line chart:
    {
         formatter : (args) => {
           let tooltip = `<p>${args[0].axisValue}</p> `;
    
           args.forEach(({ marker, seriesName, value }) => {
                 value = value || [0, 0];
                 tooltip += `<p>${marker} ${seriesName} — ${value[1]}</p>`;
           });
    
           return tooltip;
         }
       }
    

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.