简体   繁体   English

系列中的Echart图标工具提示

[英]Echart icon in series tooltip

So i have the following configuration: 所以我有以下配置:

  const frequencyChartoption = {
            title: {},
            tooltip: {},
            legend: {
                data: ['Frekvens', 'Vigtighed']
            },
            xAxis: {
                type: 'category',
                data: ['marker_01', 'marker_02'],
                axisLabel: {
                    formatter: function (value) {
                        return '{' + value + '| }\n{value|}';
                    },
                    margin: 20,
                    rich: {
                        value: {
                            lineHeight: 30,
                            align: 'center'
                        },
                        marker_01: {
                            height: 20,
                            align: 'center',
                            backgroundColor: {
                                image: icons.marker_01
                            }
                        },
                        marker_02: {
                            height: 20,
                            align: 'center',
                            backgroundColor: {
                                image: icons.maker_02
                            }
                        },

                    }

                }
            },
            yAxis: {},
            series: [{
                name: 'Frekvens',
                type: 'bar',
                data: frequencyChartFrequencyScore,
                tooltip: icons.marker_01,
                itemStyle: {
                    normal: {
                        color: colors[0],
                        label: {
                            interval: 5,
                            show: true,
                            position: 'top',
                            formatter: '\n{c}'
                        }
                    }
                }
            },
                {
                    name: 'Vigtighed',
                    type: 'bar',
                    data: frequencyChartImportance,
                    itemStyle: {
                        normal: {
                            color: colors[1],
                            label: {
                                show: true,
                                position: 'top',
                                formatter: '\n{c}'
                            }
                        }
                    }
                }
            ]
        };

Now as you can see i am using two images as my xAxis 现在您可以看到我正在使用两个图像作为我的xAxis

Now i wish to make these show up on my tooltip when i hover over the chart. 现在,当我将鼠标悬停在图表上时,我希望使这些显​​示在工具提示上。 However i am not quite sure how to do that and was hoping some of you might be able to help? 但是我不太确定该怎么做,希望你们中的一些人能够提供帮助?

Simply stated, a series may have a tooltip but the tooltip must be listed as an object with an identifying trigger (see tooltip documentation). 简而言之,一个series可能有一个工具提示,但是该工具提示必须作为带有标识trigger的对象列出(请参阅tooltip文档)。

series: [{
    name: 'Frekvens',
    type: 'bar',
    data: frequencyChartFrequencyScore,
    tooltip: {
        show: true,
        trigger: 'axis',
        formatter: (params) => {
            // see tooltip.formatter for details
            // you want to focus on the 'marker' property
            return params[0].name;
        }
    }
}]

With this in mind, you can set two variables and print them as need be within the output of your tooltip. 考虑到这一点,您可以设置两个变量,并根据需要在工具提示的输出中进行打印。 See the additional example below (from CodePen ). 请参见下面的其他示例(来自CodePen )。

var myChart = echarts.init(document.getElementById("main"));

// specify chart configuration item and data
var option = {
  title: {
    text: "ECharts entry example"
  },
  tooltip: {
    show: true,
    trigger: "axis",
    backgroundColor: 'rgba(0, 0, 0, 0.8)',
    formatter: (params) => {
      // create new marker
      var icon0 = `<span data-tooltip="minimum" style="border-left: 2px solid #fff;display: inline-block;height: 12px;margin-right: 5px;width: 20px;"><span style="background-color:${params[0].color};display: block;height: 4px;margin-top: 4px;width: 20px;"></span></span>`;
      var icon1 = `<span data-tooltip="implied-high" style="background-color:rgba(255,255,255,.75);border-radius: 2px;display: inline-block;height: 12px;margin-right:5px;width: 20px;"><span style="background-color:${params[0].color};border: 1px solid ${params[0].color};border-radius:50%;display:block;height:6px;margin-left:7px;margin-top:3px;width:6px;"></span></span>`;
      console.log("params", params, params[0].name);
      return `${icon0} ${params[0].name}
              ${icon1} ${params[0].value}`;
    },
    textStyle: {
      fontWeight: 'bold',
      fontSize: 18
    }
  },
  legend: {
    data: ["Sales"]
  },
  xAxis: {
    data: ["shirt", "cardign", "chiffon shirt", "pants", "heels", "socks"]
  },
  yAxis: {},
  series: [
    {
      name: "Sales",
      type: "bar",
      data: [5, 20, 36, 10, 10, 20]
    }
  ]
};

// use configuration item and data specified to show chart
myChart.setOption(option);

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

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