Search code examples
javascriptchartslarge-datac3.js

How to use chart in JavaScript with large data set


I need to visualize the bar chart with Javascript. So I'm used C3 JS to visualize the chart. Simply I'm using this Bar chart as follows,

<div id="chart"></div>

<script>

var chart = c3.generate({
    bindto: '#chart',
    data: {
      columns: [
        ['data1', 30, 200, 100, 400, 150, 250],
        ['data2', 50, 20, 10, 40, 15, 25]
      ],
      axes: {
        data2: 'y2'
      },
      types: {
        data2: 'bar'
      }
    },
    axis: {
      y: {
        label: {
          text: 'Y Label',
          position: 'outer-middle'
        },
        tick: {
          format: d3.format("$,") // ADD
        }
      },
      y2: {
        show: true,
        label: {
          text: 'Y2 Label',
          position: 'outer-middle'
        }
      }
    }
});

</script>

enter image description here

But the problem is when X-axis consists of the large data set Chart getting cramped. I have more than 700 data.

enter image description here

Have any possible way to avoid this? can I add scroll bar between primary and secondary X-axis?


Solution

  • Google, such a wonderfull thing ;)

    https://c3js.org/samples/interaction_zoom.html

    or this

    C3 / D3 bar chart with horizontal scroll