Highcharts 问题 - 在可缩放图表中显示标签
我有一个缩放柱形图,xAxis 中有 200 多个类别。因此,当它处于初始状态(比例1:1)时,所有这些家伙都显示在X轴下方,即使我将它们垂直放置,也无法读取任何内容。我需要缩放图表以使标签可见。
这是问题的屏幕截图:
这是我的代码: http://jsfiddle.net/sherlock85/hJcQm/
是否可以调节浓度标签(也许会自动更改步骤)取决于缩放级别?
我非常感谢你的帮助。
谢谢, 安杰伊
I have a zoom column chart with more then 200 categories in xAxis. Consequently, when it is in the initial state (scale 1:1), all these guys are shown under the X axis, and it's impossible to read anything even if I place them vertically. I need to zoom the chart to make the labels visible.
Here's screenshot of the problem:
Here's my code:
http://jsfiddle.net/sherlock85/hJcQm/
Is it possible to adjust the concentration of the labels (perhaps change the step automatically) depending on a zoom level?
I would really appreciate your help.
Thanks,
Andrzej
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
按照从最简单到最困难的顺序...
由于您的类别主要是数字(例如“mir001”),因此您可以省略类别,这将阻止它们全部显示。然后他们会显示 1、2、3 等等。
或者,您可以删除类别并使用标签格式化程序。在这种情况下,您可以执行类似的操作,再次利用标签看起来是数字并递增的事实:
以上两种方法都会减少标签的数量(标签将遵循某种模式,例如 1、50、 100,直到缩放)。
如果您想对标签非常挑剔,则必须使用标签格式化程序并进行一些数学运算来找到图形的比例,以确定标签的显示方式。例如,您可以做这样的事情,尽管它非常复杂:
我应该指出最后一个解决方案并不完全有效,进一步说明了它有多么困难。
In order from easiest to most difficult...
Since your categories are mostly numeric (e.g. 'mir001'), you could omit the categories, which would prevent them from all being displayed. They would then show 1, 2, 3, and so on.
Alternatively, you could remove the categories and use a label formatter. In this case, you could do something like this, again taking advantage of the fact that the labels appear to be numeric and increasing:
Both of the above would reduce the number of labels (the labels would follow some pattern such as 1, 50, 100, until zoomed).
If you wanted to be very particular about the labels, you would have to use the label formatter and do some math to find the scale of the graph to determine how the labels should be displayed. You could, for example, do something like this, though it is quite convoluted:
I should point out that the last solution doesn't exactly work, further illustrating how difficult it is.
我的解决方案:
My solution:
对于最初的问题来说可能有点太晚了,但我正在使用 Highcharts 开发一些东西,并且我正在寻找正是这个目的。
以下是我的做法,以供将来参考:
它基本上检查我们是否正在缩放 -
if (event.max)
- 或重置。 17 是我在缩小时得到的标签数量,标签步长设置为 5,并且使用这个特定的数据集(我很确定这一切都可以更加完善 - 但它有效)。Probably a bit too late for the original question, but I'm developing something with Highcharts and I was looking for exactly for this.
Here's how I did it, for future reference:
It basically checks if we're zooming -
if (event.max)
- or resetting. 17 is the number of labels I get when zoomed out, with labels step set to 5 and with this particular data set (I'm pretty sure this could all be more polished - but it works).这就是我解决这个问题的方法:
在重绘时调用tickPositioner。最小值和最大值包含最左边和最右边(x 轴)的包含值。
This is I how solved this problem:
The tickPositioner get called on a redraw. The min and max contain the left and right most (x-axis) inclusive values.