var windv = document.getElementById('windc').getContext('2d');
var windkmh = document.getElementById('windkmh').getContext('2d');
var windms = document.getElementById('windms').getContext('2d');
var windknp = document.getElementById('windknp').getContext('2d');
var luchtdruk = document.getElementById('luchtdruk').getContext('2d');
var temperatuur = document.getElementById('temperatuur').getContext('2d');
var wolken = document.getElementById('bewolking').getContext('2d');
var mwolken = document.getElementById('mbewolking').getContext('2d');
var hwolken = document.getElementById('hbewolking').getContext('2d');
var neerslag = document.getElementById('neerslag').getContext('2d');
var straling = document.getElementById('straling').getContext('2d');
var zicht = document.getElementById('zicht').getContext('2d');
var radarverwachting = document.getElementById('radarverwachting').getContext('2d');
// $("#windr").html("test");
document.getElementById("windr").innerHTML="
|  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  | 
"; 
var gradient = windv.createLinearGradient(0, 0, 0, 400);
gradient.addColorStop(0, 'rgba(0,111,174,0.8)');
gradient.addColorStop(1, 'rgba(21,31,38,0.5)');
// Functie om min/max waarden te berekenen met 25% marge
function calculateYAxisRange(minValue, maxValue) {
    const range = maxValue - minValue;
    const margin = range * 0.25;
    
    return {
        min: Math.max(0, minValue - margin), // Nooit onder nul
        max: maxValue + margin
    };
}
var radarChart = new Chart(radarverwachting, {
    type: 'bar',
    data: {
        labels: ,
        datasets: [{
            label: 'Radar neerslag',
            data: ,
            backgroundColor: 'rgba(0,111,174,0.8)',
            borderColor: 'rgba(0,111,174,1)',
            borderWidth: 1
        }]
    },
    options: {
        plugins: {
            legend: {
                display: false
            }
        },
        scales: {
            y: {
                ...calculateYAxisRange(0, ),
                ticks: {
                    callback: function(value, index, ticks) {
                        return value + ' mm';
                    }
                }
            }
        },
        plugins: {
            tooltip: {
                enabled: true,
                mode: 'index',
                intersect: false,
                callbacks: {
                    title: function(tooltipItems) {
                        return tooltipItems[0].label + ' uur';
                    },
                    label: function(tooltipItem) {
                        return tooltipItem.raw + ' mm';
                    }
                }
            }
        }
    }
});
var windChart = new Chart(windv, {
    type: 'line',
    data: {
        labels: ["20","21","22","23","00","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21"],
        datasets: [{
            label: 'wind',
            data: [4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,5,5,4,3,4,4,4,4,4,4,4],
            backgroundColor: 'rgba(0,111,174,0.8)',
            borderColor: 'rgba(0,111,174,1)',
            borderWidth: 1,
            fill: true
        }]
    },
    options: {
        plugins: {
            legend: {
                display: false
            }
        },
        scales: {
            y: {
                ...calculateYAxisRange(1, 7),
                ticks: {
                    callback: function(value, index, ticks) {
                        return value + ' bft';
                    }
                }
            }
        },
        plugins: {
            tooltip: {
                enabled: true,
                mode: 'index',
                intersect: false,
                callbacks: {
                    title: function(tooltipItems) {
                        return tooltipItems[0].label + ' uur';
                    },
                    label: function(tooltipItem) {
                        return tooltipItem.raw + ' bft';
                    }
                }
            }
        }
    }
});
var windknpChart = new Chart(windknp, {
    type: 'line',
    data: {
        labels: ["20","21","22","23","00","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21"],
        datasets: [{
            label: 'wind',
            data: [12,12,12,12,12,12,14,14,14,14,14,14,12,12,14,16,16,12,10,12,12,12,14,14,14,14],
            backgroundColor: 'rgba(0,111,174,0.8)',
            borderColor: 'rgba(0,111,174,1)',
            borderWidth: 1,
            fill: true
        }]
    },
    options: {
        plugins: {
            legend: {
                display: false
            }
        },
        scales: {
            y: {
                ...calculateYAxisRange(1, 18),
                ticks: {
                    callback: function(value, index, ticks) {
                        return value + ' knp';
                    }
                }
            }
        },
        plugins: {
            tooltip: {
                enabled: true,
                mode: 'index',
                intersect: false,
                callbacks: {
                    title: function(tooltipItems) {
                        return tooltipItems[0].label + ' uur';
                    },
                    label: function(tooltipItem) {
                        return tooltipItem.raw + ' knp';
                    }
                }
            }
        }
    }
});
var windkmhChart = new Chart(windkmh, {
    type: 'line',
    data: {
        labels: ["20","21","22","23","00","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21"],
        datasets: [{
            label: 'wind',
            data: [21.6,21.6,21.6,21.6,21.6,21.6,25.2,25.2,25.2,25.2,25.2,25.2,21.6,21.6,25.2,28.8,28.8,21.6,18,21.6,21.6,21.6,25.2,25.2,25.2,25.2],
            backgroundColor: 'rgba(0,111,174,0.8)',
            borderColor: 'rgba(0,111,174,1)',
            borderWidth: 1,
            fill: true
        }]
    },
    options: {
        plugins: {
            legend: {
                display: false
            }
        },
        scales: {
            y: {
                ...calculateYAxisRange(1, 30.8),
                ticks: {
                    callback: function(value, index, ticks) {
                        return value + ' km/h';
                    }
                }
            }
        },
        plugins: {
            tooltip: {
                enabled: true,
                mode: 'index',
                intersect: false,
                callbacks: {
                    title: function(tooltipItems) {
                        return tooltipItems[0].label + ' uur';
                    },
                    label: function(tooltipItem) {
                        return tooltipItem.raw + ' km/h';
                    }
                }
            }
        }
    }
});
var windmsChart = new Chart(windms, {
    type: 'line',
    data: {
        labels: ["20","21","22","23","00","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21"],
        datasets: [{
            label: 'wind',
            data: [6,6,6,6,6,6,7,7,7,7,7,7,6,6,7,8,8,6,5,6,6,6,7,7,7,7],
            backgroundColor: 'rgba(0,111,174,0.8)',
            borderColor: 'rgba(0,111,174,1)',
            borderWidth: 1,
            fill: true
        }]
    },
    options: {
        plugins: {
            legend: {
                display: false
            }
        },
        scales: {
            y: {
                ...calculateYAxisRange(1, 10),
                ticks: {
                    callback: function(value, index, ticks) {
                        return value + ' m/s';
                    }
                }
            }
        },
        plugins: {
            tooltip: {
                enabled: true,
                mode: 'index',
                intersect: false,
                callbacks: {
                    title: function(tooltipItems) {
                        return tooltipItems[0].label + ' uur';
                    },
                    label: function(tooltipItem) {
                        return tooltipItem.raw + ' m/s';
                    }
                }
            }
        }
    }
});
var luchtdChart = new Chart(luchtdruk, {
    type: 'line',
    data: {
        labels: ["20","21","22","23","00","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21"],
        datasets: [{
            label: 'luchtdruk',
            data: [1008,1007.8,1007.8,1007.6,1007.5,1007.4,1007.2,1006.7,1006.1,1005.4,1004.9,1004.9,1004.5,1004.2,1003.4,1003.4,1003.3,1003.4,1003.8,1004.2,1004.8,1005.4,1005.8,1006.2,1006.3,1006.4],
            backgroundColor: 'rgba(0,111,174,0.8)',
            borderColor: 'rgba(0,111,174,1)',
            borderWidth: 1,
            fill: true
        }]
    },
    options: {
        plugins: {
            legend: {
                display: false
            }
        },
        scales: {
            y: {
                ...calculateYAxisRange(998, 1013),
                ticks: {
                    callback: function(value, index, ticks) {
                        return value + ' hPa';
                    }
                }
            }
        },
        plugins: {
            tooltip: {
                enabled: true,
                mode: 'index',
                intersect: false,
                callbacks: {
                    title: function(tooltipItems) {
                        return tooltipItems[0].label + ' uur';
                    },
                    label: function(tooltipItem) {
                        return tooltipItem.raw + ' hPa';
                    }
                }
            }
        }
    }
});
var tempChart = new Chart(temperatuur, {
    type: 'line',
    data: {
        labels: ["20","21","22","23","00","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21"],
        datasets: [{
            label: 'temperatuur',
            data: [11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,12,12,12,12,12,11,11,11,11,11,11],
            backgroundColor: 'rgba(0,111,174,0.8)',
            borderColor: 'rgba(0,111,174,1)',
            borderWidth: 1,
            fill: true
        }]
    },
    options: {
        plugins: {
            legend: {
                display: false
            }
        },
        scales: {
            y: {
                ...calculateYAxisRange(10, 14),
                ticks: {
                    callback: function(value, index, ticks) {
                        return value + ' ºC';
                    }
                }
            }
        },
        plugins: {
            tooltip: {
                enabled: true,
                mode: 'index',
                intersect: false,
                callbacks: {
                    title: function(tooltipItems) {
                        return tooltipItems[0].label + ' uur';
                    },
                    label: function(tooltipItem) {
                        return tooltipItem.raw + ' ºC';
                    }
                }
            }
        }
    }
});
var wolkenChart = new Chart(wolken, {
    type: 'bar',
    data: {
        labels: ["20","21","22","23","00","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21"],
        datasets: [{
            label: 'wolken',
            data: [100,3,19,2,0,0,0,0,0,0,0,14,5,100,54,100,100,6,10,2,0,0,10,14,2,52],
            backgroundColor: 'rgba(0,111,174,0.8)',
            borderColor: 'rgba(0,111,174,1)',
            borderWidth: 1
        }]
    },
    options: {
        plugins: {
            legend: {
                display: false
            }
        },
        scales: {
            y: {
                beginAtZero: true,
                ticks: {
                    callback: function(value, index, ticks) {
                        return value + ' %';
                    }
                }
            }
        },
        plugins: {
            tooltip: {
                enabled: true,
                mode: 'index',
                intersect: false,
                callbacks: {
                    title: function(tooltipItems) {
                        return tooltipItems[0].label + ' uur';
                    },
                    label: function(tooltipItem) {
                        return tooltipItem.raw + ' %';
                    }
                }
            }
        }
    }
});
var mwolkenChart = new Chart(mwolken, {
    type: 'bar',
    data: {
        labels: ["20","21","22","23","00","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21"],
        datasets: [{
            label: 'wolken',
            data: [100,93,0,0,0,0,0,32,0,0,0,100,3,100,100,100,100,100,100,1,0,0,0,0,25,0],
            backgroundColor: 'rgba(0,111,174,0.8)',
            borderColor: 'rgba(0,111,174,1)',
            borderWidth: 1
        }]
    },
    options: {
        plugins: {
            legend: {
                display: false
            }
        },
        scales: {
            y: {
                beginAtZero: true,
                ticks: {
                    callback: function(value, index, ticks) {
                        return value + ' %';
                    }
                }
            }
        },
        plugins: {
            tooltip: {
                enabled: true,
                mode: 'index',
                intersect: false,
                callbacks: {
                    title: function(tooltipItems) {
                        return tooltipItems[0].label + ' uur';
                    },
                    label: function(tooltipItem) {
                        return tooltipItem.raw + ' %';
                    }
                }
            }
        }
    }
});
var hwolkenChart = new Chart(hwolken, {
    type: 'bar',
    data: {
        labels: ["20","21","22","23","00","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21"],
        datasets: [{
            label: 'wolken',
            data: [0,0,0,0,0,0,0,0,0,100,100,100,93,100,100,100,100,100,100,100,0,0,0,0,0,0],
            backgroundColor: 'rgba(0,111,174,0.8)',
            borderColor: 'rgba(0,111,174,1)',
            borderWidth: 1
        }]
    },
    options: {
        plugins: {
            legend: {
                display: false
            }
        },
        scales: {
            y: {
                beginAtZero: true,
                ticks: {
                    callback: function(value, index, ticks) {
                        return value + ' %';
                    }
                }
            }
        },
        plugins: {
            tooltip: {
                enabled: true,
                mode: 'index',
                intersect: false,
                callbacks: {
                    title: function(tooltipItems) {
                        return tooltipItems[0].label + ' uur';
                    },
                    label: function(tooltipItem) {
                        return tooltipItem.raw + ' %';
                    }
                }
            }
        }
    }
});
var neerslagChart = new Chart(neerslag, {
    type: 'bar',
    data: {
        labels: ["20","21","22","23","00","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21"],
        datasets: [{
            label: 'neerslag',
            data: [0.2,0,0,0,0,0,0,0,0,0,0,0,0.4,2,1.9,3,1.9,0.6,0.3,0,0,0,0,0,0,0],
            backgroundColor: 'rgba(0,111,174,0.8)',
            borderColor: 'rgba(0,111,174,1)',
            borderWidth: 1
        }]
    },
    options: {
        plugins: {
            legend: {
                display: false
            }
        },
        scales: {
            y: {
                ...calculateYAxisRange(0, 5),
                ticks: {
                    callback: function(value, index, ticks) {
                        return value + ' mm';
                    }
                }
            }
        },
        plugins: {
            tooltip: {
                enabled: true,
                mode: 'index',
                intersect: false,
                callbacks: {
                    title: function(tooltipItems) {
                        return tooltipItems[0].label + ' uur';
                    },
                    label: function(tooltipItem) {
                        return tooltipItem.raw + ' mm';
                    }
                }
            }
        }
    }
});
var stralingChart = new Chart(straling, {
    type: 'bar',
    data: {
        labels: ["20","21","22","23","00","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21"],
        datasets: [{
            label: 'Global radiation',
            data: [0,0,0,0,0,0,0,0,0,0,0,0,3,9,4,2,2,8,7,6,10,0,0,0,0,0],
            backgroundColor: 'rgba(0,111,174,0.8)',
            borderColor: 'rgba(0,111,174,1)',
            borderWidth: 1
        }]
    },
    options: {
        plugins: {
            legend: {
                display: false
            }
        },
        scales: {
            y: {
                ...calculateYAxisRange(0, 15),
                ticks: {
                    callback: function(value, index, ticks) {
                        return value + ' W/m2';
                    }
                }
            }
        },
        plugins: {
            tooltip: {
                enabled: true,
                mode: 'index',
                intersect: false,
                callbacks: {
                    title: function(tooltipItems) {
                        return tooltipItems[0].label + ' uur';
                    },
                    label: function(tooltipItem) {
                        return tooltipItem.raw + ' W/m2';
                    }
                }
            }
        }
    }
});
var zichtChart = new Chart(zicht, {
    type: 'line',
    data: {
        labels: ["20","21","22","23","00","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21"],
        datasets: [{
            label: 'zicht',
            data: [50000,7786,7486,7358,6905,6145,50000,50000,6335,6728,6112,6396,5541,2781,2742,2411,3464,4673,5594,3597,50000,4767,3492,6276,5333,4075],
            backgroundColor: 'rgba(0,111,174,0.8)',
            borderColor: 'rgba(0,111,174,1)',
            borderWidth: 1,
            fill: true
        }]
    },
    options: {
        plugins: {
            legend: {
                display: false
            }
        },
        scales: {
            y: {
                min: 0,
                max: 55000,
                ticks: {
                    callback: function(value, index, ticks) {
                        return value + ' m';
                    }
                }
            }
        },
        plugins: {
            tooltip: {
                enabled: true,
                mode: 'index',
                intersect: false,
                callbacks: {
                    title: function(tooltipItems) {
                        return tooltipItems[0].label + ' uur';
                    },
                    label: function(tooltipItem) {
                        return tooltipItem.raw + ' m';
                    }
                }
            }
        }
    }
});