Wijmo UI for the Web
Get the Number of Bars
Wijmo User Guide > Widgets > Chart Widgets > BarChart > BarChart How To > Get the Number of Bars

Building on the Quick Start example, you can get the number of bars in your chart. Here, we only write the number out to the console log, but you can use it for any purpose you like.

  1. In the <head> section of your HTML file, replace the script that includes the document ready function with this one, which does the following:
    • Gets the number of bars in the chart.
    • Writes the number of bars to the console log.

    Drop down and copy code

    Get Number of Bars Script
    Copy Code
    <script id="scriptInit" type="text/javascript">
        $(document).ready(function () {
            $("#wijbarchart").wijbarchart({
                chartLabelFormatString: "p0",
                seriesList: [{
                    label: "2012 Auto Sales",
                    legendEntry: true,
                    data: { 
                        x: ['Ford', 'GM', 'Chrysler', 'Toyota', 'Nissan', 'Honda'], 
                        y: [.05, .04, .21, .27, .1, .24] 
                    }
                }],
            });
            var len = $("#wijbarchart").data().fields.chartElements.bars.length;
            console.log(len);
        });
    </script>
    
  2. No changes are necessary in the <body> section of your HTML file. The basic <div> tag is sufficient to create the chart.
  3. Save your HTML file, open it in a browser, and press the F12 key. If the console tab is not already showing, select Console. The number 6 appears, which is how many bars are in this chart.
See Also

Reference

Widgets