Chart not appering

Topics: Developer Forum
Sep 11, 2012 at 2:25 PM
Edited Sep 11, 2012 at 2:31 PM

Dear,

I am using basic php code to develop chart , even i am using latest code from github/develop branch. but it still not appearing.

I am using below data generated by simple php-mysql code :

fromArray :

Array
(
    [0] => Array
        (
            [0] => 
            [1] => QATAR
            [2] => SAUDI ARABIA
            [3] => KUWAIT
            [4] => U.A.E.
            [5] => OMAN
        )

    [1] => Array
        (
            [0] => 04/2012
            [1] => 100.51
            [2] => 96.97
            [3] => 101.53
            [4] => 101.38
            [5] => 97.86
        )

    [2] => Array
        (
            [0] => 05/2012
            [1] => 100
            [2] => 100
            [3] => 100
            [4] => 100
            [5] => 100
        )

    [3] => Array
        (
            [0] => 06/2012
            [1] => 100.9
            [2] => 103.71
            [3] => 97.86
            [4] => 0
            [5] => 100.64
        )

)



$dataseriesLabels :
Array
(
    [0] => new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$B$1', null, 1)
    [1] => new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$C$1', null, 1)
    [2] => new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$D$1', null, 1)
    [3] => new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$E$1', null, 1)
    [4] => new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$F$1', null, 1)
)




$dataSeriesValues :

Array
(
    [0] =>  new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$A$2:$A$4', null, 3)
    [1] =>  new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$B$2:$B$4', null, 3)
    [2] =>  new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$C$2:$C$4', null, 3)
    [3] =>  new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$D$2:$D$4', null, 3)
    [4] =>  new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$E$2:$E$4', null, 3)
)



$xAxisTickValues :

Array
(
    [0] => new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$A$2:$A$4', null, 3)
)


Then code to generate graph :

 $objWorksheet = $objPHPExcel->getActiveSheet();
    $objWorksheet->fromArray($mainArray);
    $series = new PHPExcel_Chart_DataSeries(
                    PHPExcel_Chart_DataSeries::TYPE_LINECHART, // plotType
                    PHPExcel_Chart_DataSeries::GROUPING_CLUSTERED, // plotGrouping
                    range(0, count($dataSeriesValues) - 1), // plotOrder
                    $dataseriesLabels, // plotLabel
                    $xAxisTickValues, // plotCategory
                    $dataSeriesValues        // plotValues
    );
//    Set additional dataseries parameters
    $series->setPlotDirection(PHPExcel_Chart_DataSeries::DIRECTION_COL);

//    Set the series in the plot area
    $plotarea = new PHPExcel_Chart_PlotArea(null, array($series));
//    Set the chart legend
    $legend = new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend::POSITION_RIGHT, null, false);

    $title = new PHPExcel_Chart_Title('Test Chart');
    $yAxisLabel = new PHPExcel_Chart_Title('My ');


//    Create the chart
    $chart = new PHPExcel_Chart(
                    'chart1', // name
                    $title, // title
                    $legend, // legend
                    $plotarea, // plotArea
                    true, // plotVisibleOnly
                    0, // displayBlanksAs
                    null, // xAxisLabel
                    $yAxisLabel  // yAxisLabel
    );
//echo $chart;exit;
//    Set the position where the chart should appear in the worksheet
    $chart->setTopLeftPosition('B17');
    $chart->setBottomRightPosition('I30');

//    Add the chart to the worksheet

   $objWorksheet->addChart($chart);


But still chart not appearing ....please help
 
Coordinator
Sep 11, 2012 at 6:12 PM

Are you getting any errors when you save the workbook in PHPExcel, or load the saved workbook in MS Excel?

Are you using $objWriter->setIncludeCharts(TRUE); with your writer?

 

Sep 12, 2012 at 9:37 AM

Dear Mark,

               No i am not using $objWriter->setIncludeCharts(TRUE); ......actually its my 6th sheet where i want graph.......

 

I am getting error when i an trying to assign array directly to forarray ...like::

 

$objWorksheet->fromArray(Array
(
    [0] => Array
        (
            [0] => ''
            [1] => 'QATAR'
            [2] => 'SAUDI ARABIA'
            [3] => 'KUWAIT'
            [4] => 'U.A.E.'
            [5] => 'OMAN'
        )

    [1] => Array
        (
            [0] => '04/2012'
            [1] => 100.51
            [2] => 96.97
            [3] => 101.53
            [4] => 101.38
            [5] => 97.86
        )

    [2] => Array
        (
            [0] => '05/2012'
            [1] => 100
            [2] => 100
            [3] => 100
            [4] => 100
            [5] => 100
        )

    [3] => Array
        (
            [0] =>' 06/2012'
            [1] => 100.9
            [2] => 103.71
            [3] => 97.86
            [4] => 0
            [5] => 100.64
        )

)
);

 

Its giving me error
Parse error: syntax error, unexpected '[', expecting ')' in

 

 

I know its because of syntex ...then i tried with make string of array by using foreach loop .....so again it give me error :

Fatal error:  Uncaught exception 'Exception' with message 'Parameter $source should be an array.' in /opt/lampp/htdocs/scgcc/Classes/PHPExcel/Worksheet.php:2368
Stack trace:
#0 /opt/lampp/htdocs/scgcc/report/searchexcelreport.php(6643): PHPExcel_Worksheet->fromArray('array('','QATAR...')
#1 {main}
  thrown in /opt/lampp/htdocs/scgcc/Classes/PHPExcel/Worksheet.php on line 2368


I know its because it accept only array and i am making string with array word added ....that wont work....



I am very much concern about that which type of array accept by formarray function ......and please tell me how i can make above thing correct....


Thanks

I am waiting for your reply...

 

Sep 12, 2012 at 12:05 PM

one more thing when i tried to add $objWriter->setIncludeCharts(TRUE);  then its throwing me error

 

Fatal error: Call to a member function getPointCount() on a non-object in /opt/lampp/htdocs/scgcc/Classes/PHPExcel/Writer/Excel2007/Chart.php on line 748

 

please help

Sep 12, 2012 at 12:49 PM

Hey, men. 

Each array is composed by a set of elements with comma between them.

E.g.

$exampleArray = array(

$element1,

$element2,

$element3

);

I think, you forgot a comma symbol at the end of each element.

BUT, it's necessary to add  

$objWriter->setIncludeCharts(TRUE); 

Without this function, you couldn't see any charts.

Sep 12, 2012 at 12:52 PM

Thanks padeiro for your reply , dear when i am trying to add  $objWriter->setIncludeCharts(TRUE);  then its giving me error.

 

 

Fatal error: Call to a member function getPointCount() on a non-object in /opt/lampp/htdocs/scgcc/Classes/PHPExcel/Writer/Excel2007/Chart.php on line 748

 

 

i dont know why its happening ...... i am using 6 sheets in one workbook ,,,,,

 

 

please help

Sep 12, 2012 at 1:11 PM

when you add each value to $dataSeriesValues

Array
(
    [0] =>  new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$A$2:$A$4', null, 3)
    [1] =>  new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$B$2:$B$4', null, 3)
    [2] =>  new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$C$2:$C$4', null, 3)
    [3] =>  new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$D$2:$D$4', null, 3)
    [4] =>  new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$E$2:$E$4', null, 3)
)
If you take the values from different pages, you should change Worksheet for one sheet that contains your data.
Otherwise, if you want to make this chart on each of 6 pages, you should make a loop 6 times.

Actually,  everything is fine, besides 2 things:
1. Your arrays $dataseriesLabels, $xAxisTickValues and $dataSeriesValues have to be the same dimension, It means contain
the same number of elements.
Try this for $xAxisTickValues : 
Array
(
 [0] => new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$A$2:$A$4', null, 3),
[1] => new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$A$2:$A$4', null, 3),
[2] => new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$A$2:$A$4', null, 3),
[3] => new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$A$2:$A$4', null, 3),
[4] => new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$A$2:$A$4', null, 3)
)
Each line is the same like first (initial) one.
2. Second thing is maybe you do something wrong with $dataSeriesValues array when you fill it or make initialization.
Sep 12, 2012 at 1:18 PM

Sure i will try this but before i am stuck due to below issue :

 

Please help me .... i can apply what u say above only when i will solove this issue ....please tell me solution of below probs..

 

Thanks padeiro for your reply , dear when i am trying to add  $objWriter->setIncludeCharts(TRUE);  then its giving me error.

 

 

Fatal error: Call to a member function getPointCount() on a non-object in /opt/lampp/htdocs/scgcc/Classes/PHPExcel/Writer/Excel2007/Chart.php on line 748

 

 

i dont know why its happening ...... i am using 6 sheets in one workbook ,,,,,

 

 

please help

Sep 12, 2012 at 1:32 PM

Ok, men. Listen to me.

You have this trouble because you make incorrectly each array initialization. There are 3 principle arrays that I mentioned above. 

You need to be sure about it. Also the last element of the object PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$A$2:$A$4', null, 3) is "3". Right?

So this element shows how many points you want to display ob the chart. It should be the same number like the quantity of points you have. I can't understand your array initialization. So that's why I can't help you. Could you paste here the part of your code about the array initialization?