Search code examples
phpexceltimebar-chartphpexcel

PHP Excel Bar Chart For Time


I need PHP Excel Bar Chart for time series as Y-Axis. But I cannot able to format it into time or even with string which can accept colon(it may seems as time).


$dataSeriesValues = array( new PHPExcel_Chart_DataSeriesValues('String', 'Trends!$B$2:$B$'.count($classification_chart_data), null, 12), );


The above code is where I am trying to change the time format for Y-axis. PHP Excel Chart What I Have PHP Excel Chart What I Needed

`

$dataSeriesValues = array(
            new PHPExcel_Chart_DataSeriesValues('String', 'Trends!$B$2:$B$'.count($classification_chart_data), null, 12),
        );

` The above is the actual code.


$dataSeriesValues = array( new PHPExcel_Chart_DataSeriesValues('String', 'Trends!$B$2:$B$'.count($classification_chart_data), YYYY-MM-DD HH:MM:SS, 12), );



$dataSeriesValues = array( new PHPExcel_Chart_DataSeriesValues('String', 'Trends!$B$2:$B$'.count($classification_chart_data), FORMAT_TEXT, 12), );


Like this I have tried....


Solution

  • $worksheet->getStyle('B2:D2')->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_TIME4);

    $dataSeriesLabels1 = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$C$2', 'h:mm:ss', 1), // 2011 ];

    $dataSeriesValues1 = [new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$C$2:$C$5', 'h:mm:ss', 1),];

    Sample Image for PHP SpreadSheet with time

    In this way we can use Time format in PhpSpreadSheet