2017-04-25 42 views
1

我生成與folling JSON和代碼c3.js圖表​​,我試圖改變X軸日期格式類似這樣的「2016年11月。」「N16」 。我可以幫忙嗎?謝謝!改變格式圖表

response = [["November 2016","December 2016","January 2017","February 2017","March 2017","April 2017"],["total" 
    ,2,43,60,51,46,110],["mammo",1,20,34,12,12,60],["face",1,20,16,30,32,32],["body",0,3,10,9,2,18],["photo" 
    ,0,19,27,12,5,21],["scan",2,24,33,39,41,89]] 
    initMonthlyUsageChart(response); 

function initMonthlyUsageChart(amounts) { 
    var months = amounts.shift(); 
    c3.generate({ 
    bindto: '#monthly_usage_chart-js', 
    data: { columns : amounts }, 
    axis: { 
     x: { 
     type: 'category', 
     categories: months, 
     tick: { 
      rotate: 90, 
      format: function (x) { // x comes in as a time string. 
       x[0] = x[0].map(function(date) { 
        return date.replace(/^(\w{1}).*(\d{2})$/gi, "$1$2"); 
       }); 
      } 
     } 
     } 
    } 
    }); 
} 
+0

請分享你的整個代碼 ,什麼是在通過的jsfiddle 共享「幾個月變量」,所以我可以嘗試按你所需 –

+0

@KaushikAndani代碼感謝好,我更新以獲得解決方案! – user1937021

+0

你的圖表不生成它給我的錯誤 請給我適當的圖表代碼 –

回答

0

X不進來的時間字符串,它有作爲索引類

因此,改變該位的代碼,你需要什麼:

 format: function (x) { // x comes in as an index 
     return months[x].replace(/^(\w{1}).*(\d{2})$/gi, "$1$2"); 
     }