在响应式移动版本的图表底部显示 Highcharts 工具提示
我有这个折线图,在图表右侧显示所有系列的共享工具提示。然而,在移动视图中,它看起来很丑,因为一半的屏幕空间被图表占据,一半被工具提示占据。在移动响应式布局中,我希望图表占据整个屏幕宽度并共享工具提示转到图表底部。我怎样才能实现这个目标?
我写了下面的代码,它可以在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用响应式规则并为小屏幕定义不同的选项。例如:
现场演示: 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:
Live demo: https://jsfiddle.net/BlackLabel/w4qsjpy7/
API Reference: https://api.highcharts.com/highcharts/responsive.rules