dqwh1219 2018-08-13 03:46
浏览 98
已采纳

如何为Highcharts同步图表设置xData作为日期(Y-M)?

I want to plot the synchronized charts like this https://www.highcharts.com/demo/synchronized-charts. The JSON data will come from SQL database and the xData (x-axis) looks like below which are in year-month format:

xData: [
  "2004-04","2004-04","2004-04","2004-04","2004-04","2004-04","2004-04",
  "2004-04","2004-04","2004-04","2004-04","2012-08","2004-04","2004-04","2004-04",  
  "2004-04","2004-04","2004-04","2004-04","2004-04","2004-04","2004-04","2004-04",  
  "2004-04","2004-04","2004-04","2004-04","2004-04","2013-12","2004-04","2004-04",  
  "2007-11","2007-11","2012-08","2005-05","2004-04","2004-04","2004-04","2004-04",  
  "2004-04","2004-04","2004-04","2016-04","2004-04","2012-08","2004-04","2004-04",  
  "2004-04","2004-04","2004-04","2004-04","2004-04","2005-05","2004-04","2004-04",
  "2012-08","2016-04","2004-04","2004-04","2004-04","2004-04","2012-08","2004-04",  
  "2004-04","2004-04","2004-04","2012-08","2004-04","2004-04","2004-04","2004-04",
  "2004-04","2006-02","2007-11","2004-04","2004-04","2004-04","2005-05","2004-04",
  "2004-04","2005-05","2004-04","2004-04","2012-08","2012-08","2006-02","2005-05",
  "2004-04","2016-04","2004-04","2004-04","2004-04","2006-02","2004-04","2004-04",
  "2004-04","2004-04","2004-04","2005-05","2007-11"
 ]

So, how to plot those data as x-axis for synchronized charts?

  • 写回答

1条回答 默认 最新

  • doufei1893 2018-08-13 05:16
    关注

    you could simply use that one array as the labels for the xAxis:

    xAxis: {
        labels: {
            format: '{value}'
        }
    },
    

    but in order to plot on a timeline axis, you may need to convert these strings into integer values, which can be done with PHP: strtotime($date.'-01 00:00:00') ...hint: you need to multiply the result (in seconds) with 1000 for JavaScript timestamps (in milliseconds).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?