Ich habe eine einfache Heatmap in Plotly erstellt. unten ist der Code:dynamische Heatmaps mit Plotly
Eingangsdaten
var zValues = [
[0.10, 0.30, 0.15, 0.25, 0.40],
[0.20, 0.00, 0.75, 0.75, 0.00],
[0.75, 0.75, 0.15, 0.65, 0.20],
[0.50, 0.40, 0.00, 0.05, 0.10]
];
var data = [{
x: xValues,
y: yValues,
z: zValues,
type: 'heatmap',
colorscale: colorscaleValue,
showscale: true
}];
var layout = {
title: 'Annotated Heatmap',
annotations: [],
xaxis: {
ticks: '',
side: 'bottom'
},
yaxis: {
ticks: '',
ticksuffix: ' ',
width: 700,
height: 700,
autosize: false
}
};
for (var i = 0; i < yValues.length; i++) {
for (var j = 0; j < xValues.length; j++) {
var currentValue = zValues[i][j];
if (currentValue != 0.0) {
var textColor = 'white';
}else{
var textColor = 'black';
}
var result = {
xref: 'x1',
yref: 'y1',
x: xValues[j],
y: yValues[i],
text: zValues[i][j],
font: {
family: 'Arial',
size: 12,
color: 'rgb(50, 171, 96)'
},
showarrow: false,
font: {
color: textColor
}
};
layout.annotations.push(result);
}
}
Plotly.newPlot('myDiv', data, layout);
Jetzt möchte ich die Daten (zValues) nach regelmäßigen Abständen aktualisieren (oder die Daten neu mischen), so dass die Farben in der Heatmap auf die Veränderung basierend auf halten sollte die neuen Datenwerte.
Wie geht das?
Dank viel nutzen. es funktionierte – fateh