JpGraph : no error but broken picture - php

I make a graph with JPGraph but I've a little problem.
No error was displayed but the picture is a "broken picture".
Here is my code :
$graph = new Graph(1000,300);
$graph->img->SetMargin(40,30,50,40);
$graph->SetScale("textlin");
$graph->title->Set("Graph");
$graph->ygrid->Show();
$graph->ygrid->SetColor('blue#0.7');
$graph->ygrid->SetLineStyle('dashed');
$graph->xgrid->Show();
$graph->xgrid->SetColor('red#0.7');
$graph->xgrid->SetLineStyle('dashed');
$graph->title->SetFont(FF_ARIAL,FS_BOLD,11);
$bigCourbe = array();
$i = 0;
foreach($bigData as $data)
{
var_dump($data);
$courbe = new LinePlot($data);
$courbe->value->Show();
$courbe->value->SetFont(FF_ARIAL,FS_NORMAL,9);
$courbe->value->SetFormat('%d');
$courbe->mark->SetType(MARK_FILLEDCIRCLE);
$courbe->mark->SetFillColor("green");
$courbe->mark->SetWidth(2);
$courbe->SetWeight(10);
echo $function[$i];
$courbe->SetLegend($function[$i++]);
$bigCourbe[] = $courbe;
}
$graph->xaxis->title->Set("Heures");
$graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);
foreach ($bigCourbe as $elem) {
$graph->Add($elem);
}
//$graph->Stroke();
So, the result seems good :
array (size=24)
0 => string '0.000' (length=5)
1 => string '0.000' (length=5)
2 => string '0.000' (length=5)
3 => string '0.000' (length=5)
4 => string '0.000' (length=5)
5 => string '0.000' (length=5)
....
Index HC <- it's the $function[$i] var
array (size=24)
0 => string '0.200' (length=5)
1 => string '0.200' (length=5)
2 => string '0.100' (length=5)
3 => string '0.200' (length=5)
4 => string '0.200' (length=5)
5 => string '0.200' (length=5)
....
Index HP
array (size=24)
0 => string '0.000' (length=5)
1 => string '0.000' (length=5)
2 => string '0.000' (length=5)
3 => string '0.000' (length=5)
4 => string '0.000' (length=5)
5 => string '0.000' (length=5)
Index HPTE
array (size=24)
0 => string '0.200' (length=5)
1 => string '0.200' (length=5)
2 => string '0.100' (length=5)
3 => string '0.200' (length=5)
4 => string '0.200' (length=5)
5 => string '0.200' (length=5)
....
Total Heure
I do not see the problem...
If I remove the debug, and uncomment the $graph->Stroke(); line. I have that :
Can you help me ?
Thank you in advance.

in my case (php 7.1.0) it was Deprecated message
just put
ini_set('display_errors', 0);
at the top of your script and try again.
or
comment out $graph->Stroke(); and see what error(or warning) you have

I know this is an old question but I just had the same problem and fixed it by removing everything before the <?php.
THis was suggested in the link below - check 1.b.
Solution Source

How do you display the graph? Do you have an HTML page? Please show the HTML code.
I have a similar problem where I have no error message, but get the broken image icon.
jpGraph can't include PHP file
One thing I would recommend is to add the lines
//save to file
$fileName = "/tmp/imagefile.png";
$graph->img->Stream($fileName);
if the image from the file is correct, then you can rule out the graph generating code.

Related

Can not match the last group of numbers using php preg_match()

preg_match_all("/(\d{12})
(?:,|$)/","111762396541,561572500056,561729950637,561135281443",$matches);
var_dump($mathes):
array (size=2)
0 =>
array (size=4)
0 => string '561762396543,' (length=13)
1 => string '561572500056,' (length=13)
2 => string '561729950637,' (length=13)
3 => string '561135281443' (length=12)
1 =>
array (size=4)
0 => string '561762396543' (length=12)
1 => string '561572500056' (length=12)
2 => string '561729950637' (length=12)
3 => string '561135281443' (length=12)
But I want the $matches like this:
array (size=4)
0 => string '561762396543,' (length=13)
1 => string '561572500056,' (length=13)
2 => string '561729950637,' (length=13)
3 => string '561135281443' (length=12)
I wanna match groups of numbers(each has 12 digits) and a suffix comma if there is one.The exeption is the last group of numbers,it doesnt have to match a comma,cause it reaches the end of the line.
Try this instead:
preg_match_all("/(\d{12}(?:,|$))/","111762396541,561572500056,561729950637,561135281443",$matches);
When the $ is inside your character range brackets [ ] it is looking for the $ characters not the end-of-line.
EDIT: If you want to include the comma in your matches, then just use the above code sample and look at $matches[0].
If you wanted an easier syntax that matches any sort of word boundary, the \b will match commas and end-of-line, too:
preg_match_all("/(\d{12}\b)/","111762396541,561572500056,561729950637,561135281443",$matches);

Utf8 Sort Array

i have some problems with sorting an array.
List
0 => string 'Australien' (length=10)
1 => string 'Belgien' (length=7)
2 => string 'Botswana' (length=8)
3 => string 'Brasilien' (length=9)
4 => string 'Bulgarien' (length=9)
5 => string 'Burma' (length=5)
6 => string 'China' (length=5)
7 => string 'Costa Rica' (length=10)
73 => string 'Ägypten' (length=8)
But Ägypten should be after Australien.
I already tried with the Collator class but our client wont install the extension.
You can use setlocale along with first parameter LC_COLLATE and second locale with en_US.utf8 and simply sort using usort along with strcoll try as
setlocale(LC_COLLATE, 'en_US.utf8');
$array = array('Australien','Belgien','Botswana','Brasilien','Bulgarien','Burma','China','Costa Rica','Ägypten');
usort($array, 'strcoll');
print_r($array);
Demo

What array function should I use for creating an index?

Hello guys I am trying to create an index of all words on html page that my crawler parses.
At this moment I have managed to breakdown the html page into an array of words and I have filtered out all the stop words.
At this stage I have a few problems.
The array of words from the parsed html page have words that are repeated, I like that because I still have to record how many times a word appeared in the page.
The array looks like this.
$wordsFromHTML =
array (size=119)
0 => string 'web' (length=3)
1 => string 'giants' (length=6)
2 => string 'vryheid' (length=7)
3 => string 'news' (length=4)
4 => string 'access' (length=6)
5 => string 'mails' (length=5)
6 => string 'mobile' (length=6)
7 => string 'february' (length=8)
8 => string 'access' (length=6)
9 => string 'mails' (length=5)
10 => string 'web' (length=3)
11 => string 'february' (length=8)
12 => string 'access' (length=6)
13 => string 'mails' (length=5)
14 => string 'desktop' (length=7)
15 => string 'february' (length=8)
16 => string 'hosting' (length=7)
17 => string 'web' (length=3)
18 => string 'giants' (length=6)
19 => string 'vryheid' (length=7)
20 => string 'february' (length=8)
22 => string 'us' (length=2)
Now I want to save all the words from the $wordsFromHTML to the $indesArray which is my final index.
It should look like this.
$indexArray = array('web'=>array('url'=>array(0,10,17)))
The problem is how to keep incrementing the position ($wordsFromHTML keys) for each word that was repeated from the $wordsFromHTML array in the final index array.
The index array should only have unique words and if another word that already exists try to come in, we use the already existing word which has the same URL and increment its position.
Hope you understand my question.

Smarty value of array extraction using date_format result on other array value as a key

I have two arrays in a smarty template: $months and $contract.
{$months|var_dump} gets this:
array (size=12)
1 => string 'января' (length=12)
2 => string 'февраля' (length=14)
3 => string 'марта' (length=10)
4 => string 'апреля' (length=12)
5 => string 'мая' (length=6)
6 => string 'июня' (length=8)
7 => string 'июля' (length=8)
8 => string 'августа' (length=14)
9 => string 'сентября' (length=16)
10 => string 'октября' (length=14)
11 => string 'ноября' (length=12)
12 => string 'декабря' (length=14)
array values are russian names of months in genitive.
{$contract|var_dump} gets this
'date_till' => '1355518365' (length=10)
so I need to create a month number first from $contract.date_till. it is usually done like
{$contract.date_till|date_format:"%m"}
And now the question is: how do I extract a month name from $months array by the month number made of $contract.date_till with date_format?
I've tried many variants described in smarty manuals, but noone works. For example, this one doesn't:
{$months[{$contract.date_till|date_format:"%m"}]}
{assign var=monthNo value=$contract.date_till|date_format:"%m"}
{$months.$monthNo}
This will give u the month of the necessary date.

SimpleHTMLDom iteration through table

I am using SimpleHTMLDOM to get information from my school roster. The problem is that the table structure is pretty hard to parse and I am looking for some help.
The table looks like this:
http://pastebin.com/xg3mRAHw
The code looks like this:
http://pastebin.com/gWW7WyDA
The result looks like this (also included how I want the result to look like!):
Current format:
array
3 =>
array
'28-11-2011' =>
array
0 => string '08.45-10.30 ' (length=12)
1 => string 'CMD-1 HC interaction design' (length=27)
2 => string 'CMD-1vt-p2.01 - CMD-1vt-p2.18 ' (length=30)
3 => string 'OVk45' (length=5)
4 => string 'J.P. van Leeuwen' (length=16)
5 => string '10.30-12.15 ' (length=12)
6 => string 'CMD-1 Training samenwerken' (length=26)
7 => string 'CMD-1vt-p2.09 - CMD-1vt-p2.10 ' (length=30)
8 => string 'SL433' (length=5)
9 => string 'B. Hartman' (length=10)
Wanted format:
array
3 =>
array
'28-11-2011' =>
array
0 =>
array
'time' => string '08.45-10.30 ' (length=12)
'name' => string 'CMD-1 HC interaction design' (length=27)
'group' => string 'CMD-1vt-p2.01 - CMD-1vt-p2.18 ' (length=30)
'place' => string 'OVk45' (length=5)
'teacher' => string 'J.P. van Leeuwen' (length=16)
1 =>
array
'time' => string '10.30-12.15 ' (length=12)
'name' => string 'CMD-1 Training samenwerken' (length=26)
'group' => string 'CMD-1vt-p2.09 - CMD-1vt-p2.10 ' (length=30)
'place' => string 'SL433' (length=5)
'teacher' => string 'B. Hartman' (length=10)
The problem is that I do not understand how I can get to this result using (only) SimpleHTMLDOM. I am sure that I'm missing something here because I'm close to the final markup of the array. The last step to have it actually show up like the future example is something I cannot get to work.
Could someone give me a few tips on how to proceed and get the array like the way I want it to? I have been looking at XSL too but that is far too complicated for me at this point.
You need to segment the tr array as well.
$count = 0;
foreach ($table as $tr) {
...
$output[$info['week']][$info['date']][$count] = array();
$count++;
...
$output[$info['week']][$info['date']][$count][] = $td->innertext;
Now as for the 'time', 'name', 'group' etc. values, I don't see those anywhere in the xml, so I guess you will just have to maintain an inner count when appending td->innertext.

Categories