简体   繁体   English

Echarts3(百度)工具提示中的彩色圆形

[英]Echarts3 (baidu) colored round in tooltip

Echarts3 (baidu) colored round in tooltip Echarts3(百度)工具提示中的彩色圆形

By default the tooltip has rounds of the same colour as graph, like this:默认情况下,工具提示具有与图形相同颜色的圆形,如下所示:

http://echarts.baidu.com/gallery/editor.html?c=candlestick-brush http://echarts.baidu.com/gallery/editor.html?c=candlestick-brush

But if I customize the tooltip it removes the colour coded round like in this example:但是如果我自定义工具提示,它会删除颜色编码的圆形,如本例所示:

https://ecomfe.github.io/echarts/doc/example/tooltip.html#-en https://ecomfe.github.io/echarts/doc/example/tooltip.html#-en

Is there a way to use custom tooltip and put the colour round back.有没有办法使用自定义工具提示并将颜色放回原处。

在此处输入图片说明

Here is another way to explain it.这是解释它的另一种方法。 Go to this link pie-simple and you will find charts with no coloured round.转到此链接饼图简单,您会找到没有彩色圆形的图表。

delete the following line:删除以下行:

formatter: "{a} <br/>{b} : {c} ({d}%)"

then press <运行> to refresh and you will see the round back.然后按<运行>刷新即可看到圆回来了。

ECharts support user-defined tooltip, include the color you wanted. ECharts 支持自定义工具提示,包含你想要的颜色。

For example you have a line chart demo like this , and you want to change the default tooltip, add % or something else after the tooltip without lose the default color.Just replace tooltip code with this code below.例如,您有一个像这样的折线图演示,并且您想更改默认工具提示,在工具提示后添加%或其他内容而不丢失默认颜色。只需将工具提示代码替换为下面的代码即可。

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;
    }        
},

with this tooltip code, you will see the original tooltip color 邮件营销: 90 become color 邮件营销: 90% , we add self-defined % to tooltip.使用这个工具提示代码,您将看到原始工具提示color 邮件营销: 90变为color 邮件营销: 90% ,我们在工具提示中添加了自定义的%

Echarts already sends the marker html in params of each series with specific color. Echarts 已经在每个系列的 params 中发送了带有特定颜色的标记 html。 To create an original looking tooltip you can simply use that like this for 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;
  }

One way to solve this is to return custom HTML in your tooltip formatter, for instance:解决此问题的一种方法是在工具提示格式化程序中返回自定义 HTML,例如:

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>");
}

Example: https://cdn.datamatic.io/runtime/echarts/3.3.0_61/view/index.html#id=117670017722819924657/0B3wq5VFn9PllSEVsQTJvcnVBZU0示例: https : //cdn.datamatic.io/runtime/echarts/3.3.0_61/view/index.html#id=117670017722819924657/0B3wq5VFn9PllSEVsQTJvcnVBZU0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM