Search code examples
javascripthtmljquerycssapexcharts

Limit x-axis in Apexcharts.js


I want to limit the x-axis in the bar graph I'm using, I have multiple values but I want to show only 7 and then the user can scroll to see the remaining. Does this option exist? enter image description here


Solution

  • Setting the value of the xaxis.range property should help.

    var options = {
        series: [
            {
                name: 'PRODUCT A',
                data: [44, 55, 41, 67, 22, 43, 13, 23, 20, 8, 13, 27]
            }, {
                name: 'PRODUCT B',
                data: [13, 23, 20, 8, 13, 27, 11, 17, 15, 15, 21, 14]
            }, {
                name: 'PRODUCT C',
                data: [11, 17, 15, 15, 21, 14, 44, 55, 41, 67, 22, 43]
            }
        ],
        chart: {
            type: 'bar',
            height: 350,
            stacked: true,
            toolbar: {
              show: true
            }
        },
        xaxis: {
            range: 7
        }
    };
    var chart = new ApexCharts(document.querySelector("#chart"), options);
    chart.render();