Defining a category axis using c3.js

I just started using c3.js and I don’t know how to specify tick values ​​on the x axis. Values: type1, type2, type3 ... and here is my code:

    $(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("") }
          }
        }
      });
    });
+4
source share
1 answer

This works great. I based it on an Example category by category on the C3.js. website

$(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>
Run codeHide result
+3
source

Source: https://habr.com/ru/post/1589228/


All Articles