Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js "></script>
- <script type="text/javascript">
- <?php
- // connect to DB
- $dbfile = "sqlite:/var/www/anubis/db.sqlite3";
- class TableRows extends RecursiveIteratorIterator {
- function __construct($it) {
- parent::__construct($it, self::LEAVES_ONLY);
- }
- function current() {
- if (self::key() == 'date') {
- $dt = DateTime::createFromFormat( "U", parent::current() );
- return 'new Date('. $dt->format("Y, n - 1, j, G, p\a\\r\s\\e\I\\ n\\t(i, 10), s")."),";
- }
- return parent::current() . ",";
- }
- function beginChildren() {
- echo "[";
- }
- function endChildren() {
- echo "]," . "\n";
- }
- }
- try {
- $conn = new PDO($dbfile);
- // set the PDO error mode to exception
- $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- function makeDataDays($days) {
- makeData("today -$days days");
- }
- function makeData($modifier) {
- global $conn;
- $dt = new DateTime();
- $dt->modify($modifier);
- $date = $dt->format('U');
- $stmt = $conn->prepare(
- "SELECT date,
- 100000000*balance,
- 100000000*(balance-T.total),
- 100.0*((balance/T.total)-1.0)
- FROM balance,
- (SELECT b2.balance as total
- FROM balance b2
- WHERE b2.date > $date
- ORDER BY b2.date
- LIMIT 1) T
- WHERE date > $date
- ORDER BY date
- ;");
- $stmt->execute();
- // set the resulting array to associative
- $result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
- echo '[';
- foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) {
- echo $v;
- }
- echo ']';
- }
- ?>
- </script>
- <script type="text/javascript">
- google.charts.load('current', {'packages':['corechart']});
- google.charts.setOnLoadCallback(function() {
- drawChart(<?php makeData("last Sunday"); ?>, 'Week to date', 'ch artweek');
- drawChart(<?php makeData("first day of this month"); ?>, 'Month to date', 'chartmonth');
- drawChart(<?php makeDataDays(7); ?>, '7 days', 'chart7');
- drawChart(<?php makeDataDays(30); ?>, '30 days', 'chart30');
- drawChart(<?php makeData("10 years ago"); ?>, 'All Time', 'chart all');
- });
- function addDataHeader(data) {
- return [['date', 'Balance', 'Profit', '%Profit']].concat(data);
- }
- function drawChart(raw_data, title, domid) {
- var data = google.visualization.arrayToDataTable(addDataHeader(raw_data) );
- var options = {
- title: title,
- //curveType: 'function',
- legend: { position: 'bottom' },
- series: {
- 0: {targetAxisIndex: 0},
- 1: {targetAxisIndex: 0},
- 2: {targetAxisIndex: 1},
- },
- vAxes: {
- // Adds titles to each axis.
- 0: {title: 'satoshi'},
- 1: {title: '%'},
- }
- };
- var chart = new google.visualization.LineChart(document.getElementById(d omid));
- chart.draw(data, options);
- }
- </script>
- </head>
- <body>
- <div id="chartweek" style="width: 900px; height: 500px"></div>
- <div id="chartmonth" style="width: 900px; height: 500px"></div>
- <div id="chart7" style="width: 900px; height: 500px"></div>
- <div id="chart30" style="width: 900px; height: 500px"></div>
- <div id="chartall" style="width: 900px; height: 500px"></div>
- </body>
- </html>
- <?php
- } catch(PDOException $e) {
- echo "Connection failed: " . $e->getMessage();
- }
- $conn = null;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement