简体   繁体   English

Highcharts X轴问题

[英]Highcharts X-Axis Issue

I have googled and searched stack overflow alot before deciding to ask this question here because while some questions seemed similar, none of the solutions worked for me. 在决定在此处提出此问题之前,我已经搜索并搜索了很多堆栈溢出问题,因为尽管有些问题看起来很相似,但没有一种解决方案适合我。

I have categorised data from sometimes a very wide range eg 1881 - 2012 and would like to dynamically calculate and divide this range into only 11 points on the x-axis which is what I have room to display with no zooming enabled. 我对有时来自很宽范围的数据进行了分类(例如1881年至2012年),并且希望动态地将此范围划分为x轴上的11个点,这是我没有缩放就可以显示的空间。 If data is from from 1881 - 2012, I would like it for example want it to show(not exactly calculated) from 1881, 1901, 1921, 1941.....if its from 1958 - 2013, then 1958, 1968, 1978.... 如果数据来自1881年至2012年,例如,我希望它显示(不完全计算)1881年,1901年,1921年,1941年.....如果数据来自1958年至2013年,那么1958年,1968年,1978年....

xAxis: {
           categories: range(start_year,end_year),
           tickmarkPlacement: "on",
           tickInterval: Math.ceil(range(start_year,end_year).length/11), 
       },

.......

function range(start_year,end_year)
  {
    var years = [];

    for(var i = start_year;i<=end_year;i++)
    {
        years.push(i); 
    }
    return years;
  } 

What this code does is just skip the labels for certain years but still plots the points on the graph leading to overlapping years on the x-axis. 该代码的作用是仅跳过某些年份的标签,但仍然在图形上绘制点,从而导致x轴上的年份重叠。

Any leads on this would be highly appreciated. 任何线索对此将不胜感激。

Here's the fiddle illustrating my dilemma http://jsfiddle.net/YUPzk/4/ 这是说明我的困境的小提琴http://jsfiddle.net/YUPzk/4/

You can use tickPositioner and prepare your own calculating function. 您可以使用tickPositioner并准备自己的计算函数。
The JavaScript below is one example of how this can be done: 以下JavaScript是如何完成此操作的一个示例:
Highcharts.chart('container', { title: { text: 'Custom tick positions' }, subtitle: { text: 'through axis.tickPositions and axis.tickPositioner' }, xAxis: { tickPositions: [0, 1, 2, 4, 8] }, yAxis: { tickPositioner: function () { var positions = [], tick = Math.floor(this.dataMin), increment = Math.ceil((this.dataMax - this.dataMin) / 6); if (this.dataMax !== null && this.dataMin !== null) { for (tick; tick - increment <= this.dataMax; tick += increment) { positions.push(tick); } } return positions; } }, series: [{ data: [ [0, 1],[1, 3],[2, 2],[4, 4],[8, 3] ] }] });

The above demo code can be found at this jsfiddle 上面的演示代码可以在此jsfiddle中找到

For anyone else struggling to get this done, here's what you need because i did lot's of googling with no answers to be found for people experiencing same challenge 对于其他为完成此工作而苦苦挣扎的人,这是您需要的,因为我做了很多谷歌搜索,却找不到遇到相同挑战的人的答案

Highcharts ; 高图; x-axis scaling issue x轴缩放问题

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

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