我试图使图表从外部触发的事件调用中水平滚动,例如单击页面其他位置的按钮时。我同样能够获得我希望图表水平滚动到的位置的开始和索引。图表的DateAxis定义如下:
this.categoryAxis = chart.xAxes.push(new am4charts.DateAxis());
this.categoryAxis.dataFields.date = "value_date";
this.categoryAxis.cursorTooltipEnabled = false;
this.categoryAxis.start = 0.7;
this.categoryAxis.keepSelection = true;
由外部事件调用的函数定义如下:
function(res){
let cpre = res.tree.split(',');
cpre.forEach((el, i) => {
cpre[i] = Number(el);
});
let visibleEl = this.data.findIndex((el, i) => {
return isEqual(cpre, el.graphIndex);
});
console.log(visibleEl);
//Trying to display 6 date points at any given time, not working.
let startIndex = visibleEl - 6 < 0 ? 0 : visibleEl - 6;
this.categoryAxis.zoomToIndexes(visibleEl, startIndex);
}
此行this.categoryAxis.zoomToIndexes(visibleEl, startIndex);
当前会放大到目标索引,但也会放大地图,这并不是理想的效果。我只想让它滚动到所需位置而不缩放,谢谢。