我一直在搜索API,但似乎找不到确定的设置,让我的图表以英国格式(dd / mm / YYYY)呈现所有日期。
以下是我生成Highchart的方式:
<script type="text/javascript">
$(function () {
Highcharts.setOptions({
global: {
useUTC: false // I added this as I read it will force highcharts to set the locale to that of the browser, but it seems to have no effect
}
});
Highcharts.chart('container', {
title: {
text: 'FTE Modelling'
},
yAxis: {
min: 0,
title: {
text: 'FTE (Hours)'
}
},
data: { table: "MainContent_GridView1"},
series: [{
type: 'column',
pointWidth: 20
}, {
type: 'column',
pointWidth: 20
// total number of column's have been shortened for brevity
}, {
type: 'spline'
}]
});
});
</script>
我的图表是根据页面中不同功能而变化的动态表格,它有一个用于日期的前导列(显示在qtip和x轴中),这就是我遇到的问题
包含表&#34; MainContent_GridView1&#34;第一列是数据库中的日期,其余列是针对各种FTE要求的。但实质上,表格看起来像这样:
<table id="MainContent_GridView1">
<thead>
<tr>
<th></th>
<th>nameOfColumn</th>
<th>nameOfColumn</th>
<th>nameOfColumn</th>
</tr>
</thead>
<tbody>
<tr>
<th>25/12/2015</th>
<td>columnData</td>
<td>columnData</td>
<td>columnData</td>
</tr>
<tr>
<th>26/12/2015</th>
<td>columnData</td>
<td>columnData</td>
<td>columnData</td>
</tr>
</tbody>
</table>
对于第1行,上面目前在2017年1月12日的悬停和x轴上生成一个qtip(它加起来它认为是几个月,并且在达到12个增量后再增加一年)。
对于第2行,它将于2017年2月12日生成(出于与上述相同的原因)
理想的解决方案是设置一个全局选项,使其成为Highcharts,以便它将处理由语言环境设置的所有日期(这是发送到表的数据的方式),或者永久地将所有日期的格式设置为英国。
非常感谢
elboffor
答案 0 :(得分:2)
编辑以获得所需格式的数据。
您可以在data.dateFormat
部分设置格式。这将让您告诉highcharts您的值的日期格式是什么。
有效选项包括:
- YYYY-MM-DD
- DD / MM / YYYY
- MM / DD / YYYY
- DD / MM / YY
- MM / DD / YY
我没有看到您定义日期格式的任何地方。您需要使用Highcharts.dateFormat
或xAxis.labels.format
。这可以在您的工具提示或轴标签(以及任何标签)上完成。您可以将其设置为:
xAxis: {
type: 'datetime',
tickInterval: 7 * 24 * 36e5, // one week
labels: {
format: '{value: %d/%m/%Y}',
align: 'right',
rotation: -30
}
},