Upload data from .json or MySQL with Highcharts and Ajax

1

I have a .json document that I keep with MySQL in my database and it contains the following:

{
    "ticker": {
        "base": "BTC",
        "target": "USD",
        "price": "9330.81745211",
        "volume": "53283.57785327",
        "change": "87.84711955"   },
    "timestamp": 1525704301,
    "success": true,
    "error": ""
}

I need to get the price information either from .json or from my database to display them with the following code: p>

<script type="text/javascript">
    Highcharts.setOptions({
        global: {
            useUTC: false
        }
    });

    Highcharts.chart('btc', {
        chart: {
            type: 'spline',
            animation: Highcharts.svg, // don't animate in old IE
            marginRight: 10,
            events: {
                load: requestData
            }
        },
        title: {
            text: 'Bitcoin'
        },
        xAxis: {
            type: 'datetime',
            tickPixelInterval: 150
        },
        yAxis: {
            title: {
                text: 'Precio'
            },
            plotLines: [{
                value: 0,
                width: 1,
                color: '#808080'
            }]
        },
        tooltip: {
            formatter: function () {
                return '<b>' + this.series.name + '</b><br/>' +
                    Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) + '<br/>' +
                    Highcharts.numberFormat(this.y, 2);
            }
        },
        credits:{
            enabled:false
        },
        legend: {
            enabled: false
        },
        exporting: {    
            enabled: false
        },
        series: [{
            name: 'Valor',
            data: [];
        }]
    });

    function requestData() {
            $.ajax({
                url: 'APIcriptomonedas/datosAPI/bitcoin.json',
                type: 'GET',
                async: true,
                dataType: "json",
                success: function(data) {
                    chart.addSeries({
                        data: data.price
                    });
                },
            });
    }
</script>
    
asked by charli 07.05.2018 в 16:53
source

0 answers