amCharts不平衡

时间:2016-03-11 18:34:06

标签: javascript node.js amcharts

我试图创建一个amCharts图表,基于三个值,但结果完全混乱:图表完全向左移动,不会固定所有节点结果或显示所有数据

请帮助

    var chart = AmCharts.makeChart("chartdiv", {
        "type": "serial",
        "theme": "none",
        "pathToImages": "http://www.amcharts.com/lib/3/images/",
        "dataDateFormat": "YYYY-MM-DD",
        "valueAxes": [{
            "id":"v1",
            "axisAlpha": 0,
            "position": "left"
        }],
        "graphs": [{
            "id": "g1",
            "bullet": "round",
            "bulletBorderAlpha": 1,
            "bulletColor": "#FFFFFF",
            "bulletSize": 5,
            "hideBulletsCount": 50,
            "lineThickness": 2,
            "title": "red line",
            "useLineColorForBulletBorder": true,
            "valueField": "Tweets"
        },
                  {
            "id": "g2",
            "bullet": "round",
            "bulletBorderAlpha": 1,
            "bulletColor": "#00FF00",
            "bulletSize": 5,
            "hideBulletsCount": 50,
            "lineThickness": 2,
            "title": "green line",
            "useLineColorForBulletBorder": true,
            "valueField": "Retweets"
        }],
        "chartScrollbar": {
            "graph": "g1",
            "scrollbarHeight": 30
        },
        "chartCursor": {
            "cursorPosition": "mouse",
            "pan": true,
             "valueLineEnabled":true,
             "valueLineBalloonEnabled":true
        },
        "categoryField": "date",
        "categoryAxis": {
            "parseDates": true,
            "dashLength": 1,
            "minorGridEnabled": true,
            "position": "top"
        },
        exportConfig:{
          menuRight: '20px',
          menuBottom: '50px',
          menuItems: [{
          icon: 'http://www.amcharts.com/lib/3/images/export.png',
          format: 'png'   
          }]  
        },
        "dataProvider": 
                    [{"date":"2016-03-11","Tweets":96,"Exposure":633286,"Retweets":73},{"date":"2016-03-10","Tweets":235,"Exposure":1637137,"Retweets":48},{"date":"2016-03-09","Tweets":116,"Exposure":657912,"Retweets":30},{"date":"2016-03-08","Tweets":98,"Exposure":510558,"Retweets":129},{"date":"2016-03-07","Tweets":91,"Exposure":930904,"Retweets":58},{"date":"2016-03-06","Tweets":20,"Exposure":56490,"Retweets":6},{"date":"2016-03-05","Tweets":22,"Exposure":134128,"Retweets":13},{"date":"2016-03-04","Tweets":40,"Exposure":263687,"Retweets":60},{"date":"2016-03-03","Tweets":35,"Exposure":477493,"Retweets":17},{"date":"2016-03-02","Tweets":39,"Exposure":541723,"Retweets":70}]

    }
);

chart.addListener("rendered", zoomChart);

zoomChart();
function zoomChart(){
    //chart.zoomToIndexes(chart.dataProvider.length - 40, chart.dataProvider.length - 1);
    chart.zoomToIndexes(0, 10);
}

http://jsfiddle.net/srp8313j/52/

1 个答案:

答案 0 :(得分:2)

数据点的顺序很重要。对于基于日期的图表,数据点需要按从最旧到最新的升序排列。在您的数据中,它们正在向后运行。要解决此问题,只需更改数据点的顺序:

"dataProvider": [
  {"date":"2016-03-02","Tweets":39,"Exposure":541723,"Retweets":70},
  {"date":"2016-03-03","Tweets":35,"Exposure":477493,"Retweets":17},
  {"date":"2016-03-04","Tweets":40,"Exposure":263687,"Retweets":60},
  {"date":"2016-03-05","Tweets":22,"Exposure":134128,"Retweets":13},
  {"date":"2016-03-06","Tweets":20,"Exposure":56490,"Retweets":6},
  {"date":"2016-03-07","Tweets":91,"Exposure":930904,"Retweets":58},
  {"date":"2016-03-08","Tweets":98,"Exposure":510558,"Retweets":129},
  {"date":"2016-03-09","Tweets":116,"Exposure":657912,"Retweets":30},
  {"date":"2016-03-10","Tweets":235,"Exposure":1637137,"Retweets":48},
  {"date":"2016-03-11","Tweets":96,"Exposure":633286,"Retweets":73}
]

Updated fiddle