请帮助我。我希望轴范围及其在一个时期内重复出现,例如在此示例中,如果每个范围只有一个开始和结束日期,则轴范围仅显示一次:
https://www.amcharts.com/demos/stacked-area/
但是如果每个轴范围有多个开始日期和结束日期怎么办?可以显示它们吗?例如:
此代码无效。我有两个轴范围测试a和测试b。
function createRange(axis, from, to, title) {
var range = axis.axisRanges.create();
range.value = from;
range.endValue = to;
range.grid.stroke = chart.colors.getIndex(7);
range.grid.strokeOpacity = 0.6;
range.grid.strokeDasharray = "5,2";
range.label.text = title;
range.label.inside = true;
range.label.rotation = 90;
range.label.horizontalCenter = "right";
range.label.verticalCenter = "middle";
}
createRange(dateAxis, new Date(Date.parse(testa_start)), new Date(Date.parse(testa_end)), "Test A");
createRange(dateAxis, new Date(Date.parse(testb_start)), new Date(Date.parse(testb_end)), "Test B");
请帮助。非常感谢。谢谢
答案 0 :(得分:1)
您应该设置range.date
而不是range.value
。
看到code pen具有固定功能。
function createRange(axis, from, to, title) {
var range = axis.axisRanges.create();
range.date = from;
range.endValue = to;
range.grid.stroke = chart.colors.getIndex(7);
range.grid.strokeOpacity = 0.6;
range.grid.strokeDasharray = "5,2";
range.axisFill.fill = chart.colors.getIndex(7);
range.axisFill.fillOpacity = 0.2;
range.label.text = title;
range.label.inside = true;
range.label.rotation = 90;
range.label.horizontalCenter = "right";
range.label.verticalCenter = "middle";
}
createRange(dateAxis, new Date(2005, 1, 1), new Date(2007, 1, 1), 'Test');