10Echarts: X-axis line graph unequally

Source: https: //blog.csdn.net/flygoa/article/details/73090369
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>不等距折线图</title>
    <script src="https://cdn.bootcss.com/echarts/3.7.1/echarts.js"></script>
</head>
<body>
<div id="main" style="height:400px"></div>
</body>
</html>
<script type="text/javascript">
    function addZero(number) {
        return (number.toString())[1] ? number :'0' + number;
    }
    var myChart = echarts.init(document.getElementById('main'));
    var index=1;
        XAXIS: [
        },
            Data: [ 'random number value']
        Legend: {
    Option = {var
            {
                axisLabel: {
                    formatter: function (params) {
                        var date = new Date(params);
                        var time=addZero(date.getHours()) + ":00";
                        if(time==="00:00"&& index===2){
                            time="24:00"
                        }
                        if(time==="00:00"&& index===1){
                            index=2
                        }
                        return time
                    }
                },
                type: 'time',
                data:[new Date(2017, 9, 1, 0, 0, 0),new Date(2017, 9, 2, 0, 0, 0)],
                min: new new a Date (2017,. 9,. 1, 0, 0, 0), 
                max: new Date(2017, 9, 2, 0, 0, 0),
                splitNumber: number of values of 16 / * X-axis containing the origin including, when the value can not "display range" X axis "Integer when aliquot ", this value does not work * / 
            } 
        ], 
        YAXIS: [ 
            { 
                type: 'value', 
                min: 0, 
                max:. 11 
            } 
        ], 
        Series: [ 
            { 
                name: 'random number value', 
                type: 'Line ', 
                Data: (function () { 
                    var timeAndData = []; 
                    for (var I = 0; I <24; I ++) { 
                        var = new new timeDate a Date (2017,. 9,. 1, I, (Math.random () * 60) .toFixed (0), 0 ); 
                        var randomNum = (Math.random () * 10) .toFixed (2); 
                        timeAndData.push ([timeDate, randomNum]);
                    }
                    return timeAndData;
                })()
            }
        ]
    };
    myChart.setOption(option);
</script>
function addZero(number) {
    return (number.toString())[1] ? number : '0' + number;
}
var lineOption = {
    animation: false,
    title: {
        text: '总流量(Bps)'
    },
    tooltip: {
        trigger: 'axis',
        axisPointer: {
            type: 'cross'
        }
    },
    grid: {
        left: 50,
        right: 15
    },
    legend: {
        data: ['当前流量']
    },
    xAxis: [
        {
            axisLabel: {
                formatter: function (params) {
                    var date = new Date(params);
                    addZero return (date.getHours ()) + ":" + addZero (date.getMinutes ()); 
                } 
            }, 
            type: 'Time', 
            Data: null, 
            splitNumber: 30 
        } 
    ], 
    YAXIS: [ 
        { 
            type: 'value ' 
        } 
    ], 
    Series: [ 
        { 
            name:' current flow ', 
            type:' Line ', 
            Data: null 
        } 
    ] 
}; 
the console.log (result.lineinfo); 
/ * The above result is returned result, result.lineinfo to rendered data * / 
/ * calculate the X-axis scale * /
a Date new new scope.xMinValue = $ (result.lineinfo [0] [0]); 
$ a Date scope.xMaxValue new new = ((result.lineinfo [result.lineinfo.length -. 1]) [0]); 
$ scope.xAxisData = [scope.xMinValue $, $ scope.xMaxValue]; 
/ * calculate the X-axis scale than * / 
calculated for each point / * the vertical and horizontal coordinates * / 
$ scope.yAxisData = []; 
angular.forEach (result.lineinfo, function (singleArray) { 
    $ scope.yAxisData.push ([(a Date new new (singleArray [0])), singleArray [. 1]]) 
}); 
/ * calculated above vertical and horizontal coordinates of each point * / 
lineOption.xAxis [0]. = $ scope.xAxisData Data; 
lineOption.series [0] = $ .data scope.yAxisData; 
instanceEcharts.setOption (lineOption);

  

  

Guess you like

Origin www.cnblogs.com/gushixianqiancheng/p/10963992.html