Trying to integrate PHP with progress bar

Share RGraph:  

« Back to message list

Enter your email address to get email updates on this topic. You can stop receiving updates by clicking the link in the update email messages.

Posted by Julie on 12th January 2017
Hi there,
I want to create a progress graph for multiple projects. I'm not sure how to use it. It doesn't work. Please help. Thanks
The following is my code:

<?php
if (!empty($dataProject))
{
    foreach($dataProject as $project)
    {
?>
      <script>
          new RGraph.Bar({
              id: '<?php $project->project_id; ?>',
              data: [<?php $project->project_progress; ?>],
              options: {
                        textAccessible: true,
                        variant: '3d',
                        strokestyle: 'rgba(0,0,0,0)',
                        colors: ['Gradient(red:#f99:#0f0:#0f0)'],
                        gutterBottom: 80,
                        gutterLeft: 50,
                        gutterRight: 35,
                        unitsPost: '%',
                        hmargin: 7,
                        labels: ['Completion'],
                        shadowColor:'#ccc',
                        ymax: 100,
                        noaxes: true,
                        shadowOffsetx: 3,
                        backgroundGridColor: 'rgba(0,0,0,0)',
                        adjustable: false,
                        noxaxis: true
                       }
                     }).draw();
      </script>
      <canvas id="<?php $project->project_id; ?>" width="125" height="300" align=right>
           [No canvas support]
      </canvas>
<?php

    }
}
Posted by Richard on 12th January 2017
Hi there,

Your code works perfectly. This is an example:

www.rgraph.net/fiddle/view.html/bar-chart-and-php-integration

So you should probably look at the output (view-source in your browser) and see what your PHP is creating as there might be an error there. Also have a look in your browsers JavaScript console to see if there is any error being reported.

www.rgraph.net/canvas/docs/howto-debug-your-charts-with-chrome.html




Richard
Posted by Julie on 13th January 2017
Hi Richard,

Thanks for your reply..

Yea.. I had the following error.. and Im trying to figure out how to fix it.. appreciate if you could advice.
Thanks

RGraph.bar.js:46 Uncaught TypeError: Cannot read property 'getContext' of null
     at new RGraph.Bar (RGraph.bar.js:46)
     at 1:133
Posted by Richard on 13th January 2017
Hi there,

That's an error that you get when you get the ID of your canvas tag wrong. So perhaps your $project->project_id variable does not contain what you think it does.




Richard

Add a reply




« Back to message list