Click here to Skip to main content
16,021,285 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am using jqplot to create bar chart.

The code is as below.

JavaScript
<script class="code" type="text/javascript">

$(document).ready(function(){

  var s1 = [2, 6, 7, 10]
  var s2 = [7, 5, 3, 4];
  var s3 = [14, 9, 3, 8];

   
    plot3 = $.jqplot('chart1', [s1, s2, s3], {
               
                stackSeries: true,
                captureRightClick: true,
                animate: !$.jqplot.use_excanvas,
                seriesDefaults: {
                    renderer: $.jqplot.BarRenderer,
                    rendererOptions: {
                       barMargin: 30,
                        highlightMouseDown: true
                    },
                    pointLabels: { show: true }
                },
                axes: {
                    xaxis: {
                        renderer: $.jqplot.CategoryAxisRenderer
                    },
                    yaxis: {
                        padMin: 0
                    }
                },
                legend: {
                    renderer: $.jqplot.EnhancedLegendRenderer,
                    show: true,
                    location: 'e',
                    placement: 'outside'
                }
            });
            $('#chart1').bind('jqplotDataClick',
    function (ev, seriesIndex, pointIndex, data) {
        $('#info3').html('series: ' + seriesIndex + ', point: ' + pointIndex + ', data: ' + data);
    }
  );
        });
    </script>


Here, I have done hardcoding.

How can I have it dynamically??

Please suggest.

Thank you.
Posted
Updated 24-Feb-14 22:26pm
v2

1 solution

Firstly, add a ";" after first line of this :
JavaScript
var s1 = [2, 6, 7, 10]
var s2 = [7, 5, 3, 4];
var s3 = [14, 9, 3, 8];

Secondly, retrieve your values from your database (or from where you want) and fill these arrays dynamically, instead of filling them by hardcoding ;)
 
Share this answer
 
Comments
praveenagarkar 26-Feb-14 0:40am    
semicolon is there but here it has been missed :p and am retrieving values from database but i dont know how to bind it and fill these arrays..
Artefakt94 26-Feb-14 4:13am    
Do you retrieve these values from database with Ajax ?
praveenagarkar 26-Feb-14 4:16am    
yes
Artefakt94 26-Feb-14 4:35am    
Can I see your code ? Edit your answer to add it ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900