Note that there are some explanatory texts on larger screens.

plurals
  1. PODrawing graph with HighRoller / High Charts php
    text
    copied!<p>I am using the php wrapper "highroller" to try and graph some data I have in a table in my database.</p> <p>Now, this code works (from the example):</p> <pre><code>&lt;?php require_once('../HighRoller/HighRoller.php'); require_once('../HighRoller/HighRollerSeriesData.php'); require_once('../HighRoller/HighRollerLineChart.php'); $chartData = array(5324, 7534, 6234, 7234, 8251, 10324); $series1 = new HighRollerSeriesData(); $series1-&gt;addName('myData')-&gt;addData($chartData); $linechart = new HighRollerLineChart(); $linechart-&gt;chart-&gt;renderTo = 'linechart'; $linechart-&gt;title-&gt;text = 'Hello HighRoller'; $linechart-&gt;yAxis-&gt;title-&gt;text = 'Total'; $linechart-&gt;addSeries($series1); ?&gt; &lt;head&gt; &lt;script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"&gt;&lt;/script&gt; &lt;!-- HighRoller: set the location of Highcharts library --&gt; &lt;?php echo HighRoller::setHighChartsLocation("../highcharts/highcharts.js");?&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="linechart"&gt;&lt;/div&gt; &lt;script type="text/javascript"&gt; &lt;?php echo $linechart-&gt;renderChart();?&gt; &lt;/script&gt; &lt;/body&gt; </code></pre> <p>However, I am trying to edit the $chartdata = array(5324,...) so that I can pull this from a database. Here is my attempt:</p> <pre><code>$connection = mysql_connect(#,#,#) or die("Couldn't connect to the server."); $database = mysql_select_db(#, $connection) or die ("Couldn't select the correct database."); $result = mysql_query("SELECT price FROM highroller"); while ($row = mysql_fetch_array($result)){ $priceData[] = $row['price']; } $chartData = $priceData; $linechart = new HighRollerLineChart(); $linechart-&gt;chart-&gt;renderTo = 'linechart'; $linechart-&gt;title-&gt;text = 'Line Chart'; $series1 = new HighRollerSeriesData(); $series1-&gt;addName('myData')-&gt;addData($chartData); $linechart-&gt;addSeries($series1); </code></pre> <p>Now, I am not sure why this does not work as the $priceData is an array just like the previous static array.</p> <p>Also, for reference, here is the function for 'addData' from the library:</p> <pre><code>/** add data to plot in your chart * @param $chartdata - array, data provided in 1 of 3 HighCharts supported array formats (array, assoc array or mult-dimensional array) * @return void */ public function addData($chartdata){ if(!is_array($chartdata)){ die("HighRoller::addData() - data format must be an array."); } $this-&gt;series = array($chartdata); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload