使用Highcharts.js在x轴上显示日期(displaying dates on x axis with Highcharts.js)

编程入门 行业动态 更新时间:2024-10-06 06:40:04
使用Highcharts.js在x轴上显示日期(displaying dates on x axis with Highcharts.js)

我正在用highcharts.js建立一个条形图。 x轴是日期数组,而y轴是0-100的数字数组。 我想在X轴上显示日期,但只在有新日期时显示刻度。 如果你看这个小提琴你可以看到当前的情节以及日期看起来如何糟糕。 看看这个小提琴 ,以及它如何以优雅的方式显示日期。 基本上我只想在绘制许多数据点时在x轴上显示几个刻度。

$(function () { $('#container').highcharts({ chart: { type: 'column' }, title: { text: 'Monthly Average Rainfall' }, subtitle: { text: 'Source: WorldClimate.com' }, xAxis: { categories: dates , crosshair: true }, yAxis: { min: 0, title: { text: 'Rainfall (mm)' } }, tooltip: { headerFormat: '<span style="font-size:10px">{point.key}</span><table>', pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' + '<td style="padding:0"><b>{point.y:.1f} mm</b></td></tr>', footerFormat: '</table>', shared: true, useHTML: true }, plotOptions: { column: { pointPadding: 0.2, borderWidth: 0 } }, series: [{ name: 'Tokyo', data: ticks }] });

I’m building a bar chart with highcharts.js. The x-axis is an array of dates, while the y-axis is an array of numbers from 0-100. I want to display the dates on the X axis but only show ticks when there is a new date. If you look at this fiddle you can see the current plot and how the dates look bad. Look at this fiddle and how it displays the dates in an elegant way. Essentially I want to only show a few ticks on the x-axis while plotting many data points.

$(function () { $('#container').highcharts({ chart: { type: 'column' }, title: { text: 'Monthly Average Rainfall' }, subtitle: { text: 'Source: WorldClimate.com' }, xAxis: { categories: dates , crosshair: true }, yAxis: { min: 0, title: { text: 'Rainfall (mm)' } }, tooltip: { headerFormat: '<span style="font-size:10px">{point.key}</span><table>', pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' + '<td style="padding:0"><b>{point.y:.1f} mm</b></td></tr>', footerFormat: '</table>', shared: true, useHTML: true }, plotOptions: { column: { pointPadding: 0.2, borderWidth: 0 } }, series: [{ name: 'Tokyo', data: ticks }] });

最满意答案

将minTickInterval添加到xAxis设置:

xAxis: { categories: dates , crosshair: true, minTickInterval: 24 }

Add minTickInterval to your xAxis settings:

xAxis: { categories: dates , crosshair: true, minTickInterval: 24 }

更多推荐

本文发布于:2023-08-07 13:29:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1464071.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:日期   js   Highcharts   axis   dates

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!