Change language

How do I make a dynamic graph in PHP using canvasJS?

|
Let’s take an example that needs to create a graph where we can display monthly products sold and purchased. We’ll look at two arrays that we can also look at from our database. Once we get the data from the database and store it in arrays, it can easily draw a dynamic graph using the canvasJS library.Create a file and save it in the project folder. The filename chart_sample.phpcontains the data in an array, where the first array represents purchased products and the second array represents a list of sols products. Now use canvasJS to draw the graph.Example :  
// First array for the purchased item $purchased = array (10 , 15, 19, 0, 5, 7, 0, 0, 12, 13, 10, 1);  
// Second array for the sold product $sold = array (7, 12, 14, 0, 3, 7, 0, 0, 10, 7, 5, 0);  
// Chart data for purchased products $dataPoints = array ( array ( "label" = > "Jan" , "y" = > $purchased [0]), array ( " label " = > "Feb" , "y" = > $purchased [1]), array ( "label" = > "March" , "y" = > $purchased [2]), array ( "label" = > "April" , "y" = > $purchased [3]), array ( "label" = > "May" , "y" = > $purchased [4]), array ( "label" = > "Jun" , "y" = > $purchased [5]), array ( "label" = > "July" , "y" = > $purchased [6]), array ( "label" = > "Aug" , "y" = > $purchased [7]), array ( "label" = > "Sep" , "y" = > $purchased [8]), array ( "label" = > "Oct" , "y" = > $purchased [9]), array ( "label" = > "Nov" , "y" = > $purchased [10]), array ( "label" = > "Dec" , "y" = > $purchased [11]) ) ;  
// Data for plotting the goods sold $dataPoints2 = array ( array ( "label" = > "Jan" , "y" = > $sold [0]), array ( "label" = > "Feb" , "y" = > $sold [1]), array ( "label" = > "March" , "y" = > $sold [2]), array ( "label" = > "April" , "y" = > $sold [3]), array ( "label" = > "May" , "y" = > $sold [4]), array ( "label" = > "Jun" , "y" = > $sold [5]), array ( "label" = > "July" , "y" = > $sold [6]), array ( "label" = > "Aug" , "y" = > $sold [7]), array ( "label" = > "Sep" , "y" = > $sold [8]), array ( "label" = > "Oct" , "y" = > $sold [9]), array ( "label" = > "Nov" , "y" = > $sold [10]), array ( "label" = > "Dec" , "y" = > $sold [11]) ) ;  
?>  


< script src = " https://canvasjs.com/assets/script/canvasjs.min .js " > < / script > < / head >  

< / html >
Output:Link : CanvasJS
SO 1 data error