amCharts wrong Zoom startDates and endDates

邮差的信 提交于 2019-12-13 04:21:02

问题


I am using amCharts for displaying stock data. I have 7 zoom levels: 1H, 1D, 1W, 1M, 3M, 1Y, MAX. For 1H, 1D, I am using a dataset which contains minute wise data. For 1W, 1M, I use a different dataset which has hour wise data. And for rest 3 levels, I have another dataset with day wise data. Now here is my problem:

When initially, I load minute wise data at default zoom level 1D, and add a listener "changed" to chart.periodSelector, after clicking on 1W button or any further zoom level button, the difference in minutes between startDate and endDate of generated event: var minsDiff = (event.endDate.getTime() - event.startDate.getTime()) / 60000 is always equal to number of minutes in 1 day (1440) instead of 7 days.

I suppose this may be because the current dataset loaded is minutes dataset with 1440 max number of datapoints. So it may be setting date range for 1 Week equal to that of 1 Day because only that much data is available. But what I want is actual date range of 1 week if I click 1W button because I want to load a different chart with different dataset (hour wise data for 1W).

I tried using listener "zoomed" of chart. But same problem persisted.


回答1:


Normally out of scope periods are not visible unless you set hideOutOfScopePeriods to false. As you noticed, if a period is greater than the amount of data available then the chart will truncate the zoom to fit the data you have. Checking the predifinedPeriod property in the changed event is a surefire way to see which button was clicked, which will help in this scenario where the data doesn't necessarily encompass the entire period:

listeners: [
  {
    event: "changed",
    method: function(eventObj) {
      console.log("clicked " + eventObj.predefinedPeriod);
    }
  }
]


来源:https://stackoverflow.com/questions/48006967/amcharts-wrong-zoom-startdates-and-enddates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!