2016-12-28 31 views
0

我在AmCharts中有一個圖表,我想在圖表頂部開始滾動而不是在底部。chartScrollbar AmCharts

var chart = AmCharts.makeChart("chartdiv", { 
    "type": "serial", 
    "theme": "light", 
    "rotate":true, 
    "maxSelectedSeries": 4, 
    "mouseWheelScrollEnabled": true, 
    "marginRight": 70, 
    "dataProvider": [{ 
    "country": "USA", 
    "visits": 3025, 
    "color": "#FF0F00" 
    }, { 
    "country": "China", 
    "visits": 1882, 
    "color": "#FF6600" 
    }, { 
    "country": "Japan", 
    "visits": 1809, 
    "color": "#FF9E01" 
    }, { 
    "country": "Germany", 
    "visits": 1322, 
    "color": "#FCD202" 
    }, { 
    "country": "UK", 
    "visits": 1122, 
    "color": "#F8FF01" 
    }, { 
    "country": "France", 
    "visits": 1114, 
    "color": "#B0DE09" 
    }, { 
    "country": "India", 
    "visits": 984, 
    "color": "#04D215" 
    }, { 
    "country": "Spain", 
    "visits": 711, 
    "color": "#0D8ECF" 
    }, { 
    "country": "Netherlands", 
    "visits": 665, 
    "color": "#0D52D1" 
    }, { 
    "country": "Russia", 
    "visits": 580, 
    "color": "#2A0CD0" 
    }, { 
    "country": "South Korea", 
    "visits": 443, 
    "color": "#8A0CCF" 
    }, { 
    "country": "Canada", 
    "visits": 441, 
    "color": "#CD0D74" 
    }], 
    "valueAxes": [{ 
    "axisAlpha": 0, 
    "position": "left", 
    "title": "Visitors from country" 
    }], 
    "startDuration": 1, 
    "graphs": [{ 
    "balloonText": "<b>[[category]]: [[value]]</b>", 
    "fillColorsField": "color", 
    "fillAlphas": 0.9, 
    "lineAlpha": 0.2, 
    "type": "column", 
    "valueField": "visits" 
    }], 
    "chartCursor": { 
    "categoryBalloonEnabled": false, 
    "cursorAlpha": 0, 
    "zoomable": false 
    }, 
    "categoryField": "country", 
    "categoryAxis": { 
    "gridPosition": "start", 
    "labelRotation": 45 
    }, 
    "chartScrollbar": { 
    //"graph": "Not set", 
    "backgroundColor":"#2f373e", 
    "graphType": "smoothedLine", 
    "resizeEnabled": false, 
    "scrollbarHeight": 15, 
    "scrollDuration": 0, 
    "updateOnReleaseOnly": true 
    } 

}); 

jsfiddle

正如你可以在的jsfiddle滾動條上圖的底部開始看,我有滾動到圖形的頂部看到的第一個結果。

回答

1

由於設置了maxSelectedSeries屬性,圖表似乎放大到最後,因此在初始化時圖表放大到最後的〜x系列。你可以通過調用zoomToIndexes解決此通過添加init監聽器設置變焦時initilation所需位置:

var chart = AmCharts.makeChart("chartdiv", { 
    // ... 
    "listeners": [{ 
    "event": "init", 
    "method": function(e) { 
     e.chart.zoomToIndexes(0, 4); 
    } 
    }] 
}); 

Updated fiddle

+0

謝謝你很多關於您的解決方案! – Caru