benchew0904 Posted January 6, 2012 Share Posted January 6, 2012 Anyone can help me with plotting of multiple line graph in php. I have researched on multiple line graph online and I would like to plot the graph by taking data from my database but the example below is inserting the graph data manually. Anyone can teach me how to use a for loop inside an array? <?php //Include the code require_once 'phplot.php'; //Define the object $plot = new PHPlot(800,600); //Set titles $plot->SetTitle("A 3-Line Plot\nMade with PHPlot"); $plot->SetXTitle('X Data'); $plot->SetYTitle('Y Data'); //Define some data $example_data = array( array('a',3,4,2), array('b',5,3,1), array('c',7,2,6), array('d',8,1,4), array('e',2,4,6), array('f',6,4,5), array('g',7,2,3) ); $plot->SetDataValues($example_data); //Turn off X axis ticks and labels because they get in the way: $plot->SetXTickLabelPos('none'); $plot->SetXTickPos('none'); //Draw it $plot->DrawGraph(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/254450-multiple-line-graph/ Share on other sites More sharing options...
Ivan Ivković Posted January 6, 2012 Share Posted January 6, 2012 You don't make a for loop INSIDE an array, you make an array IN foor loop. foreach(range('a', 'g') as $letter) { $example_data = array( array($letter,3,4,2) ); } Quote Link to comment https://forums.phpfreaks.com/topic/254450-multiple-line-graph/#findComment-1304860 Share on other sites More sharing options...
benchew0904 Posted January 6, 2012 Author Share Posted January 6, 2012 From your example, "array($letter,3,4,2)", is I want to just a for loop for the following data, is it possible? Quote Link to comment https://forums.phpfreaks.com/topic/254450-multiple-line-graph/#findComment-1305095 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.