My chart lines are not in order

匆匆过客 提交于 2019-12-14 03:07:48

问题


I have a graph and the result of joining all the lines should be as in the image. but currently they are not. what am I doing wrong?

https://jsfiddle.net/r2uaq27a/

var chart = c3.generate({
  data: {
    xs: {
      data1: "data2"
    },
    columns: [
      ['data1', 2,3,4,7,8,9,8,7,3],
      ['data2', 1,2,3,4,5,4,3,2,1]
    ]

  }
});

回答1:


Set the some what undocumented xSort property of data to false:

var chart = c3.generate({
    data: {
        xSort: false,
        x: 'x',
        order: function (i) { console.log(i); },
        columns: [
            ['x', 1,2,3,4,5,4,3,2,1],
            ['data1', 2,3,4,7,8,9,8,7,3]
        ]
    }
});

Running:

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]
    ]

  }
});
#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>


来源:https://stackoverflow.com/questions/46325699/my-chart-lines-are-not-in-order

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!