I have a set of data that spans a number of dates. Some of the data points need to be identified with a different style so they stand out. I can approximate what I need by creating 2 plot lines using different mark styles but it doesn't look cohesive and can be confusing to some people. Here is an example using that method.
All of the data points in the sample above should be connected. The questions are
Is it possible to create a single plot line with different mark styles?
If the answer to the above is no is there a way to somehow "merge" the 2 plot lines so all of the points get connected?
The code that created the sample graph:
<?php
require_once 'jpgraph/jpgraph.php';
require_once 'jpgraph/jpgraph_line.php';
require_once 'jpgraph/jpgraph_date.php';
$line1D = array(1497844800,1498449600,1505102400,1516597200);
$line1Y = array(79.00,76.00,53.00,14.00);
$line2D = array(1504584000,1507521600);
$line2Y = array(9.87,9.93);
$graph = new Graph(640,480);
$graph->clearTheme();
$graph->SetScale('datlin');
$graph->xaxis->SetLabelAngle(60);
$graph->xaxis->SetFont(FF_ARIAL,FS_NORMAL,8);
$graph->xaxis->SetLabelFormatString('m/d/Y',true);
$graph->yaxis->scale->SetGrace(5);
$line1=new LinePlot($line1Y,$line1D);
$line1->SetColor('#4A6EC6');
$line1->SetWeight(2);
$line1->mark->SetFillColor('#4A6EC6');
$line1->mark->SetType(MARK_FILLEDCIRCLE);
$graph->Add($line1);
$line2=new LinePlot($line2Y,$line2D);
$line2->SetColor('#4A6EC6');
$line2->SetWeight(2);
$line2->mark->SetType(MARK_CIRCLE);
$line2->mark->SetColor('#4A6EC6');
$graph->Add($line2);
$graph->Stroke(); // display the graph
?>
The way to have different marks on a line is to create a 3rd line that is just the line without any marks. Then change the current lines that have marks to be scatter plots instead so just the points are added with the desired marks. When the 3 things are plotted together, 2 scatter plots and the line, they come together as a single line with different marks.
The modified code that works as desired is:
<?php
require_once 'jpgraph/jpgraph.php';
require_once 'jpgraph/jpgraph_line.php';
require_once 'jpgraph/jpgraph_date.php';
require_once 'jpgraph/jpgraph_scatter.php';
$line1D = array(1497844800,1498449600,1505102400,1516597200);
$line1Y = array(79.00,76.00,53.00,14.00);
$line2D = array(1504584000,1507521600);
$line2Y = array(9.87,9.93);
$line3D = array_merge($line1D,$line2D);
$line3Y = array_merge($line1Y,$line2Y);
$graph = new Graph(640,480);
$graph->clearTheme();
$graph->SetScale('datlin');
$graph->xaxis->SetLabelAngle(60);
$graph->xaxis->SetFont(FF_ARIAL,FS_NORMAL,8);
$graph->xaxis->SetLabelFormatString('m/d/Y',true);
$graph->yaxis->scale->SetGrace(5);
$line1=new ScatterPlot($line1Y,$line1D);
$line1->SetColor('#4A6EC6');
$line1->SetWeight(2);
$line1->mark->SetFillColor('#4A6EC6');
$line1->mark->SetType(MARK_FILLEDCIRCLE);
$graph->Add($line1);
$line2=new ScatterPlot($line2Y,$line2D);
$line2->SetColor('#4A6EC6');
$line2->SetWeight(2);
$line2->mark->SetType(MARK_CIRCLE);
$line2->mark->SetColor('#4A6EC6');
$graph->Add($line2);
$line3=new LinePlot($line3Y,$line3D);
$line3->SetColor('#4A6EC6');
$line3->SetWeight(2);
$graph->Add($line3);
$graph->Stroke(); // display the graph
?>
Related
I have this project in php in which my goal is to compare data from the database with some data I get from outlook, and if it's the same data i skip to the next row, otherwise I update.
The data in the DB comes like below:
$db = 'Meeting F2F Planung Meetings/Bilas 2018 2017-09-19 10:002017-09-19 12:0000KI Büro'
The data from outlook:
$outlook = 'Meeting F2F Planung Meetings/Bilas 2018<font size="2"><span style="font-size:10pt;"><div class="PlainText"> </div></span></font>2017-09-19 10:002017-09-19 12:0000KI Büro'
What i do is to get the data from outlook look like the one in DB is:
$outlook = (strip_tags(html_entity_decode($outlook)));
I still get the 'Büro' when I transfrom the data from outlook, so when i compare $outlook and $event, they appear as not equal so in my project it updates.
By asking here I got to the code above, but in this case it doesn't seem to work.
Try this
$outlook = utf8_decode(strip_tags(htmlspecialchars_decode($outlook)));
echo $outlook;
This is my second day messing with the PHP SDK, I've encountered a road block with uploading an attachment to an Estimate with my code. I wanted a PHP form where one can upload a file and shoot it into the QBO company; my first step was to first try and set a static variable to see if it works, my code look slike this:
$Estimate = $dataService->query("SELECT * FROM Estimate WHERE DocNumber in ('{$ID}')");
// Create a new IPPAttachable
$up = "http://www.somedomain.com/test.pdf";
$sendMimeType = "application/pdf";
$randId = rand();
$entityRef = new IPPReferenceType($Estimate->Id);
$attachableRef = new IPPAttachableRef($entityRef);
$objAttachable = new IPPAttachable();
$objAttachable->FileName = $randId."TEST02.pdf";
//$objAttachable->AttachableRef = $Estimate->DocNumber;
$objAttachable->AttachableRef = $attachableRef;
$objAttachable->Note = "Test";
$objAttachable->ContentType = $sendMimeType;
$resultObj = $dataService->Upload($up,
$objAttachable->FileName,
$sendMimeType,
$objAttachable);
This code fires, adds an attachment to the proper estimate but the attachment is less than 1k and is unreadable. Almost as if it never fetched the document to attach, it simply made some kind of a "generic" success.
Can anyone assist with updating the above code? I'm sure its right in front of me, but I keep missing.
Thank you!
I have a project in which data are show in pie chart. It can export the pie chart to powerpoint from php. But the pie chart is show with by exploding. I want to show it without exploding it. Is it possible?
I am using PowerPoint2007. And the code is as following -
<?php
require_once 'iconnect.php';
require_once 'QueryHandler.php';
require_once 'ResultTypes.php';
include_once 'Sample_Header.php';
use PhpOffice\PhpPowerpoint\PhpPowerpoint;
use PhpOffice\PhpPowerpoint\Shape\Chart\Type\Pie3D;
use PhpOffice\PhpPowerpoint\Style\Fill;
use PhpOffice\PhpPowerpoint\Style\Color;
use PhpOffice\PhpPowerpoint\Style\Shadow;
use PhpOffice\PhpPowerpoint\Shape\Chart\Series;
use PhpOffice\PhpPowerpoint\Style\Border;
use PhpOffice\PhpPowerpoint\Style\Alignment;
use PhpOffice\PhpPowerpoint\IOFactory;
Connect(3);
global $linkid;
$queryHandler=new QueryHandler();
$query="SELECT sku,value ".
"FROM ferrero_booker t1,booker_sku t2 ".
"WHERE t1.skuID=t2.skuID ".
"LIMIT 10";
$result = $queryHandler->runQuery($query,$linkid,ResultTypes::$TYPE_ARRAY);
$data=array();
for($i=0;$i<count($result);$i++)
{
$id=$result[$i][0];
$data[$id]=(float)$result[$i][1];
}
$objPHPPowerPoint = new PhpPowerpoint();
$objPHPPowerPoint->getProperties()->setCreator('PHPOffice')
->setLastModifiedBy('PHPPowerPoint Team')
->setTitle('Sample 07 Title')
->setSubject('Sample 07 Subject')
->setDescription('Sample 07 Description')
->setKeywords('office 2007 openxml libreoffice odt php')
->setCategory('Sample Category');
$objPHPPowerPoint->removeSlideByIndex(0);
$currentSlide = createTemplatedSlide($objPHPPowerPoint);
$pie3DChart = new Pie3D();
$series = new Series('', $data);
$series->setShowSeriesName(true);
$series->getDataPointFill(0)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FF4672A8'));
$series->getDataPointFill(1)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FFAB4744'));
$series->getDataPointFill(2)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FF8AA64F'));
$series->getDataPointFill(3)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FF725990'));
$series->getDataPointFill(4)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FF4299B0'));
$series->getDataPointFill(5)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FFDC853E'));
$series->getDataPointFill(6)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FF93A9CE'));
$pie3DChart->addSeries($series);
$shape = $currentSlide->createChartShape();
$shape->setName('PHPPowerPoint Daily Downloads')
->setResizeProportional(false)
->setHeight(550)
->setWidth(700)
->setOffsetX(120)
->setOffsetY(80);
$shape->getBorder()->setLineStyle(Border::LINE_SINGLE);
$shape->getTitle()->setText('Booker Sales');
$shape->getTitle()->getFont()->setItalic(true);
$shape->getPlotArea()->setType($pie3DChart);
$shape->getView3D()->setRotationX(90);
$shape->getView3D()->setPerspective(90);
$shape->getLegend()->getBorder()->setLineStyle(Border::LINE_SINGLE);
$shape->getLegend()->getFont()->setItalic(true);
$oWriterPPTX = IOFactory::createWriter($objPHPPowerPoint, 'PowerPoint2007');
$oWriterPPTX->save("sample.pptx");
print_r($data);
?>
I haven't seen a way to do it in the code, but it's easy to modify the source. Whether you should is another matter, but I won't touch that topic here.
The pie chart explosion is controlled by an "explosion" tag written to the xml, and this happens in the writer. Specifically this file (on my installation/version):
PHPPowerPoint/src/PhpPowerpoint/Writer/PowerPoint2007/Chart.php
Within that file, the following lines add the explosion effect:
// c:explosion
$objWriter->startElement('c:explosion');
$objWriter->writeAttribute('val', '20');
$objWriter->endElement();
You can therefore remove the explosion by suppressing the above lines. If you just want this attribute unconditionally gone, comment the above lines out, or delete them. If you want to extend the API, then add the relevant methods to the Pie chart class and check for the values here, conditionally executing the above lines based on those settings.
I hope this helps.
We have displayed the student statistics for each departments in our application. Everything is working fine for us. But the designs are getting overlap for each student stats.
FYI, See the below screenshot
Here the stats % 0.3 and 1.0 are getting overlapped.
Code:
$color=array("#5c61fb","#bf7a7c","#f46163","#f4fafb","#f4fa63",
"#f4c463","#5cfa63","#bc74f2","#66e1e3","#f4a0ce");
$graph = new PieGraph(750,400,"auto");
$graph->SetShadow();
$graph->SetBackgroundImage('logo.jpg',BGIMG_COPY);
$graph->legend->SetFillColor('lightblue#0.7');
$graph->title->Set("Résultat $_GET[annee] $_GET[bourse]");
//$p1 = new PiePlot3D($arrayx_val);
$p1 = new PiePlot3D($arrayy);
$p1->SetSize(0.5);
$p1->SetCenter(0.4);
$p1->SetSliceColors($color);
$p1->SetLegends($arrayx);
$p1->value->SetFormat('%.1f%%');
//$p1->value->SetFormat("%.5d%%"); //$p1->SetLabelType(PIE_VALUE_ABS);
$p1->SetLabelPos(1);
$p1->value->HideZero();
//$p1->value->SetFont( FF_FONT1, FS_BOLD);
//$p1->value->SetMargin(50);
$p1->SetLabelMargin(20);
//$p1->SetShadow();
$graph->footer->left->SetFont( FF_FONT2, FS_BOLD);
$graph->footer->left->Set("Exclusion : ".$array_footer[0]." Abandon : ".$array_footer[1]." Démission : ".$array_footer[2]."");
$graph->footer-> center-> SetColor("red");
$graph->Add($p1);
$graph->Stroke();
So kindly assist our request and how to avoid this overlapping design as per the screenshot.
Thanks.
Hi so I've been struggling a good while to make the chart I want and I'm getting very close.
First I have performance data of a stock portfolio that should be on YAXIS #1... That's good.
Then I want a benchmark on YAXIS #2... The Line plot works, but the scale is weird :
Notice how it starts at 50 and goes 10, 15, 20, etc...
The thing is the scale should be between 3400 and 3800 since that's the range of my data.
Here is my code :
<?php // content="text/plain; charset=utf-8"
require($_SERVER['DOCUMENT_ROOT'] . '/wp-blog-header.php');
require_once ('jpgraph.php');
require_once ('jpgraph_line.php');
require_once ('jpgraph_date.php');
require_once ('jpgraph_utils.inc.php');
// Get a dataset
$data = get_transient( 'daily_nav' );
$ydata = $data[1];
$xdata = $data[0];
$data2 = get_transient( 'CAC40_history' );
$ydata2 = array_reverse($data2[1]);
$xdata2 = array_reverse($data2[0]);
$dateUtils = new DateScaleUtils();
list($tickPositions, $minTickPositions) = DateScaleUtils::GetTicks($xdata);
// Setup a basic graph
$width=800; $height=500;
$graph = new Graph($width, $height);
$graph->SetScale('datlin');
$graph->SetYScale(0,'lin');
$graph->SetYScale(1,'lin');
$graph->SetMargin(60,20,40,60);
$graph->xaxis->SetPos('min');
$graph->xaxis->SetTickPositions($tickPositions,$minTickPositions);
// Setup the titles
$graph->title->SetFont(FF_GEORGIA,FS_NORMAL,16);
$graph->title->Set('Performance vs. CAC40');
$graph->subtitle->SetFont(FF_ARIAL,FS_ITALIC,10);
$graph->subtitle->Set('graphique journalier depuis la création en juin 2012');
// Setup the labels to be correctly format on the X-axis
$graph->xaxis->SetFont(FF_ARIAL,FS_NORMAL,8);
$graph->xaxis->SetLabelAngle(30);
// The second paramter set to 'true' will make the library interpret the
// format string as a date format. We use a Month + Year format m-d-Y
$graph->xaxis->SetLabelFormatString('m-Y',true);
// And then add line. We use two plots in order to get a
// more distinct border on the graph
$lp2 = new LinePlot($ydata,$xdata);
$lp2->SetColor('#71a7da');
$graph->Add($lp2);
$graph->xgrid->Show();
$graph->AddY(0,$lp2);
// second chart
$lp3 = new LinePlot($ydata2, $xdata2);
$lp3->SetColor('blue');
//$graph->Add($lp3);
//$graph->xgrid->Show();
$graph->AddY(1,$lp3);
// And send back to the client
$graph->Stroke();
?>
Would be great if anyone can help, can't figure this one out.
Thanks
I am quite a newbie but had the same issue myself a minute ago.
Missing zeros on the right? Try changing margin settings?
$graph->SetMargin(60,50,40,60);