简体   繁体   English

如何使用Echarts(JS)为折线图的每个点显示工具提示

[英]How display tooltip for each point of a line chart using Echarts (JS)

I have a question about the Echarts library https://ecomfe.github.io/echarts-doc/public/en/index.html . 我有一个有关Echarts库的问题https://ecomfe.github.io/echarts-doc/public/en/index.html

I'm using Echarts to draw a line chart from a series of points (x,y) and I want to display the coordinates (x,y) of each point in the drawn line chart when the user hovers over the mouse on the point as tooltip the problem that I found is that I can display only for the points given in entered and not for the totality of line that is to say I cannot display the coordinates of a point between two successive points given in input. 我正在使用Echarts从一系列点(x,y)绘制折线图,​​并且当用户将鼠标悬停在该点上时,我想在绘制的折线图中显示每个点的坐标(x,y)作为工具提示,我发现的问题是,我只能显示输入中给定的点,而不能显示整个线,也就是说,我无法显示输入中给定的两个连续点之间的点的坐标。

how can I display the tooltip for each point of the graph as tooltip? 如何将图形的每个点的工具提示显示为工具提示?

I have used this JSON object as an option object to pass it as a parameter to the setOption method. 我已将此JSON对象用作选项对象,将其作为参数传递给setOption方法。

       {
        tooltip: {
            type: 'item'
        },
        grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true,
            show: true,
            backgroundColor: "#fff",

        },
        toolbox: {
            feature: {
                dataZoom: {
                    title: {
                        zoom: "zoom by rectangle",
                        back: "undo zooming"
                    }
                }
            }
        },
        xAxis: {
            type: 'value',
        },
        yAxis: {
            type: 'value',
            triggerEvent: true
        },
        dataZoom: [{
                type: 'inside',
                xAxisIndex: [0],
                moveOnMouseMove: true,
            },
            {
                type: 'inside',
                yAxisIndex: [0],
                moveOnMouseMove: true,
            }
        ],
        series: [{
            name: "line1",
            data: [
                [1.5, 10],
                [5, 7],
                [8, 8],
                [12, 6],
                [11, 12],
                [16, 9],
                [14, 6],
                [17, 4],
                [19, 9]
            ],
            type: 'line',
        }]
    };

A solution to your problem would be to change the tooltip option to set the type to cross . 解决您的问题的方法是更改​​工具提示选项以将类型设置为cross It would look something like this - 看起来像这样-

tooltip: {
        axisPointer: {
                type: 'cross'
            }
    }

This type of display is particularly helpful when you are using orthometric axis as it displays the location of the mouse. 当您使用正交轴时,这种类型的显示特别有用,因为它显示了鼠标的位置。

Echarts Docs for tooltip: https://ecomfe.github.io/echarts-doc/public/en/option.html#tooltip.axisPointer.type 用于工具提示的Echarts文档: https ://ecomfe.github.io/echarts-doc/public/en/option.html#tooltip.axisPointer.type

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

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