PHPPowerPoint Remove Legend From Bar Graph - php

I am using PHPPowerPoint to export a .ppt file using PHP. I am successful until now when I want to remove the legend from the Bar Graph.
The code which is generating the bar graph is:
$chart1 = new Bar();
$series = new Series('City Distribution', $timeseries);
$series->setShowSeriesName(false);
$series->setShowValue(true);
$series->getFill()->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FF1dd2af'));
$chart1->addSeries($series);
$gFill = new Fill();
$gFill->setFillType(Fill::FILL_GRADIENT_PATH)->setRotation(90)->setStartColor(new Color( 'FF1dd2af' ))->setEndColor(new Color( 'FFFFFFFF' ));
$oFill = new Fill();
$oFill->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FFFFFFFF'));
$oShadow = new Shadow();
$oShadow->setVisible(true)->setDirection(45)->setDistance(10);
// Create a shape (chart)
$shape = $currentSlide->createChartShape();
//$shape->getAlignment()->setVertical( Alignment::VERTICAL_TOP );
$shape->getTitle()->setVisible(false);
$shape->setName('City Distribution')->setResizeProportional(false)->setHeight(300)->setWidth(250)->setOffsetX(25)->setOffsetY(200);
$shape->setFill($oFill);
$shape->getTitle()->setText('City Distribution');
$shape->getTitle()->getFont()->setItalic(true);
$shape->getPlotArea()->getAxisX()->setTitle('City');
$shape->getPlotArea()->getAxisY()->setTitle('Number of Users');
$shape->getPlotArea()->setType($chart1);
$shape->getLegend()->getBorder()->setLineStyle(Border::LINE_SINGLE);
$shape->getLegend()->getFont()->setItalic(true);
This is working just fine but it is putting a legend box, which I want to remove. Any Idea?

Nevermind I figured out it by myself, all you need to do is:
$shape->getLegend()->setVisible(false);
Put it below the line
$shape->getTitle()->setVisible(false);

Related

How to iterate in google ocr textannotation object with php?

I'm trying to get pages, paragraphs, blocks, etc
similar to the code below but in PHP.
https://cloud.google.com/vision/docs/fulltext-annotations
"""Returns document bounds given an image."""
client = vision.ImageAnnotatorClient()
bounds = []
with io.open(image_file, 'rb') as image_file:
content = image_file.read()
image = types.Image(content=content)
response = client.document_text_detection(image=image)
document = response.full_text_annotation
# Collect specified feature bounds by enumerating all document features
for page in document.pages:
for block in page.blocks:
for paragraph in block.paragraphs:
for word in paragraph.words:
for symbol in word.symbols:
if (feature == FeatureType.SYMBOL):
bounds.append(symbol.bounding_box)
if (feature == FeatureType.WORD):
bounds.append(word.bounding_box)
if (feature == FeatureType.PARA):
bounds.append(paragraph.bounding_box)
if (feature == FeatureType.BLOCK):
bounds.append(block.bounding_box)
# The list `bounds` contains the coordinates of the bounding boxes.
I was able to create this
require AUTOLOAD;
use Google\Cloud\Vision\VisionClient;
use Google\Cloud\Vision\V1\ImageAnnotatorClient;
use Google\Cloud\Vision\V1\TextAnnotation;
$path = 'img scr';
$imageAnnotator = new ImageAnnotatorClient();
$image = file_get_contents($path);
$response = $imageAnnotator->documentTextDetection($image);
$texts = $response->getFullTextAnnotation();
But I'm facing a hard time trying to iterate with the TextAnnotation object.
Either I got the message Cannot use object of type Google\Cloud\Vision\V1\TextAnnotation as array .Even if I try to force the object as array.
Here is the documentation from google for the object
To get the result from $response->getFullTextAnnotation(); try the following:
$response->getFullTextAnnotation()->getText();

Teechart PHP CalcXPosreturning 0

I've been trying to use Teechart to draw a couple of graphs for a project. I've managed to draw the graphs just fine. What I am struggling with is annotating specific points on the graph with some labels.
The specific problem is that when I use $chart1->CalcXPos(someIndex); it always returns 0 instead of a value of the pixels. How can I got about resolving this?
$chart1 = new TChart(640,480);
$varname = new Line($chart1->getChart());
$someYValues = array(2,3,5,7,11,13);
$theXValues = array(-3,-1,1,3,4,5);
$i=0;
foreach($someYValues as $x){
$varname->addXY($theXValues[$i],$someYValues[$i]);
$i++;
}
$varname->Setcolor(Color::BLUE());
$chart1->getAxes()->getBottom()->getTitle()->setText("X-axis label (units)");
$chart1->getAxes()->getLeft()->getTitle()->setText("Y-axis label (units)");
$tool=new Annotation($chart1->getChart());
$tool->getShape()->setCustomPosition(true);
//$chart1->paint;
$xvalue = $chart1->getAxes()->getBottom()->CalcXPosValue($theXValues[2]);
$yvalue = $chart1->getAxes()->getLeft()->CalcYPosValue($someYValues[2]);
//$xvalue = $varname->CalcXPosValue($theXValues[2]);
//$yvalue = $varname->CalcYPosValue($someYValues[2]);
echo $xvalue;
echo $yvalue;
$tool->setTop($xvalue);
$tool->setLeft($yvalue);
$tool->setText("Random Text ");
$chart1->render("ecg.png");
Try forcing a chart repaint before using Calc* functions:
$chart1->doInvalidate();

CalendarListEntry not showing up with Google PHP API

I am trying to add an entry with this sample of code :
<?php
$service = new \Google_Service_Calendar($client);
$calendarListEntry = new \Google_Service_Calendar_CalendarListEntry();
$calendarListEntry->setId($calendarId);
$calendarListEntry->setHidden(false);
$calendarListEntry->setSelected(true);
$calendarListEntry = $service->calendarList->insert($calendarListEntry);
The calendar is inserted but not shown on the Gmail Android App. I have to go to settings to display it.
I thought with setHidden() and setSelected() it would work but it didn't change anything. Plus, $calendarListEntry returned after insert has hidden = null.
Any thoughts ?

phppowerpoint pie chart exploding

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.

How can auto post to google plus in PHP?

I find article about Post on Google Plus on
https://developers.google.com/+/api/latest/moments/insert
From that we find example shows how to create moment.
$moment_body = new Google_Moment();
$moment_body->setType("http://schemas.google.com/AddActivity");
$item_scope = new Google_ItemScope();
$item_scope->setId("target-id-1");
$item_scope->setType("http://schemas.google.com/AddActivity");
$item_scope->setName("The Google+ Platform");
$item_scope->setDescription("A page that describes just how awesome Google+ is!");
$item_scope->setImage("https://developers.google.com/+/plugins/snippet/examples/thing.png");
$moment_body->setTarget($item_scope);
$momentResult = $plus->moments->insert('me', 'vault', $moment_body);
From Google APIs Client Library for PHP i'm not find api about Google_ItemScope, and Google_Moment is Google_PlusMomentsService.php. So can not try this example.
Anybody know about this? Or have solution can me try auto post on google plus using PHP?
Thanks
i also found same problem, in new google + api they change class name try below code
$plusservicemoment = new Google_Service_Plus_Moment();
$plusservicemoment->setType("http://schemas.google.com/AddActivity");
$plusService = new Google_Service_Plus($client);
$item_scope = new Google_Service_Plus_ItemScope();
$item_scope->setId('12345');
$item_scope->setType("http://schemas.google.com/AddActivity");
$item_scope->setName("yout site/api name");
$item_scope->setDescription("A page that describes just how html work!");
//$item_scope->setImage("full image path here");
$plusservicemoment->setTarget($item_scope);
$result = $plusService->moments->insert('me','vault',$plusservicemoment);

Categories