AmCharts每周数据显示

时间:2016-11-07 15:03:07

标签: javascript svg amcharts

我在使用amcharts显示数据时遇到了一些麻烦。" minPeriod"财产等于" WW"。

我的代码集示例:

var data = [];
var date = new Date();

for (var i = 0; i< 10;i++){
data.push({
    calcDate: moment(new Date()).startOf('day').add(i, 'days').toDate(), 
value: Math.random(100)});}

var chart = AmCharts.makeChart("chartdiv", {
"type": "serial",
"startDuration": 0,
"categoryField": "calcDate",
"theme": "light",
"marginRight": 70,
"autoMarginOffset": 20,
"dataProvider": data,
"graphs": [{
        "type": "column",
        "fillAlphas": 1,
    "balloonText": "[[category]]<br><b><span style='font-size:14px;'>[[value]] C</span></b>",
    "lineColor": "#b6d278",
    "valueField": "value"
}],
"chartCursor": {
    "cursorAlpha": 0.1,
    "cursorColor": "#000000",
},
"categoryAxis": {
    "minPeriod": "DD",
    "parseDates": true,
    "minorGridEnabled": true
},
"export": {
    "enabled": true
}});

Days example (how it must look)

var data = [];
var date = new Date();

for (var i = 0; i< 10;i++){
data.push({
    calcDate: moment(new Date()).startOf('day').add(7*i, 'days').toDate(), 
value: Math.random(100)});}

var chart = AmCharts.makeChart("chartdiv", {
"type": "serial",
"startDuration": 0,
"categoryField": "calcDate",
"theme": "light",
"marginRight": 70,
"autoMarginOffset": 20,
"dataProvider": data,
"graphs": [{
        "type": "column",
        "fillAlphas": 1,
    "balloonText": "[[category]]<br><b><span style='font-size:14px;'>[[value]] C</span></b>",
    "lineColor": "#b6d278",
    "valueField": "value"
}],
"chartCursor": {
    "cursorAlpha": 0.1,
    "cursorColor": "#000000",
},
"categoryAxis": {
    "minPeriod": "WW",
    "parseDates": true,
    "minorGridEnabled": true
},
"export": {
    "enabled": true
}
});

Week example (broken)

正如您所看到的,所有最后一个链接的标签都与左侧对齐,这使得我的图表非常难看。我认为它正在发生,因为实际值之间的断开和categoryAxis所期望的。也许有一个属性可以解决它,但我无法找到它。

如果您遇到同样的问题并向我提出建议,请提供帮助。

1 个答案:

答案 0 :(得分:1)

您可以在categoryAxis中将centerLabels设置为true,以强制标签居中。

Updated codepen