View unanswered posts | View active topics It is currently Sun Apr 28, 2024 4:35 pm



Reply to topic  [ 9 posts ] 
two charts in one image 
Author Message
Regular pChart user
Regular pChart user

Joined: Mon Apr 25, 2011 5:24 pm
Posts: 9
Post two charts in one image
hi there

On the 1.37 version it was possible to draw two charts from different data series on the same image with the clearScale() method.

using the pChart 2, how can I generate two or more charts into the same image?


Mon Apr 25, 2011 5:27 pm
Profile
Site Admin
Site Admin
User avatar

Joined: Thu Dec 02, 2010 2:31 pm
Posts: 409
Location: France
Post Re: two charts in one image
Hi,

No need anymore for this function. You can draw as many charts as you want on the same picture. Just redefine the scale each time invoking the drawScale() function.

If you take a look in the documentation, you'll notice many examples of what you're looking for. Take the drawLineChart as a base if you want, there are two charts on the same picture here.

JD.


Tue Apr 26, 2011 8:49 am
Profile WWW
Regular pChart user
Regular pChart user

Joined: Mon Apr 25, 2011 5:24 pm
Posts: 9
Post Re: two charts in one image
ty JD for your fast replay.

The drawLineChart sample use the same dataset. I've cheched the samples from the 2.x versions and thay all are using the same dataset to generate two graphs into the same image.

I assume that I'm too stupid to figure out how to generate two charts into the same image with different data series. :(

$serie1 = array(1, 4, 2, 5, 3);
$serie2 = array(3, 5, 4, 3, 1);

How can I generate a line chart with $serie1 and a bar chart with $serie2 on a single image with those datasets?

ps:As you already know, the succes of your lib depends of the support you provide and the dev comunity you build around your work..

good luck! until now u did a great job.


Tue Apr 26, 2011 11:50 am
Profile
pChart user
pChart user

Joined: Sat Apr 23, 2011 8:45 am
Posts: 5
Location: K-Town, Germany
Post Re: two charts in one image
Hi dodole,

The example from http://wiki.pchart.net/doc.combo.charts.html would be the one you're searching for.

It uses one dataset with all series, too. The clou is to (un)set the series drawable.

Code:
$MyData->addPoints($serie1, "PlotSerie");
$MyData->addPoints($serie2, "BarSerie");
// ...
$MyData->setSerieDrawable("PlotSerie", FALSE);
$myPicture->drawBarChart();

$MyData->setSerieDrawable("PlotSerie", TRUE);
$MyData->setSerieDrawable("BarSerie", FALSE);
$myPicture->drawSplineChart();


Hannes


Tue Apr 26, 2011 12:58 pm
Profile
Regular pChart user
Regular pChart user

Joined: Mon Apr 25, 2011 5:24 pm
Posts: 9
Post Re: two charts in one image
ty hts,

our right, now i get it :)

ps: that's the only way?


Tue Apr 26, 2011 1:08 pm
Profile
Regular pChart user
Regular pChart user

Joined: Mon Apr 25, 2011 5:24 pm
Posts: 9
Post Re: two charts in one image
nono1974 wrote:
I succeed by managing two separated data objects.

can you paste some code about this idea?

I have some problems in understanding the approach. For example how do you call pImage when your using more pData objects?


Mon Jul 18, 2011 11:48 am
Profile
New pChart user
New pChart user

Joined: Mon Sep 19, 2011 2:19 pm
Posts: 1
Post Re: two charts in one image
nono1974 wrote:
$MyData->addPoints($AAA,"AAA");
$MyData->addPoints($abscisse,"Labels");

$myPicture = new pImage(X,Y,$MyData);
.....
$MyData->setSerieDrawable("AAA",TRUE);
$myPicture->drawBarChart();

$MyData2->addPoints($BBB,"BBB")
$PieChart = new pPie($myPicture,$MyData2);
$PieChart->draw3DPie(X,Y,....);

....

$myPicture->stroke();


hey nono1974
can you write the whole code without omitting any of your code? I'm getting crazy trying to create two different charts with two different data objects in one image...


Mon Sep 19, 2011 2:23 pm
Profile
Regular pChart user
Regular pChart user

Joined: Mon Apr 25, 2011 5:24 pm
Posts: 9
Post Re: two charts in one image
I'm also stucked.

I do ;t know how can I have two bar charts with different pData into the same image. Pie has the pPie class which allows to add a different pData into the same image.


Mon Sep 19, 2011 5:40 pm
Profile
New pChart user
New pChart user

Joined: Tue Dec 06, 2011 9:39 pm
Posts: 2
Location: Anchorage, AK
 Re: two charts in one image
I too am having an issue with the "to charts in one image" setup. In the attached image you can see that I am successfully graphing multiple datasets with two different styles. The first are the "envelopes", in this case, the blue and red. They should be drawn as "drawScatterLineChart", while the red & green dots should be drawn as "drawScatterPlotChart". Before I draw the second chart (the dots), I set all the points in the line chart to setSerieDrawable=FALSE, but it is still drawing dots on the line chart. Any ideas?

Code:
include 'func.inc';

/* pChart library inclusions */
include("pChart/class/pData.class.php");
include("pChart/class/pDraw.class.php");
include("pChart/class/pImage.class.php");
include("pChart/class/pScatter.class.php");

/* Create the pData object */
$myData = new pData(); 

/////////// Create all your datasets.
/* GET AIRCRAFT CG ENVELOPE DATA */
$i=1;
$envelope_result = mysql_query("SELECT * FROM `aircraft_envelopes` WHERE `tailnumber` = " . $_REQUEST['tailnumber']);
while($envelope = mysql_fetch_array($envelope_result)) {
   unset($arm); unset($weight);
   $result = mysql_query("SELECT * FROM aircraft_cg WHERE `tailnumber` = " . $_REQUEST['tailnumber'] . " AND envelope = " . $envelope['id']);
   while($row = mysql_fetch_array($result)) {
      $arm[] = $row['arm']; $weight[] = $row['weight'];
   }
   // We have to add the first point back to the end so we have a connected graph
   $arm[] = $arm[0]; $weight[] = $weight[0];

   /* Create the X axis and the binded series */
   $myData->addPoints($arm,"EnvelopeCG" . $envelope['id']);
   $myData->setSerieOnAxis("EnvelopeCG" . $envelope['id'],0);

   /* Create the Y axis and the binded series */
   $myData->addPoints($weight,"EnvelopeWeight" . $envelope['id']);
   $myData->setSerieOnAxis("EnvelopeWeight" . $envelope['id'],1);

   /* Create the scatter chart binding */
   $myData->setScatterSerie("EnvelopeCG" . $envelope['id'],"EnvelopeWeight" . $envelope['id'],$i);
   $myData->setScatterSerieDescription($i,$envelope['name']);
   $myData->setScatterSerieColor($i,array("R"=>hexdec(substr($envelope['color'],0,2)),"G"=>hexdec(substr($envelope['color'],2,2)),"B"=>hexdec(substr($envelope['color'],4,2))));
   
   $i++;
}

   /* Create the X axis and the binded series */
   $myData->setAxisName(0,"Inches From Reference Datum");
   $myData->setAxisXY(0,AXIS_X);
   $myData->setAxisUnit(0,"\"");
   $myData->setAxisPosition(0,AXIS_POSITION_BOTTOM);

   /* Create the Y axis and the binded series */
   $myData->setAxisName(1,"Pounds");
   $myData->setAxisXY(1,AXIS_Y);
   $myData->setAxisPosition(1,AXIS_POSITION_LEFT);

if ($_REQUEST['size']!="small") {
/* Create the X axis and the binded series */
$myData->addPoints($_GET["totarm_to"],"MyCG_TO");
$myData->setSerieOnAxis("MyCG_TO",0);

/* Create the Y axis and the binded series */
$myData->addPoints($_GET["totwt_to"],"MyWeight_TO");
$myData->setSerieOnAxis("MyWeight_TO",1);

/* Create the scatter chart binding */
$myData->setScatterSerie("MyCG_TO","MyWeight_TO",9998);
$myData->setScatterSerieDescription(9998,"Takeoff CG");
$myData->setScatterSerieColor(9998,array("R"=>0,"G"=>160,"B"=>0));

/* Create the X axis and the binded series */
$myData->addPoints($_GET["totarm_ldg"],"MyCG_LDG");
$myData->setSerieOnAxis("MyCG_LDG",0);

/* Create the Y axis and the binded series */
$myData->addPoints($_GET["totwt_ldg"],"MyWeight_LDG");
$myData->setSerieOnAxis("MyWeight_LDG",1);

/* Create the scatter chart binding */
$myData->setScatterSerie("MyCG_LDG","MyWeight_LDG",9999);
$myData->setScatterSerieDescription(9999,"Landing CG");
$myData->setScatterSerieColor(9999,array("R"=>255,"G"=>0,"B"=>0));
}

/* Draw the background */
$Settings = array("R"=>0, "G"=>0, "B"=>0, "Dash"=>1, "DashR"=>190, "DashG"=>203, "DashB"=>107);

/* Create the pChart object, draw the background, set the graph area */
if ($_REQUEST['size']=="small") {
   $myPicture = new pImage(400,195,$myData);
   $myPicture->drawRectangle(0,0,399,194,$Settings);
   $myPicture->setGraphArea(50,25,375,135);
} elseif ($_REQUEST['size']=="print") {
   $myPicture = new pImage(720,950,$myData);
   $myPicture->drawRectangle(0,0,719,949,$Settings);
   $myPicture->setGraphArea(50,25,675,890);
} else {
   $myPicture = new pImage(700,340,$myData);
   $myPicture->drawRectangle(0,0,699,339,$Settings);
   $myPicture->setGraphArea(50,25,675,280);
}

/* Set the default font */
$myPicture->setFontProperties(array("FontName"=>"pChart/fonts/verdana.ttf","FontSize"=>8));

/* Create the Scatter chart object */
$myScatter = new pScatter($myPicture,$myData);

/* Draw the scale */
$myScatter->drawScatterScale();

/* Draw a scatter line chart */
for ($j = 1; $j <= $i; $j++) {
   $myData->setSerieDrawable($j,TRUE);
   $myData->setSerieDrawable(9998,FALSE);
   $myData->setSerieDrawable(9999,FALSE);
}
$myScatter->drawScatterLineChart();

/* Draw a scatter plot chart */
for ($j = 1; $j <= $i; $j++) {
   $myData->setSerieDrawable($j,FALSE);
   $myData->setSerieDrawable(9998,TRUE);
   $myData->setSerieDrawable(9999,TRUE);
}
$myScatter->drawScatterPlotChart();

/* Create data value label & legend */
if ($_REQUEST['size']=="print") {
   $LabelSettings = array("Decimals"=>1,"TitleMode"=>LABEL_TITLE_BACKGROUND,"TitleR"=>255,"TitleG"=>255,"TitleB"=>255,"DrawVerticalLine"=>TRUE);
   $myScatter->writeScatterLabel(9998,0,$LabelSettings);
   $myScatter->writeScatterLabel(9999,0,$LabelSettings);
} elseif ($_REQUEST['size']!="small") {
   $myScatter->drawScatterLegend(60,20,array("Mode"=>LEGEND_VERTICAL,"Style"=>LEGEND_NOBORDER));
   $LabelSettings = array("Decimals"=>1,"NoTitle"=>TRUE,"DrawVerticalLine"=>TRUE);
}

/* Render the picture (choose the best way) */
$myPicture->stroke();


Attachments:
scatter.png
scatter.png [ 18.2 KiB | Viewed 13474 times ]
Sun Feb 12, 2012 6:37 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 9 posts ] 

Who is online

Users browsing this forum: No registered users and 16 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron