Menu

PHPlot stop working when SQL query

2015-11-20
2015-11-23
  • Carlos Cantalapiedra Sánchez

    Hello, I have just downloaded the example code from http://www.phplot.com/ page and it works for me. But if I add a SQL to the code (to get the data from DB to generate the chart) it stops working. The code I added is the following:

    getInfo($_SESSION['id_user']); # PHPlot Example: Bar chart, 3 data sets, shaded $data = array( array('Jan', 40, 2, 4), array('Feb', 30, 3, 4), array('Mar', 20, 4, 4), array('Apr', 10, 5, 4), array('May', 3, 6, 4), array('Jun', 7, 7, 4), array('Jul', 10, 8, 4), array('Aug', 15, 9, 4), array('Sep', 20, 5, 4), array('Oct', 18, 4, 4), array('Nov', 16, 7, 4), array('Dec', 14, 3, 4), ); $plot = new PHPlot(800, 600); $plot->SetImageBorderType('plain'); $plot->SetPlotType('bars'); $plot->SetDataType('text-data'); $plot->SetDataValues($data); # Main plot title: $plot->SetTitle('Shaded Bar Chart with 3 Data Sets'); # Make a legend for the 3 data sets plotted: $plot->SetLegend(array('Engineering', 'Manufacturing', 'Administration')); # Turn off X tick labels and ticks because they don't apply here: $plot->SetXTickLabelPos('none'); $plot->SetXTickPos('none'); $plot->DrawGraph(); ?>

    What is going on? Thank you very much

     
  • Carlos Cantalapiedra Sánchez

     

    Last edit: Carlos Cantalapiedra Sánchez 2015-11-20
  • lbayuk

    lbayuk - 2015-11-20

    Hello,

    It isn't clear if you solved this yourself or not. The forum emails I got say you figured it out, and the solution (as I understand it) was you need to use "new" to create a PHPlot object rather than your framework's "singleton" method. But this isn't in the thread above, so I assume you edited it. Please post back if this is unresolved.

     
  • Carlos Cantalapiedra Sánchez

    No, it's not solved yet. I've noticed that if the code is in an empty php file it works. If I include the controller.php file it still works but when instantiate it ($controller = Controller::singleton();) it stops working.

     

    Last edit: Carlos Cantalapiedra Sánchez 2015-11-23
  • Carlos Cantalapiedra Sánchez

    Ok I got it. It's as simple as changing the $controller = Controller::singleton() for $controller = new Controller(). Now it works perfectly.

    Greetings

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.