以更愉快的方式呈现轴的值

时间:2017-09-20 17:42:46

标签: javascript d3.js c3.js

在我当前的图表中,x轴值难以辨认。如何改进表示或至少x值的间隔具有均匀的分离。

enter image description here

var chart = c3.generate({
  data: {
    xs: {
      data1: "data2",
      data3: "data4"
    },
    xSort: false,
    columns: [
      ['data1', -4,3,4,7,8,9,8,7,3],
      ['data2', -5,2,3,4,5,4,3,2,1],
      ['data3', Math.random() * 10,Math.random() * 10,Math.random() * 10,Math.random() * 10,Math.random() * 10,Math.random() * 10],
      ['data4', Math.random() * 10,Math.random() * 10,Math.random() * 10,Math.random() * 10,Math.random() * 10,Math.random() * 10]
    ]

  }
});

https://jsfiddle.net/9zmbq0g0/

1 个答案:

答案 0 :(得分:1)

使用axis.x.tick.values

var chart = c3.generate({
  data: {
    xs: {
      data1: "data2",
      data3: "data4"
    },
    xSort: false,
    columns: [
      ['data1', 2,3,4,7,8,9,8,7,3],
      ['data2', 1,2,3,4,5,4,3,2,1],
      ['data3', Math.random() * 10,Math.random() * 10,Math.random() * 10,Math.random() * 10,Math.random() * 10,Math.random() * 10],
      ['data4', Math.random() * 10,Math.random() * 10,Math.random() * 10,Math.random() * 10,Math.random() * 10,Math.random() * 10]
    ]
  },
  axis: {
    x: {
      tick: {
        values: d3.range(-5,10)
      }
    }
  }
});
#catImage {
  width: 40px;
  height: 40px;
  position: absolute;
  left: 40px;
  top: 0px;
}
<link data-require="c3.js@0.4.11" data-semver="0.4.11" rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/c3/0.4.11/c3.css" />
<script data-require="c3.js@0.4.11" data-semver="0.4.11" src="https://cdnjs.cloudflare.com/ajax/libs/c3/0.4.11/c3.js"></script>
<script data-require="d3@3.5.17" data-semver="3.5.17" src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.17/d3.js"></script>
<div id="chart"></div>