2015-05-21 2 views
4

Я только начал использовать c3.js, и я не знаю, как указать значения тиков по оси x. Значения: type1, type2, type3 ... и вот мой код:Определение оси категории с помощью c3.js

$(document).ready(function(){ 
     var mammoReconstructionsAcceptedChart = c3.generate({ 
     bindto: '#mammo_reconstructions_accepted', 
     data: { 
      x: 'x', 
      columns: [ 
      ['x', 'type1', 'type2', 'type3', 'type4', 'type5', 'type6'], 
      ['data1', 30, 200, 100, 400, 150, 250] 
      ] 
     }, 
     axis: { 
      x: { 
      tick: { format: d3.format("") } 
      } 
     } 
     }); 
    }); 
+0

использование домена и диапазон? – thatOneGuy

+0

Я обновил заголовок. Вам нужна ось *** категории ***, а не *** линейная *** или *** *** ось ***. –

ответ

3

Это работает отлично. Я основывал его на Category Axis Example на веб-сайте C3.js.

$(document).ready(function() { 
 
    var mammoReconstructionsAcceptedChart = c3.generate({ 
 
    bindto: '#mammo_reconstructions_accepted', 
 
    data: { 
 
     columns: [ 
 
     ['data1', 30, 200, 100, 400, 150, 250] 
 
     ] 
 
    }, 
 
    axis: { 
 
     x: { 
 
     type: 'category', 
 
     categories: ['type1', 'type2', 'type3', 'type4', 'type5', 'type6'] 
 
     } 
 
    } 
 
    }); 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/c3/0.4.10/c3.min.js"></script> 
 
<link href="https://cdnjs.cloudflare.com/ajax/libs/c3/0.4.10/c3.min.css" rel="stylesheet" /> 
 

 
<div id="mammo_reconstructions_accepted"></div>

+1

Это сработало отлично. Благодарю [г-н Polywhirl] (http://stackoverflow.com/users/1762224/mr-polywhirl) – AlexLarra