使用update()函數經過AJAX方法更新表單。

var ajaxCallLiveSubs = function(){

    // endopoint
    var url = 'https://jsonplaceholder.typicode.com/posts/1';

    var interval = 5000;

    var time = 0;

    // Live Subs Charts
    var ctx_live = document.getElementById("myChart");

    var liveChart = new Chart(ctx_live, {
        type: 'line',
        data: {
            labels: [],
            datasets: [{
                data: [],
                borderWidth: 1,
                borderColor:'#00c0ef',
                label: 'liveCount',
            }]
        },
        options: {
            responsive: true,
            maintainAspectRatio: false,
            legend: {
                display: false
            },
            scales: {
                yAxes: [{
                    ticks: {
                        beginAtZero:true,
                    }
                }]
            }
        }
    });

    var doAjax = function() {

        $.ajax({
                    url: url,
                    success: function(){
                        var currentTime = ++time
                        var currentValue = Math.random()*1000;
                        liveChart.data.labels.push(currentTime);
                        liveChart.data.datasets[0].data.push(currentValue);

                        liveChart.update();

                    },
                    complete: function () {
                            // Schedule the next
                            setTimeout(doAjax, interval);
                    }
                });
    };

    doAjax();

};

ajaxCallLiveSubs();

Comment

this.props.history.push

在導航時,您可以將傳遞道具傳遞給歷史對象

this.props.history.push({
    pathname: '/template',
    search: '?query=abc',
    state: { detail: response.data }
})

Comment

vh and vw

vh:表示的是view height,也就是螢幕可視範圍高度的百分比
vw:表示的是view width,也就是螢幕可是範圍寬度的百分比

Comment

陣列元素順序重新排序 sort()

排序函數 sort() 方法,預設為 ASCII 字符順序進行「升序排列」。

陣列.sort()

var Brand = ["Oldsmobile", "Pontiac", "Buick", "Cadillac", "Holden", "Saturn", "GMC"];
Brand.sort()

//輸出 Buick, Cadillac, GMC, Holden, Oldsmobile, Pontiac, Saturn

陣列.reverse()順序反轉

Brand.sort() //陣列重新排序
Brand.reverse() //順序反轉(反轉元素的排列秩序)

//輸出 Saturn, Pontiac, Oldsmobile, Holden, GMC, Cadillac, Buick

Comment

關於Chart.js

Chart.js是一款彈性很高的圖表JavaScript library,支援八種常見的統計圖表類型,夠將圖表混合在一起使用,也支援動畫的效果,讓我們製作出來的圖表更加精美!

範例一 格線顏色與多線條

Chart.js

    var config = {
        type: 'line',
        data: {
            labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
            datasets: [{
                label: 'My First dataset',
                backgroundColor: window.chartColors.red,
                borderColor: window.chartColors.red,
                data: [10, 30, 39, 20, 25, 34, -10],
                fill: false,
            }, {
                label: 'My Second dataset',
                fill: false,
                backgroundColor: window.chartColors.blue,
                borderColor: window.chartColors.blue,
                data: [18, 33, 22, 19, 11, 39, 30],
            }]
        },
        options: {
            responsive: true,
            title: {
                display: true,
                text: 'Grid Line Settings'
            },
            scales: {
                yAxes: [{
                    gridLines: {
                        drawBorder: false,
                        color: ['pink', 'red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'purple']
                    },
                    ticks: {
                        min: 0,
                        max: 100,
                        stepSize: 10
                    }
                }]
            }
        }
    };

    window.onload = function() {
        var ctx = document.getElementById('canvas').getContext('2d');
        window.myLine = new Chart(ctx, config);
    };

Comment

Copyright © 2018 ucamc