简体   繁体   English

以动态yaxis标签为字符串的Highcharts

[英]Highcharts with dynamic yaxis labels as strings

I've been trying to add some custom yAxis labels to highcharts but I've not been able to so far. 我一直在尝试向highcharts添加一些自定义yAxis标签,但到目前为止我还没有做到。 I've tried using formatter from a predefined array of strings and I've tried addAxis method but that doesn't get me the results I'm looking for. 我试过使用预定义的字符串数组中的格式化程序,并试过了addAxis方法,但这并没有为我提供所需的结果。

Basically I have some numbers (lets say 4 and 4000) and I want to have these as my yLabels. 基本上我有一些数字(分别说4和4000),我想将它们作为我的yLabels。 However, I do NOT want the giant space between them. 但是,我希望它们之间有巨大的空间。 They need to be one right after the other and in ascending order. 他们需要一个接一个并按升序排列。 I cannot figure out how to do this leaving them as integers and I cannot figure out how to dynamically add them to highcharts as strings. 我无法弄清楚该如何将它们保留为整数,也无法解决如何将其作为字符串动态添加到highcharts中。 I'm not even sure if this is possible 我什至不确定这是否可行

Any help would be greatly appreciated. 任何帮助将不胜感激。

Here is the Y-axis label formatter documentation from Highcharts you're probably looking for. 这是您可能正在寻找的HighchartsY轴标签格式化程序文档 I wrote this fiddle to simulate the custom y-axis functionality you were wanting, although I'm not sure how you want to map those values to the x-axis data. 我写了这个小提琴来模拟您想要的自定义y轴功能,尽管我不确定您如何将这些值映射到x轴数据。 This should give you a good starting point. 这应该为您提供一个良好的起点。

Code for reference: 参考代码:

$('#container').highcharts({

    yAxis: {
        categories: ['4', '4000', 'Foobar'],

        labels: {
            formatter: function () {
                return this.value;
            }
        }
    },

    series: [{
        data: [0, 1, 2]
    }]
});

This stackoverflow question may also help although I noticed some dead links. 尽管我注意到一些死链接,但这个stackoverflow问题也可能有所帮助。

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

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