1

i have simple php page with script where i fetch data from DB

$plot_row1 = array();
$plot_row2 = array();
$query1 = "SELECT date, name, value FROM list WHERE date between '$s_date' and '$e_date'      
ORDER BY date";

$result = $mysqli->query($query1);
    while ($row = $result->fetch_array(MYSQL_ASSOC))
{
    $sum_list = $sum_list + $row['value'];
    $plot_row1[] = $row['value'];
    $plot_row2[] = $row['date'];
}

Then I would like to have jqplot chart where X axis consists of dates from $plot_row2[] and Y axis contains values from $plot_row2[]

I started with the following code and what I need is to somehow prepared the values (in PHP) in the appropriate way to be used as an input for the jqplot (instead of the question marks).

echo "<div id='loggerChart1' style='height:400px;width:400px;'>";
echo "<script class='code' type='text/javascript' language='javascript'>";

echo "$.jqplot('loggerChart1',  [?????]);";
echo "</script>";
echo "</div>";

Thank you

1
  • And how would the prepared data look like? Comma separated strings/numbers? Commented Sep 22, 2013 at 22:25

2 Answers 2

2
<?php

$prepared_array = ARRAY();

foreach ($plot_row1 AS $key => $value) {
  $prepared_array[] = '['.$plot_row2[$key].','.$value.']';
}
$prepared_string = '['.implode(',', $prepared_array).']';

var_dump($prepared_string);

?>
Sign up to request clarification or add additional context in comments.

Comments

1

x-axis values (you don't have JS code for anything else, so no y-axis, captions, etc.)

$prepared_x_values = '[['.implode(',', $plot_row2).']]';

2 Comments

Thank you, but I do not understands your statement about Y axis. I need the data looks like this: [[$plot_row2,$plot_row1],[$plot_row2,$plot_row1],...] continuously from the 2 arrays...
Well, I had a "short" look on the jqPlot website... And the JS-Code there looks different for all charts I have seen.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.