General developer forum

Getting Error in moodle chart api

Picture of santhosh kumar
Getting Error in moodle chart api

Hi All,

 I am working on chart api in moodle 3.4. I am get exception error "Exception - Argument 1 passed to core\chart_base::add_series() must be an instance of core\chart_series, string given, called in [dirroot]\blocks\charttest\moodlechart.php on line 25". What i am missing in code.

// my file is in blocks/charttest/moodlechart.php



$chart = new core\chart_bar();

print_r($chart);        /// printing object value as well

$labels = array(20,40,80,100);
$sales = array(100,200,300,400,500,600,700);
$expenses = array(50,60,70,80,90,100,110);

echo $OUTPUT->render($chart);

Average of ratings: -
Picture of Farhan Karmali
Re: Getting Error in moodle chart api
Core developersParticularly helpful MoodlersPlugin developersTesters

Hi Santosh 

Your series should be in this format 

$series2 = new \core\chart_series('Series 2 (Line)', [400, 460, 1120, 540]);

Please see this for more information

Average of ratings: -