pChart 2.x forum
http://wiki.pchart.net/forum/

Can't create multiple series, what am I missing?
http://wiki.pchart.net/forum/viewtopic.php?f=1&t=29455
Page 1 of 1

Author:  ljb2of3 [ Mon Jul 30, 2012 10:54 pm ]
Post subject:  Can't create multiple series, what am I missing?

I've spent the afternoon playing with pChart which so far is working, except for the fact that I'm unable to create multiple series. I have temperature from two probes as well as timestamps associated with each reading.

I can graph one series without issue, but when I add the second series it appears to just append the data from the second series onto the end of the first series. Also, using color coding or weight formatting seems to affect all the points, not just the series I tell it to.

Below is the code I'm using. $allReadings[] is an array containing more arrays that represent each dataset. I have verifed that the two datasets have equal amounts of entries. I've spent the last two hours searching for clues on google and going over the examples trying to find what I'm doing wrong, but I can't find it. Can someone point me in the right direction here?

Code:
#       echo "generating graph";

        $myData = new pData();
        $myData->addPoints($allTimestamps[0], "Timestamp");

        $myData->addPoints($allReadings[0], "Probe 1");
        $myData->addPoints($allReadings[1], "Probe 2");

        $myData->setSerieWeight("Probe 2", 2);

        $myData->setAbscissa("Timestamp");
        $myData->setXAxisName("Time");
        $myData->setXAxisDisplay(AXIS_FORMAT_TIME,"H:i");

        $myData->setAxisName(0,"Temperature");
        $myData->setAxisUnit(0," F");

        $myData->loadPalette("/var/www/palettes/navy.color", TRUE);

        $myPicture = new pImage(1400,500,$myData);
        $myPicture->setFontProperties(array("FontName"=>"/var/www/fonts/Forgotte.ttf","FontSize"=>12));

        $myPicture->setGraphArea(60,40,1380,480);

        $myPicture->drawScale(array("LabelSkip"=>59, "CycleBackground"=>TRUE));
        $myPicture->drawSplineChart();

        $myPicture->Render("/var/www/graph.png");


Thanks,
ljb2of3

Author:  ljb2of3 [ Tue Jul 31, 2012 2:08 pm ]
Post subject:  Re: Can't create multiple series, what am I missing? *neverm

*sigh* Turns out pChart is working perfectly... the issue was me being an idiot. It's been so long since I used PHP or any loosely typed language that it was a simple as me forgetting to reset a variable in a loop. My second dataset also contained my first dataset which why it appeared that my second dataset had been appended to the first and that modifying the color of the second one affected the entire line. Because it was! A simple $var = NULL at the end of the loop and everything is happy!

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/