简体   繁体   English

AmCharts每周数据显示

[英]AmCharts weekly data display

i have some troubles with displaying data via amcharts when "minPeriod" property is equal to "WW". 当“ minPeriod”属性等于“ WW”时,我无法通过amcharts显示数据。

My codepen examples: 我的codepen示例:

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) . 周示例(中断)

As you can see, all the last link's labels are aligned to the left and it makes my chart pretty ugly. 如您所见,所有最后一个链接的标签都向左对齐,这使我的图表非常难看。 I think it's happening because of the disconnecting between real values and expected by categoryAxis. 我认为这是由于实际值与categoryAxis期望值之间的脱节而发生的。 Maybe there's a property to fix it, but i could'n find it. 也许有一个属性可以修复它,但是我找不到。

If you've faced the same problem and have some advices to me, please help. 如果您遇到了同样的问题,并且对我有一些建议,请帮助。

You can set centerLabels to true in your categoryAxis to force the labels to be centered. 您可以在categoryAxis中将centerLabels设置为true,以使标签居中。

Updated codepen 更新的代码笔

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

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