Home forums Using CanvasJS Legends showing only DataPoint Reply To: Legends showing only DataPoint

#7635

Anjali
Participant

andres,

You are echoing data twice for creating JSON, instead of this echo at once and include all required properties within it. For doing the same please follow the below code:

while($row = mysqli_fetch_array($result))
{        
     $point = array("label" => $row['Support'] , "y" => $row['yValues'], "legendText" => $row['Descriptors']);
     array_push($data_points, $point);        
}

$length = sizeof($data_points);

echo "[";
   for ( $i = 0; $i <= $length-1; $i++) { 
	echo "{ \"label\": \"" , $data_points[$i]['label'],"\", \"y\": ", $data_points[$i]['y'], ", 
		\"legendText\": \"" , $data_points[$i]['legendText'], "\" }";

	if( $i < $length-1)
	   echo ",";
   }
echo "]";

__
Anjali