CanvasJS是一个JavaScript库,用于轻松为网页创建其他类型的图表。例如条形图,饼图,柱形图,面积图,折线图等。
让我们以需要创建一个图表的示例为例,在该图表中我们可以显示每月销售和购买的产品。我们将考虑两个数组,我们也可以从数据库中考虑它们。一旦我们从数据库中获取数据并将其存储在数组中,它就可以使用canvasJS轻松绘制动态图形。
创建一个文件并将其保存在项目文件夹中。文件名chart_sample.php包含数组形式的数据,其中第一个数组代表购买的产品,第二个数组代表sols产品列表。现在,使用canvasJS绘制图形。
例如:
<"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 to draw graph for sold products $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]) ); "htmlcode"><!DOCTYPE HTML> <html> <head> <script src="/UploadFiles/2021-04-02/canvasjs.min.js">以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。