I have developed a program which consists of creating new Excel worksheets containing different cells. The next step would be to generate a vertical bar chart to display various data retrieved from data cells.
All the chart examples work fine, I don't encounter any specific problem, however whenever I try to create my own chart, by calling the rangeToArray() and fromArray() methods, nothing appears in the worksheet, see the subset of my code below to clarify this issue:
The first step consists of creating a new worksheet containing two cells with 40 data per cell, after that, I retrieve the data from those cells by calling rangeToArray() method, then the final step is to call the fromArray() method to use these data to create a graph but it does not work, the graph remains empty, I can only display the title and the yAxisLabel.
I suspect a problem with the fromArray() method but I can't figure out why, could you please help me by giving a similar working example by using this approach? Thanks in advance
$retrieve_data = array();
$retrieve_data = $worksheet->rangetoArray("D8:E48",null,null,null);
$worksheet = $objPHPExcel->getActiveSheet();
$objWorksheet = $worksheet;
$objWorksheet->fromArray($retrieve_data, NULL, 'D8', false);
$dataseriesLabels = array( new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$D$8', null, 1), new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$E$8', null, 1),);
$xAxisTickValues = array( new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$D$8:$D$27', null, 20),);
$dataSeriesValues = array( new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$D$8:$D$27', null, 20), new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$E$8:$E$27', null, 20),);
$series = new PHPExcel_Chart_DataSeries( PHPExcel_Chart_DataSeries::TYPE_BARCHART, plotType PHPExcel_Chart_DataSeries::GROUPING_STANDARD, range(0, count($dataSeriesValues)-1), $dataseriesLabels, $xAxisTickValues, $dataSeriesValues);
$series->setPlotDirection(PHPExcel_Chart_DataSeries::DIRECTION_COL);
$plotarea = new PHPExcel_Chart_PlotArea(null, array($series));
$legend = new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend::POSITION_RIGHT, null, false);
$title = new PHPExcel_Chart_Title('Test Column Chart');
$yAxisLabel = new PHPExcel_Chart_Title('Value');
$chart = new PHPExcel_Chart( 'chart1', $title, $legend, $plotarea, true, 0, null, $yAxisLabel);
$chart->setTopLeftPosition('G2');
$chart->setBottomRightPosition('S20');
$objWorksheet->addChart($chart);
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="BAL_Delhaize2012.xlsx"');
header('Cache-Control: max-age=0');
objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->setIncludeCharts(TRUE);
$objWriter->save('php://output');
I can see two obvious problems in the chart definition:
$xAxisTickValues = array(
new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$D$8:$D$27', null, 20),
);
$dataSeriesValues = array(
new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$D$8:$D$27', null, 20),
new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$E$8:$E$27', null, 20),
);
Should the first set of data series values really be the same as your x-Axis tick values?
$series = new PHPExcel_Chart_DataSeries(
PHPExcel_Chart_DataSeries::TYPE_BARCHART,
plotType PHPExcel_Chart_DataSeries::GROUPING_STANDARD,
range(0, count($dataSeriesValues)-1),
$dataseriesLabels,
$xAxisTickValues,
$dataSeriesValues
);
the word "plotType" should throw a parser error here.
But if you believe that the problem is with the fromArray() method, test that without the chart to confirm that it's doing what you'd expect
Mark,
Oops, I forgot to answer your question. I made a mistake in my example, here's the code about the data series values and the x-Axis tick values:
$dataseriesLabels = array(
new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$D$8', null, 1),
new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$E$8', null, 1),);
$xAxisTickValues = array(
new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$D$9:$D$27', null, 20),);
The label is located in $D$8 and $E$8 cells, while the data as from $D$9 to $D$27
By the way what is the easiest way to debug a problem with this class when you get no error message?
Related
Retrieve a node based on condition:
$query = \Drupal::entityQuery('node')
->condition('type', 'my_content_type')
->condition('title', 'my node title');
$nid = $query->execute();
The result of $nid is the correct node ID but the format is a string, (es: "123")
When I want to load the node by its ID, I write:
$node_id = Node::load($nid);
Doing this, the result I get is NULL because the variable $nid is holding a string (not integer).
If I write the code like this:
$node_id = Node::load(123);
I get the node loaded.
How can I convert the variable string ($nid) as an integer ?
I tried:
$nid_int = (int) $nid;
$node_id = Node::load($nid_int);
also I tried:
$nid_int = intval($nid);
$node_id = Node::load($nid_int);
But I alwas get result NULL
Thanks for your help
You can't use Node::load($nid); directly, because the $query->execute() return an array like ['vid' => "nid"].
$query = \Drupal::entityQuery('node')
->condition('type', 'my_content_type')
->condition('title', 'my node title');
$nids = $query->execute();
$nid = (int)array_shift($nids);
Can try:-
$nid_string = $nid->__toString();
$node_id = Node::load((int) $nid_string);
I want to select fields from SQLite database using ActiveQuery where two columns has equal not empty values.
I need such resulting SQL as example:
SELECT * FROM messages WHERE msg_sent = 0 AND file_size = downloaded_size AND file_sha1 = downloaded_sha1
I've asked for such solution:
use yii\db\Expression;
$messages = Messages::find()
->where([
'file_downloaded' => 1,
])
->andWhere(['=', 'msg_sent', 0])
->andWhere(['=', 'file_size', new Expression('`downloaded_size`')])
->andWhere(['=', 'file_sha1', new Expression('`downloaded_sha1`')])
->asArray()
->all();
// to debug raw SQL I have used the following:
$query = = Messages::find()
->where([
'file_downloaded' => 1,
])
->andWhere(['=', 'msg_sent', 0])
->andWhere(['=', 'file_size', new Expression('`downloaded_size`')])
->andWhere(['=', 'file_sha1', new Expression('`downloaded_sha1`')]);
echo var_dump($query->prepare(Yii::$app->db->queryBuilder)->createCommand()->rawSql) . PHP_EOL;
Assuming you activeRecord class is named MyModel
$models = MyModel::find()
->where(['msg_sent'=> 0,
'file_size'=>'downloaded_size',
'file_sha1' =>'downloaded_sha1'])
->all();
and if don't work hashed format for where you can use the literal format as
$models = MyModel::find()
->where('msg_sent = 0 and file_size= downloaded_size and file_sha1 = downloaded_sha1')
->all();
var ids = ['1', '2', '3'];
var filters = new Array();
filters[0] = new nlobjSearchFilter('mainline', null, 'is', 'T');
filters[4] = new nlobjSearchFilter('entity', null, 'notanyof', ids);
var searchResult = nlapiSearchRecord('creditmemo', null, filters, columns);
Hello I'm trying to list all credit memos but where the customer ID is not 1,2 or 3?
Can you help me? Thanks
The proper operator is "noneof".
new nlobjSearchFilter('entity',null,'noneof',[1,2,3]);
I have a table store the data of image in long blob type, how to retrieve image show in phpexcel? My sample of code:
$order = "SELECT * FROM tblorder";
$tblorder = $conn->query($order);
$row_order = $tblorder->fetch(PDO::FETCH_ASSOC);
$image =$row_order["image"];
$data = base64_encode($image);
$objDrawing = new PHPExcel_Worksheet_MemoryDrawing();
$objDrawing->setName('image');
$objDrawing->setDescription('image');
$objDrawing->getIndexedFilename($data);
$objDrawing->setRenderingFunction(PHPExcel_Worksheet_MemoryDrawing::RENDERING_JPEG);
$objDrawing->setMimeType(PHPExcel_Worksheet_MemoryDrawing::MIMETYPE_DEFAULT);
$objDrawing->setCoordinates('A85');
$objDrawing->setWorksheet($sheet->getActiveSheet());
$pExcel = new PHPExcel();
$pExcel->setActiveSheetIndex(0);
$aSheet = $pExcel->getActiveSheet();
$aSheet->setTitle('Name');
$data ='data://image/jpg;base64,'.base64_encode($row['Picture']);
$gdImage = imagecreatefromjpeg($data);
$objDrawing = new PHPExcel_Worksheet_MemoryDrawing();
$objDrawing->setName('Sample image');
$objDrawing->setDescription('Sample image');
$objDrawing->setImageResource($gdImage);
$objDrawing->setRenderingFunction(PHPExcel_Worksheet_MemoryDrawing::RENDERING_JPEG);
$objDrawing->setMimeType(PHPExcel_Worksheet_MemoryDrawing::MIMETYPE_DEFAULT);
$objDrawing->setHeight(150);
$objDrawing->setCoordinates('I1');
$objDrawing->setWorksheet($aSheet);
if(count($priceRange)){
$facets = new \Elastica\Facet\Range('price');
$facets->setField('price');
foreach ($min as $key => $value) {
$facets->addRange(intval($min[$key])*100, intval($max[$key])*100);
}
$facets->setGlobal(false);
$query->addFacet($facets);
}
This doesn't work for me, I am trying to search on two ways.
Like this:
$client = $this->container->get('fos_elastica.client')
$searcher = new \Elastica\Search($client)
$esResultSet = $searcher->search($query , 500)
$arrayOfResults = $esResultSet->getResults()
$facets = $esResultSet->getFacets()
Or like this
$resultSet = $finder->find($query, 500)
Neither of this works. Why my facet range doesn't work?
Here is more code:
$boolQuery = new \Elastica\Query\Bool();
$fieldText = new \Elastica\Query\Text();
$fieldText->setFieldQuery('name', $keyword);
$fieldText->setFieldParam('name', 'analyzer', 'my_analyzer');
$boolQuery->addMust($fieldText);
$fieldText = new \Elastica\Query\Text();
$fieldText->setFieldQuery('description', $keyword);
$fieldText->setFieldParam('description', 'analyzer', 'my_analyzer');
$boolQuery->addShould($fieldText);
$fieldTerms = new \Elastica\Query\Terms();
$fieldTerms->setTerms('country_id', $countryArray);
$boolQuery->addMust($fieldTerms);
$fieldTerms = new \Elastica\Query\Terms();
$fieldTerms->setTerms('taxon_ids', $themeArray);
$boolQuery->addMust($fieldTerms);
$query->setSort(array("price" => array("order" => "asc")));