2017-07-07 22 views
0

我使用C3圖表呈現在我的項目的一些數據在圖表圖例,我想露面的傳說(標籤在我的情況),而不是在AcisX數字:如何顯示使用C3 JS使用JSON

數據JSON格式:

[ 
    {"Label":"DQUA","Aut":3.75,"NoAut":3.75,"CM":32}, 
    {"Label":"DPRO","Aut":43.9,"NoAut":0,"CM":144}, 
    {"Label":"DMAI","Aut":1.6999999999999993,"NoAut":0,"CM":0}, 
    {"Label":"DENG","Aut":0,"NoAut":0,"CM":16} 
] 

我試圖讓任務工作:

 var chart = c3.generate({ 
     bindto: '.ks-chart-orders-block', 
     data: { 
      url: '/Home/AbsencesByDepartementFiltredByReasons', 
      mimeType: 'json', 
      type:'bar', 
      keys:{ 
      value: ['Aut','NoAut','CM'] 
      }, 
     } 
     } 
    }); 

Getted結果: enter image description here 預期結果: enter image description here

回答

1

您需要自定義類別來修改x軸:

var chart = c3.generate({ 
    bindto: '.ks-chart-orders-block', 

    data: { 
     url: '/Home/AbsencesByDepartementFiltredByReasons', 
     mimeType: 'json', 
     type:'bar', 
     keys:{ 
     x: 'Label', 
     value: ['Aut','NoAut','CM'] 
     }, 
    }, 

    axis: { 
     x: { 
     type: 'category', 
     tick: { 
      centered: true 
     } 
     } 
    } 
}); 
+0

@jajsuperman感謝您的重播,但分類是動態的,也就像你可以在JSON數據看, 所以應該自動執行而無需手動硬編碼。 –

+1

@AyyoubDahhane我編輯了代碼。只需刪除Categories數組,並在鍵內放入'x:'Label'' – katagorri