Trying to integrate PHP with a progress bar

« 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:

if (!empty($dataProject))
    foreach($dataProject as $project)
          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'],
                        ymax: 100,
                        noaxes: true,
                        shadowOffsetx: 3,
                        backgroundGridColor: 'rgba(0,0,0,0)',
                        adjustable: false,
                        noxaxis: true
      <canvas id="<?php $project->project_id; ?>" width="125" height="300" align=right>
           [No canvas support]

Posted by Richard on 12th January 2017
Hi there,

Your code works perfectly. This is an example:

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.

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 Uncaught TypeError: Cannot read property 'getContext' of null
     at new RGraph.Bar (
     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.


Add a reply

« Back to message list