amCharts 日期时间值问题,无法设置 hh:mm 时间
amCharts date-time value issue, can not set hh:mm time
我刚开始使用 amCharts 创建甘特图和其他图表。我正在尝试创建一个甘特图并为每一列设置一些时间值。所以我可以用这些线创建;
{
"category": "Planned",
"segments": [ {
"start": 8,
"duration": 9,
"color": "#46615e",
"task": "Order"
} ,{
"start": 18,
"duration": 1,
"color": "#46615e",
"task": "Order"
} ,{
"start": 20,
"duration": 1,
"color": "#46615e",
"task": "Order"
}
]
}
但是对于起始值,我想写 08:18、18:22、20:25 之类的东西,而不是 8、18、20。
但它不适用于这些值..你知道吗?我将在下面分享所有代码。
<!-- Styles -->
<style>
#chartdiv {
width: 100%;
height: 500px;
}
</style>
<!-- Resources -->
<script src="https://www.amcharts.com/lib/3/amcharts.js"></script>
<script src="https://www.amcharts.com/lib/3/serial.js"></script>
<script src="https://www.amcharts.com/lib/3/gantt.js"></script>
<script src="https://www.amcharts.com/lib/3/themes/light.js"></script>
<script src="https://www.amcharts.com/lib/3/plugins/export/export.min.js"></script>
<link rel="stylesheet" href="https://www.amcharts.com/lib/3/plugins/export/export.css" type="text/css" media="all" />
<!-- Chart code -->
<script>
var chart = AmCharts.makeChart( "chartdiv", {
"type": "gantt",
"theme": "dark",
"marginRight": 70,
"period": "hh",
"dataDateFormat":"YYYY-MM-DD hh:nn",
"balloonDateFormat": "JJ:NN",
"columnWidth": 0.5,
"valueAxis": {
"type": "date",
"parseDates": true,
"minPeriod": "mm"
},
"brightnessStep": 0,
"graph": {
"fillAlphas": 0.5,
"balloonText": "<span style='font-size:11px'>[[category]] -> [[task]]</span>",
"labelText": "[[task]]",
"labelPosition": "left",
"labelOffset": 0,
},
"rotate": true,
"categoryField": "category",
"segmentsField": "segments",
"colorField": "color",
"startDate": "2018-10-02 00:00",
"startField": "start",
"endField": "end",
"durationField": "duration",
"dataProvider": [ {
"category": "",
"segments": [ {
"start": 7,
"duration": 17,
"color": "#fff"
} ]
}, {
"category": "Column A",
"segments": [ {
"start": 8,
"duration": 9,
"color": "#46615e",
"task": "Order"
} ,{
"start": 19,
"duration": 1,
"color": "#46615e",
"task": "Order"
} ,{
"start": 21,
"duration": 1,
"color": "#46615e",
"task": "Order"
}
]
}, {
"category": "Column B",
"segments": [ {
"start": 8,
"duration": 8,
"color": "#8dc49f",
"task": "Order"
}, {
"start": 17,
"duration": 2,
"color": "#8dc49f",
"task": "Order"
}, {
"start": 20,
"duration": 2,
"color": "lightblue",
"task": "Order"
} ]
}],
"chartCursor": {
"cursorColor":"#55bb76",
"valueBalloonsEnabled": false,
"cursorAlpha": 0,
"valueLineAlpha":0.5,
"valueLineBalloonEnabled": true,
"valueLineEnabled": true,
"zoomable":false,
"valueZoomable":true
}
} );
</script>
<!-- HTML -->
<div id="chartdiv"></div>
startField 和endField 映射的值只接受数值。如果要设置时间,则必须通过 startDateField 和 endDateField 使用日期。
"startDateField": "start",
"endDateField": "end",
"dataProvider": [ {
// ...
"segments": [ {
"start": "2016-01-01 08:18",
"end": "2016-01-11 18:18",
勾选this example。虽然它仅使用日期,但您可以提供与您的 dataDateFormat 匹配的日期时间。
我刚开始使用 amCharts 创建甘特图和其他图表。我正在尝试创建一个甘特图并为每一列设置一些时间值。所以我可以用这些线创建;
{
"category": "Planned",
"segments": [ {
"start": 8,
"duration": 9,
"color": "#46615e",
"task": "Order"
} ,{
"start": 18,
"duration": 1,
"color": "#46615e",
"task": "Order"
} ,{
"start": 20,
"duration": 1,
"color": "#46615e",
"task": "Order"
}
]
}
但是对于起始值,我想写 08:18、18:22、20:25 之类的东西,而不是 8、18、20。
但它不适用于这些值..你知道吗?我将在下面分享所有代码。
<!-- Styles -->
<style>
#chartdiv {
width: 100%;
height: 500px;
}
</style>
<!-- Resources -->
<script src="https://www.amcharts.com/lib/3/amcharts.js"></script>
<script src="https://www.amcharts.com/lib/3/serial.js"></script>
<script src="https://www.amcharts.com/lib/3/gantt.js"></script>
<script src="https://www.amcharts.com/lib/3/themes/light.js"></script>
<script src="https://www.amcharts.com/lib/3/plugins/export/export.min.js"></script>
<link rel="stylesheet" href="https://www.amcharts.com/lib/3/plugins/export/export.css" type="text/css" media="all" />
<!-- Chart code -->
<script>
var chart = AmCharts.makeChart( "chartdiv", {
"type": "gantt",
"theme": "dark",
"marginRight": 70,
"period": "hh",
"dataDateFormat":"YYYY-MM-DD hh:nn",
"balloonDateFormat": "JJ:NN",
"columnWidth": 0.5,
"valueAxis": {
"type": "date",
"parseDates": true,
"minPeriod": "mm"
},
"brightnessStep": 0,
"graph": {
"fillAlphas": 0.5,
"balloonText": "<span style='font-size:11px'>[[category]] -> [[task]]</span>",
"labelText": "[[task]]",
"labelPosition": "left",
"labelOffset": 0,
},
"rotate": true,
"categoryField": "category",
"segmentsField": "segments",
"colorField": "color",
"startDate": "2018-10-02 00:00",
"startField": "start",
"endField": "end",
"durationField": "duration",
"dataProvider": [ {
"category": "",
"segments": [ {
"start": 7,
"duration": 17,
"color": "#fff"
} ]
}, {
"category": "Column A",
"segments": [ {
"start": 8,
"duration": 9,
"color": "#46615e",
"task": "Order"
} ,{
"start": 19,
"duration": 1,
"color": "#46615e",
"task": "Order"
} ,{
"start": 21,
"duration": 1,
"color": "#46615e",
"task": "Order"
}
]
}, {
"category": "Column B",
"segments": [ {
"start": 8,
"duration": 8,
"color": "#8dc49f",
"task": "Order"
}, {
"start": 17,
"duration": 2,
"color": "#8dc49f",
"task": "Order"
}, {
"start": 20,
"duration": 2,
"color": "lightblue",
"task": "Order"
} ]
}],
"chartCursor": {
"cursorColor":"#55bb76",
"valueBalloonsEnabled": false,
"cursorAlpha": 0,
"valueLineAlpha":0.5,
"valueLineBalloonEnabled": true,
"valueLineEnabled": true,
"zoomable":false,
"valueZoomable":true
}
} );
</script>
<!-- HTML -->
<div id="chartdiv"></div>
startField 和endField 映射的值只接受数值。如果要设置时间,则必须通过 startDateField 和 endDateField 使用日期。
"startDateField": "start",
"endDateField": "end",
"dataProvider": [ {
// ...
"segments": [ {
"start": "2016-01-01 08:18",
"end": "2016-01-11 18:18",
勾选this example。虽然它仅使用日期,但您可以提供与您的 dataDateFormat 匹配的日期时间。