在响应式移动版本的图表底部显示 Highcharts 工具提示

发布于 2025-01-11 12:44:42 字数 1408 浏览 0 评论 0原文

我有这个折线图,在图表右侧显示所有系列的共享工具提示。然而,在移动视图中,它看起来很丑,因为一半的屏幕空间被图表占据,一半被工具提示占据。在移动响应式布局中,我希望图表占据整个屏幕宽度并共享工具提示转到图表底部。我怎样才能实现这个目标?

我写了下面的代码,它可以在 jsfiddle 上运行。

responsive: {
    rules: [{
      chartOptions: {
        chart: {
          marginRight: 0
        },
        tooltip: {
        outside: true,
          positioner: function(boxWidth, boxHeight, point) {
            var chart = this.chart; // get plotTop;

            return {
              x: chart.plotLeft + chart.plotSizeX - 100,
              y: chart.chartHeight - chart.plotTop - chart.xAxis[0].bottom + boxHeight + 50
            };
          }
        }
      },
      condition: {
        maxWidth: 640
      }
    }]
  }

https://jsfiddle.net/userMB/k790c4rw/4/

但问题是我的图表包含在一个容器 div 内,该容器 div 进一步包含在一个部分内。就像下面的代码一样:因此,工具提示没有按照我想要的方式显示在图表下方。我有什么想法可以实现这一目标吗?

<section class="section section-lg ">
    <div class="container" style="max-width: 95vw; border: 1px solid grey; min-height: 65vh;">
        <"some form">
        <div id="chart" style="min-height: 50vh;"></div>
    </div>
<section>

相同的代码在封闭的部分和 div 元素中的行为有所不同。请参阅 https://jsfiddle.net/userMB/k790c4rw/10

I have this line chart where I am showing a shared tooltip of all series on the right side of the chart. However, in the mobile view, it looks ugly because half the screen space is taken by the chart and half by the tooltip. In the mobile responsive layout, I want the chart to take the whole screen width and shared tooltip to go to the bottom of the chart. How can I achieve this?

I have written the code below and it works on jsfiddle.

responsive: {
    rules: [{
      chartOptions: {
        chart: {
          marginRight: 0
        },
        tooltip: {
        outside: true,
          positioner: function(boxWidth, boxHeight, point) {
            var chart = this.chart; // get plotTop;

            return {
              x: chart.plotLeft + chart.plotSizeX - 100,
              y: chart.chartHeight - chart.plotTop - chart.xAxis[0].bottom + boxHeight + 50
            };
          }
        }
      },
      condition: {
        maxWidth: 640
      }
    }]
  }

https://jsfiddle.net/userMB/k790c4rw/4/

But the problem is that my chart is enclosed inside a container div which is further enclosed inside a section. Like the code below: Hence, the tooltip doesn't show below the chart as I want. Any ideas how I can achieve this?

<section class="section section-lg ">
    <div class="container" style="max-width: 95vw; border: 1px solid grey; min-height: 65vh;">
        <"some form">
        <div id="chart" style="min-height: 50vh;"></div>
    </div>
<section>

And that same code behaves differently within enclosed section and div elements. see https://jsfiddle.net/userMB/k790c4rw/10

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

看透却不说透 2025-01-18 12:44:42

您可以使用响应式规则并为小屏幕定义不同的选项。例如:

  responsive: {
    rules: [{
      chartOptions: {
        chart: {
          marginRight: 0
        },
        tooltip: {
          positioner: function(boxWidth, boxHeight, point) {
            var chart = this.chart; // get plotTop;

            return {
              x: chart.plotLeft + chart.plotSizeX - 100,
              y: chart.plotTop + chart.plotSizeY - 50
            };
          }
        }
      },
      condition: {
        maxWidth: 640
      }
    }]
  }

现场演示: https://jsfiddle.net/BlackLabel/w4qsjpy7/

API 参考: https://api.highcharts.com/highcharts/responsive.rules

You can use responsive rules and define different options for small screens. For example:

  responsive: {
    rules: [{
      chartOptions: {
        chart: {
          marginRight: 0
        },
        tooltip: {
          positioner: function(boxWidth, boxHeight, point) {
            var chart = this.chart; // get plotTop;

            return {
              x: chart.plotLeft + chart.plotSizeX - 100,
              y: chart.plotTop + chart.plotSizeY - 50
            };
          }
        }
      },
      condition: {
        maxWidth: 640
      }
    }]
  }

Live demo: https://jsfiddle.net/BlackLabel/w4qsjpy7/

API Reference: https://api.highcharts.com/highcharts/responsive.rules

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文