Disable hover on HighCharts

后端 未结 10 740
长情又很酷
长情又很酷 2021-02-03 21:03

I have building a pie chart using HighCharts library, and here is my chart:

 // http://jsfiddle.net/t2MxW/20890/

    var chart = new Highcharts.Chart({
                 


        
相关标签:
10条回答
  • 2021-02-03 21:44

    As specified in the accepted answer, you need to set

     tooltip: { enabled: false }
    

    Note - you must specify this as a property of your Highcharts.Options object (i.e. your chart options object, not a property of your series). So, either specify it in the JSON that you pass into your Highcharts.Chart object, or specify it as a property of a Highcharts.Options object that you explicitly create, before you pass it to you Highcharts.Chart

    See https://api.highcharts.com/highcharts/tooltip.enabled

    0 讨论(0)
  • 2021-02-03 21:48

    In order to completely turn off tooltip and hover effects on a chart, it is needed to turn off the tooltip, disable hover state and set inactive data opacity to 100%.

    This answer is based on previous answers and shows a complete solution to the problem.

    This is the configuration which turns off the hover and tooltip effects:

      series: {
        states: {
          hover: {
            enabled: false
          },
          inactive: {
            opacity: 1,
          }
        }
      },
      tooltip: {
        enabled: false
      }
    
    0 讨论(0)
  • 2021-02-03 21:52

    The title of the question is about disabling hovering, so in case anyone else finds themselves here for that purpose, I'll elaborate on @SergeyB's answer.

    There are a few options that affect how mouse hovering changes a series' styling. They each have different effects depending on the series type. I'll talk about line and pie series here, but generally, you can look under plotOptions.<seriesType>.states.hover for styling applied to the currently hovered series and plotOptions.<seriesType>.states.inactive for styling applied to the non-hovered series (e.g. plotOptions.pie.states.hover). None of these options affect the tooltip styling.

    plotOptions.series.states.inactive

    plotOptions.series.states.inactive affects the styling applied to all series that aren't currently being hovered over. To prevent them from fading into the background, set plotOptions.series.states.inactive.opacity to 1.

    var chartOptions = {
        // ...
        plotOptions: {
            series: {
                states: {
                    inactive: {
                        opacity: 1,
                    },
                },
            },
        },
    }
    

    jsFiddle for line

    jsFiddle for pie

    plotOptions.series.states.hover

    plotOptions.series.states.hover affects the styling applied to the series that's being hovered over. For example, for a line series, the default is to thicken the line width and apply a halo to the nearest point.

    To disable any styling of a currently hovered line series, set plotOptions.series.states.hover.enabled to false.

    var chartOptions = {
        // ...
        chart: {
            type: "line",
        },
        plotOptions: {
            series: {
                states: {
                    hover: {
                        enabled: false,
                    },
                },
            },
        },
    }
    

    jsFiddle

    Unfortunately, if we set this on a pie series, this will make the hovered slice fade into the background with the rest of the inactive slices (see this jsFiddle for an example). If we want to remove all hover styling without affecting the inactive styling, we can set plotOptions.series.states.hover.halo.size to 0 (which removes the halo) and plotOptions.pie.states.hover.brightness to 0 (which removes the brightening effect). Note that since brightness is specific to pie series, it's documented under plotOptions.pie instead of plotOptions.series (though it worked for me even when I added it under plotOptions.series).

    var chartOptions = {
        // ...
        chart: {
            type: "pie",
        },
        plotOptions: {
            series: {
                states: {
                    hover: {
                        halo: {
                            size: 0,
                        },
                        // this worked for me even though it's not
                        // documented under plotOptions.series:
                        //brightness: 0,
                    },
                },
            },
            pie: {
                states: {
                    hover: {
                        brightness: 0,
                    },
                },
            },
        },
    }
    

    jsFiddle

    plotOptions.series.stickyTracking

    If you're using a line or area series, you may have noticed that as soon as you hover over the chart, even if you're not touching a series, the nearest series will receive hover styling and the rest will receive inactive styling. This is because plotOptions.series.stickyTracking is true by default for line and area series. If you set plotOptions.series.stickyTracking to false, hover and inactive styling will only be applied while you're hovering over a line.

    var chartOptions = {
        // ...
        chart: {
            type: "line",
        },
        plotOptions: {
            series: {
                stickyTracking: false,
            },
        },
    }
    

    jsFiddle

    plotOptions.series.enableMouseTracking

    As @ninedozen noted, you can completely disable all responsive interactions based on mouse movement by setting plotOptions.series.enableMouseTracking to false. Note that this will also disable tooltips in addition to hover/inactive styling.

    Options scope

    To apply these options to all series in the entire chart, place them under plotOptions.series. To apply them only to certain series types (or if the option is specific to a certain series), place them under plotOptions.<seriesType>. To apply them to a specific series, place them inside that series' options.

    var chartOptions = {
        series: [
            {
                name: "series1",
                type: "line",
                data: [...],
                // these options will only apply to series1, not series2 or series3
                states: {...},
            },
            {
                name: "series2",
                type: "line"
                data: [...],
            },
            {
                name: "series3",
                type: "pie"
                data: [...],
            }
        ],
        plotOptions: {
            // these options will apply to all series in the chart
            series: {states: {...}},
            // these options will only apply to series of type line
            // i.e. series1 and series2
            line: {states: {...}}
        }
    }
    
    0 讨论(0)
  • 2021-02-03 21:53

    you can simply disable it by setting the option

    tooltip:{
       enabled: false
    }
    
    0 讨论(0)
提交回复
热议问题