AM使用zoomToDates查看初始视图

问题描述 投票:1回答:3

被遗忘了一点点。

我在zoomToIndexes上找到了一些其他的帮助,但是我无法让zoomToDates在我的页面上工作。

实况页面是b2 resource urq sales

我试图设置从2000到现在显示的初始视图..我想从图表中的80年代早期拍一些原始销售数据,但不希望图表最初显示最近30多年。

任何帮助将非常感激!

amcharts
3个回答
5
投票

zoomToDates将真正的JavaScript Date对象作为参数:

chart.zoomToDates(new Date(2005, 0, 1), new Date(2015, 11, 31));

你也可以使用图表的rendered事件来“预缩放”负载:

var chart = AmCharts.makeChart("chartdiv", {
  // your chart config
  // ...
});

chart.addListener("rendered", function(event) {
  event.chart.zoomToDates(new Date(2005, 0, 1), new Date(2015, 11, 31));
});

注意,Date()构造函数参数(第二个参数)中的月份是从零开始的。含义1月是0,2月1日等。


1
投票

您应该为zoomToValues使用chart对象的valueAxis属性。我希望这对你有帮助。

 var chart= AmCharts.makeChart("chartdiv", {
      "type": "gantt",
      "theme": "black",
           ...
    });

    zoomChart();
    chart.addListener("dataUpdated", zoomChart);



 function zoomChart(event) {
   chart.valueAxis.zoomToValues(new Date(2017, 2, 10), new Date(2017,2,12));
  // or ==> event.chart.valueAxis.zoomToValues(new Date(2017, 2, 10), new Date(2017,2,12));
 }

-1
投票

这对我有用:

var chart= AmCharts.makeChart("chartdiv", {
        type: "serial",
        ...
} );

chart.addListener("dataUpdated", zoomChart);

zoomChart();

function zoomChart() {
        chart.zoomToDates(new Date(2018, 2, 26), new Date(2018, 2, 28));
}

注意:Date()构造函数中的months参数从零开始。 1月是0,2月是1等

© www.soinside.com 2019 - 2024. All rights reserved.