简体   繁体   English

Highcharts在分页时不改变x轴标签

[英]Highcharts not changing x-axis label on pagination

I have found this jsfiddle very helpful when I started working on paginated highchart columns. 当我开始处理分页的高图列时,我发现这个jsfiddle非常有用。 On top of this good example, I would like to know how I could change the x-axis labels into each data's corresponding name. 除了这个好例子,我想知道如何将x轴标签更改为每个数据的相应名称。 (Ex. Along the x-axis, we should find the names of 'Fred G. Aandahl', 'Watkins Moorman Abbitt', 'Amos Abbott', etc. with their corresponding y-values and must change accordingly when the "Next" button is clicked.) (例如,沿着x轴,我们应该找到'Fred G. Aandahl','Watkins Moorman Abbitt','Amos Abbott'等的名字及其相应的y值,并且必须在“Next”时相应地改变单击按钮。)

I have tried adding "xAxis" option inside the highcharts portion but still had no luck. 我试过在highcharts部分添加“xAxis”选项,但仍然没有运气。

  pie = new Highcharts.Chart({
        chart: {
            renderTo: 'container',
            type: 'column'
        },
        xAxis: {
            labels: {
                formatter: function(){
                    return this.value;
                }
             }
        },
        series: [{
            data: []
        }]
    }); 

and

pie = new Highcharts.Chart({
        chart: {
            renderTo: 'container',
            type: 'column'
        },
        xAxis: {
            labels: {
                  format: '{value}'
              }
        },
        series: [{
            data: []
        }]
    });

Can someone help me regarding on what I am missing in this example? 在这个例子中,有人可以帮助我解决我所缺少的问题吗? It will be very much appreciated. 非常感谢。

You can set type of xAxis to category and without category array the value in axis will be taken from the point. 您可以将xAxis的类型设置为category,如果没有类别数组,则将从该点获取轴中的值。 But you will need to change your setData call to 但是您需要将setData调用更改为

pie.series[0].setData( data.slice(from, to), true, true, false ); pie.series [0] .setData(data.slice(from,to),true,true,false);

xAxis: {
            type: 'category'
        },

Example: http://jsfiddle.net/kpxp4/8/ 示例: http//jsfiddle.net/kpxp4/8/

I am able to change the x-axis labels accordingly by adding 我可以通过添加相应地更改x轴标签

pie.xAxis[0].update({
    categories: category.slice(from, to)
})

after the setData call, where category is an array of all the x-axis labels that you want to display in correspondence to each y-axis value. 在setData调用之后,其中category是要与每个y轴值对应显示的所有x轴标签的数组。 Moreover, the 而且,

xAxis: {
        type: 'category'
}

portion, as suggested by @Kacper Madej, works for the specific data format given originally. 按照@Kacper Madej的建议,部分适用于最初给出的特定数据格式。 However, the pie.xAxis[0].update() could be used on a more general sense given that you know the array of x-axis labels that you want to use (regardless of the data or series format that you have). 但是, pie.xAxis [0] .update()可以在更一般的意义上使用,因为您知道要使用的x轴标签数组(无论您拥有何种数据或系列格式)。

Here is the link to the jsfiddle . 这是jsfiddle的链接。

Hope this could be of any help, too. 希望这也可以提供任何帮助。

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

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