var chartDef = [
    { id: 'solarEchart', echart: null, type: 'bar', series: ['预测功率', '实时功率', '预测发电量', '实时发电量'] },
    { id: 'chargeEchart', echart: null, type: 'bar', series: ['预测功率', '实时功率'] },
    { id: 'loadEchart', echart: null, type: 'line', series: ['预测功率', '实时功率'] },
]

function getRandomCurveData(m, n) {
    var data = []
    var t0 = Date.parse('2025-07-01 00:00:00')
    var step = 600
    var N = 86400 / step
    var y = 500;
    for (var i = 0; i < N; ++i) {
        var x = t0 + i * step * 1000
        y = Math.floor((y + RAND(0, 20) - 10) * 100) / 100
        data[i] = { name: x, value: [x, y] }
    }
    return data
}

chartDef.forEach((item) => {
    item.echart = initEchartCurve(item.id, item.series, item.yAxisLeft, item.yAxisRight)
    updateEchartCurve(item.echart, 1, getRandomCurveData(100, 200))

    for (var i = 0; i < item.series.length; ++i) {
        updateEchartCurve(item.echart, i, getRandomCurveData(300 * (i + 1), 400 * (i + 1)))
    }
})


window.onresize = () => {

    chartDef.forEach(item => {
        if (item.echart) item.echart.resize()
    })
}