Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $dataPoints = array();
- //Best practice is to create a separate file for handling connection to database
- try{
- // Creating a new connection.
- // Replace your-hostname, your-db, your-username, your-password according to your database
- $link = new \PDO( 'mysql:host=localhost;dbname=users;charset=utf8mb4', //'mysql:host=localhost;dbname=canvasjs_db;charset=utf8mb4',
- 'root', //'root',
- '', //'',
- array(
- \PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
- \PDO::ATTR_PERSISTENT => false
- )
- );
- $handle = $link->prepare('select Date, Profits from bot_items_db');
- $handle->execute();
- $result = $handle->fetchAll(\PDO::FETCH_OBJ);
- foreach($result as $row){
- array_push($dataPoints, array("x"=> $PHPstr=strtotime($row->Date)*1000, "y"=> $row->Profits));
- }
- $link = null;
- }
- catch(\PDOException $ex){
- print($ex->getMessage());
- }
- ?>
- <!DOCTYPE HTML>
- <html>
- <head>
- <script>
- window.onload = function () {
- var chart = new CanvasJS.Chart("chartContainer", {
- animationEnabled: true,
- title:{
- text: "Bot(s) Profits by Year"
- },
- axisY: {
- title: "Profits in USD",
- valueFormatString: "#0,,.",
- suffix: "00",
- prefix: "$"
- },
- data: [{
- type: "spline",
- markerSize: 5,
- xValueFormatString: "YYYY",
- yValueFormatString: "$#,##0.##",
- xValueType: "dateTime",
- dataPoints: <?php echo json_encode($dataPoints, JSON_NUMERIC_CHECK); ?>
- }]
- });
- chart.render();
- }
- </script>
- </head>
- <body>
- <div id="chartContainer" style="height: 370px; width: 100%;"></div>
- <script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement