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).

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

    报告相同问题?

    悬赏问题

    • ¥15 k210显示failed init to model
    • ¥15 Evil-droid生成的APK手机已经下载但无法建立任务
    • ¥25 c语言韩信点兵的变式
    • ¥15 怎么根据书上的例子完成这个问题呢?
    • ¥15 ECharts 增加Zoom,整行包括右边的Text一起滑动
    • ¥15 关于网上一个easyx制作的见缝插针小游戏(c++)
    • ¥15 开地址法双散列函数处理碰撞
    • ¥15 想问一下这个是什么情况 虚拟机Linux打不开了
    • ¥15 联通光猫掉注册了怎么重新注册上去
    • ¥15 关于unity开发steamvr程序遇到的问题