简体   繁体   English

Amchart 4轴范围

[英]Amchart 4 axis range

please help me. 请帮我。 I'd like the axis ranges with their to repeated in a period for instance in this example the axis ranges just displayed once if there is only one start and end date for each ranges: 我希望轴范围及其在一个时期内重复出现,例如在此示例中,如果每个范围只有一个开始和结束日期,则轴范围仅显示一次:

https://www.amcharts.com/demos/stacked-area/ https://www.amcharts.com/demos/stacked-area/

but what if there are multiple start date and end date for each axis range? 但是,如果每个轴范围有多个开始日期和结束日期怎么办? is it possible to display them? 可以显示它们吗? for instance: 例如:

  • 1994- Fines for speeding increased 1994年-超速罚款
  • 1995-Motorcycle fee introduced 1995-开始收取摩托车费
  • 1996- Fines for speeding increased 1996年-提速罚款
  • 1997-Motorcycle fee introduced 1997年-引入摩托车费
  • 1998- Fines for speeding increased 1998年-超速罚款增加

This code isn't working. 该代码不起作用。 I have 2 axis ranges test a and test b. 我有两个轴范围测试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"); 

Please help. 请帮忙。 appreciate it very much. 非常感谢。 Thanks 谢谢

You should set range.date instead of range.value . 您应该设置range.date而不是range.value

See that full working code pen with the fixed function. 看到具有固定功能的完整工作代码笔

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');

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

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