繁体   English   中英

在折线图高图的x轴上显示年份

[英]Display year in x axis of line graph highcharts

这是当前图表的样子:

http://jsfiddle.net/VunVq/1/

在x轴上,我只想显示年份,而不是显示完整日期。

例如2008 2009 2010

工具提示应显示完整日期。

xAxis: {
            categories: ['2008-03-31', '2009-03-31', '2010-03-31']
        },

我阅读了api参考,但无法弄清楚如何仅在x轴上显示年份,可能是因为它过去了我的就寝时间并且我的头脑无法正常工作。

使用label's formatter回调JavaScript函数格式化标签。

 xAxis: {
            categories: ['2008-03-31', '2009-03-31', '2010-03-31'],
            labels: {
                formatter: function () {
                    return this.value.split('-')[0];
                }
            }
        }

演示

您还可以将类型xaxis设置为日期时间( http://api.highcharts.com/highcharts#xAxis.type ),并将pointStart()/ pointInterval用于系列。

暂无
暂无

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

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