Bitcoin Forum

Bitcoin => Project Development => Topic started by: Coinbuddy on July 10, 2015, 10:11:34 AM



Title: How to develop a bitcoin price chart?
Post by: Coinbuddy on July 10, 2015, 10:11:34 AM
Developers please guide us how to develop a bitcoin chart using www.chartjs.org and also for other altcoin.

Show by examples!


Title: Re: How to develop a bitcoin price chart?
Post by: coinableS on July 11, 2015, 12:07:36 AM
Are you just looking for a simple line chart?
Personally, I would create PHP file that pulled the current price and then log the time and price to a database . I'd set a cron job so that it runs once every minute. So you'd have a sql table that looked something like this:

Code:
-------------------------
price         |     time
====================
285.24      |     8:57
285.88      |     8:56
283.65      |     8:55
284.01      |     8:54

From there just query your database and do a loop for each price instance that is in your database. Output your loops into the Labels and Data variables in the JS.

Code:
<script>
    var sqlPrices=[<?php 
    
while($info=mysqli_fetch_array($data))
        echo 
$info['price'].','
    
?>
];
    <?php
    $data
=mysqli_query($mysqli,"SELECT * FROM priceTable");
    
?>

    var sqlLabels=[<?php 
    
while($info=mysqli_fetch_array($data))
        echo 
'"'.$info['time'].'",'
    
?>
];
    </script>

Code:
var data = {
    labels: [sqlLabels],
    datasets: [
        {
            label: "My First dataset",
            fillColor: "rgba(220,220,220,0.2)",
            strokeColor: "rgba(220,220,220,1)",
            pointColor: "rgba(220,220,220,1)",
            pointStrokeColor: "#fff",
            pointHighlightFill: "#fff",
            pointHighlightStroke: "rgba(220,220,220,1)",
            data: [sqlPrices]
        }
    ]
};



Title: Re: How to develop a bitcoin price chart?
Post by: Jeremycoin on July 11, 2015, 02:51:51 AM
You want to make a Bitcoin price chart, please inform me when it finish. :D
I maybe can try it