KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Not enough columns given to draw the requested chart #2099

Open Augustine Arthur opened this topic on on May 24, 2021 - 6 comments

Augustine Arthur commented on May 24, 2021

Pls I need solution to this error message "Not enough columns given to draw the requested chart". The table and the BarChart display well but the Piechart does not display. Thanks.

Sebastian Morales commented on May 24, 2021

A PieChart needs exactly one label column and one numeric column. Pls post your report view code for us to check it for you. Tks,

Augustine Arthur commented on May 24, 2021

Pls this is the report view code:

RevenueQuarter.view.php

<?php
    use \koolreport\widgets\google;
    use \koolreport\widgets\koolphp\Table;
	use \koolreport\widgets\google\ColumnChart;
	use \koolreport\inputs\Select;
    use \koolreport\clients\bootstrap;
?>

<div class="report-content">
  
    <div class="text-center">
       <h1>Revenue Summary Per Quarter </h1>
        <p class="lead">
           
        </p>
    </div>
    <?php
        $salesYear = isset($_POST['salesYear']) ? 
            $_POST['salesYear'] : array(2017, 2018, 2019, 2020, 2021, 2022);
			//print_r($_POST);
    ?>
    <form method="post" class="text-center">
        <div class="form-group">
            <span style="margin-left:10px;">
                <input id="y2017" type="checkbox" name="salesYear[]" value="2017"
                <?php echo in_array(2017, $salesYear) ? 'checked' : '' ?> />
                <label for="y2017">2017</label>
            </span>
            <span style="margin-left:10px;">
                <input id="y2018" type="checkbox" name="salesYear[]" value="2018" 
                <?php echo in_array(2018, $salesYear) ? 'checked' : '' ?> />
                <label for="y2018">2018</label>
            </span>
            <span style="margin-left:10px;">
                <input id="y2019" type="checkbox" name="salesYear[]" value="2019" 
                <?php echo in_array(2019, $salesYear) ? 'checked' : '' ?> />
                <label for="y2019">2019</label>
            </span>
			<span style="margin-left:10px;">
                <input id="y2020" type="checkbox" name="salesYear[]" value="2020" 
                <?php echo in_array(2020, $salesYear) ? 'checked' : '' ?> />
                <label for="y2020">2020</label>
            </span>
			<span style="margin-left:10px;">
                <input id="y2021" type="checkbox" name="salesYear[]" value="2021" 
                <?php echo in_array(2021, $salesYear) ? 'checked' : '' ?> />
                <label for="y2021">2021</label>
            </span>
			<span style="margin-left:10px;">
                <input id="y2022" type="checkbox" name="salesYear[]" value="2022" 
                <?php echo in_array(2022, $salesYear) ? 'checked' : '' ?> />
                <label for="y2022">2022</label>
            </span>
        </div>
        <div class="form-group">
            <button type="submit" class="btn btn-primary">Submit</button>
			 <button formaction="exportRevenue.php" class="btn btn-primary">Download PDF</button>
			
        </div>
		
    </form>
    <?php 
	
      Table::create(array(
        "dataStore" => $this->dataStore('salesQuarterProductName'),
      ));
    ?>
    <div class='row'>
        <div class="col-md-6">
            <?php 
            google\BarChart::create(array(
                "dataStore"=>$this->dataStore('salesQuarterProductNameNoAll'),
                "options"=>array(
                'title' => 'Barchart Showing Revenue by Regions',
                'isStacked' => true
                ),
                "width"=>'100%',
                // 'height'=>'400px',
            ));
            ?>
        </div>
        <div class="col-md-6">
            <?php 
            google\PieChart::create(array(
                "dataStore"=>$this->dataStore('salesQuarterProductNameAll'),
                "options"=>array(
                'title' => 'Piechart Showing Revenue by Regions',
                ),
                "width"=>'100%',
                // 'height'=>'300px',
            ));
            ?>
        </div>
    </div>

</div>


//This is the RevenueQuartersPdf.view.php

<?php
    use \koolreport\widgets\koolphp\Table;
    use \koolreport\widgets\google\ColumnChart;
	use \koolreport\widgets\google\PieChart;
?>
<html>
    <body style="margin:0.5in 1in 0.5in 1in">
        <link rel="stylesheet" href="../../assets/bootstrap3/bootstrap.min.css" />
        <link rel="stylesheet" href="../../assets/bootstrap3/bootstrap-theme.min.css" />   
       <div class="page-header" style="text-align:right"><i>Revenue Summary</i></div>
        <div class="page-footer" style="text-align:right">{pageNum}</div>
		
        
        <hr/>

<div class="report-content">
   
	 <?php
	//$salesYear = array(2017, 2018, 2019, 2020, 2021, 2022);
     //  $salesYear = isset($_POST['salesYear']) ? 
      //  $_POST['salesYear'] : array(2017, 2018, 2019, 2020, 2021, 2022);
		// foreach ($_POST as $key => $value) {
        // if (strpos($key, "salesYear") === true) {
            // echo $value;
        // }
    // }
		
    ?> 
	<?php
	$salesYear = isset($_POST['salesYear']) ? 
            $_POST['salesYear'] : array(2017, 2018, 2019, 2020, 2021, 2022);
        $salesYearStr = implode(", ", $salesYear);
		
	    
	?>
    <div class="text-center">
        <h1>Revenue Summary Per Quarter For The Year(s) <?php echo $salesYearStr; ?></h1> 
		


	 </h1>
        <p class="lead">
        
        </p>
    </div>
	

    <?php 
      Table::create(array(
        "dataStore" => $this->dataStore('salesQuarterProductName'),
		//WHERE salesYear  !checked;
      ));
    ?>
	
    <div class='row'>
        <div class="col-md-6">
            <?php 
			
            ColumnChart::create(array(
                "dataStore"=>$this->dataStore('salesQuarterProductNameNoAll'),
                "options"=>array(
                'title' => 'Barchart Showing Revenue Summary Ahafo Region',
                'isStacked' => true
                ),
                "width"=>'100%',
                // 'height'=>'400px',
            ));
            ?>
        </div>
        <div class="col-md-6">
            <?php 
            PieChart::create(array(
                "dataStore"=>$this->dataStore('salesQuarterProductNameAll'),
                "options"=>array(
                'title' => 'Piechart Showing Revenue Summary',
                ),
                "width"=>'100%',
                // 'height'=>'300px',
            ));
			
            ?>
			
        </div>
    </div>

</div>
</body>
</html>
Sebastian Morales commented on May 26, 2021

Pls print out the datastore's data in your report view to check its data like this:

//MyReport.view.php
<?php
    print_r($this->dataStore('salesQuarterProductNameAll')->data());        

Then in your PieChart create pls specify exactly 2 columns, the 1st for labels and the 2nd for numeric values, for example:

            <?php 
            PieChart::create(array(
                "dataStore"=>$this->dataStore('salesQuarterProductNameAll'),
                "columns" => array("labelCol", "valueCol"),
                "options"=>array(
                'title' => 'Piechart Showing Revenue Summary',
                ),
                "width"=>'100%',
                // 'height'=>'300px',
            ));
Augustine Arthur commented on May 27, 2021

Hi Sebastian I have implemented your suggestion in the report view as per code below but gives me error: ?php

        google\PieChart::create(array(
            "dataStore"=>$this->dataStore('salesQuarterProductNameAll'),
			"columns" => array("Revenue_Source", "Amount"),
            "options"=>array(
            'title' => 'Piechart Showing Revenue by Regions',
            ),
            "width"=>'100'
           // 'height'=>'300px',
		
        ));
        ?>

However I get the following error message: Notice: Undefined index: Revenue_Source in C:\xampp\htdocs\koolreport\koolreport\core\src\widgets\google\Chart.php on line 159

Notice: Undefined index: Amount in C:\xampp\htdocs\koolreport\koolreport\core\src\widgets\google\Chart.php on line 159

Notice: Undefined index: Revenue_Source in C:\xampp\htdocs\koolreport\koolreport\core\src\widgets\google\Chart.php on line 203

Notice: Undefined index: Amount in C:\xampp\htdocs\koolreport\koolreport\core\src\widgets\google\Chart.php on line 203

Pls any suggestion.

Sebastian Morales commented on May 27, 2021

It meant your datastore doesn't have those columns "Revenue_Source" and "Amount". Like I said, pls print out your datastore's data:

//MyReport.view.php
<?php
    print_r($this->dataStore('salesQuarterProductNameAll')->data());  

to see which columns and data are available. Rgds,

Augustine Arthur commented on May 28, 2021

Hi Sebastian, your suggestion is implemented successfully. The PieChart is now working successfully. Thank you.

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
solved

None