我的Web应用程序必须具有从服务器更新数据的热图。 Highcharts JS库可以轻松创建热图,但是数据更新会导致错误:跳过第一行,仅显示最后2个单元格。
我尝试设置turboThreshold
,使用不同的值,使轴保持不变,使用字典和其他一些东西声明值,但这无济于事。我该如何解决这个问题?
// Init works well
var ch1 = Highcharts.chart('chart1', {
chart: { type: 'heatmap' },
xAxis: { categories: ['X1', 'X2'] },
yAxis: { categories: ['Y1', 'Y2'] },
colorAxis: { minColor: '#FFFFFF', maxColor: Highcharts.getOptions().colors[0] },
series: [{
name: 'Z', turboThreshold: 0,
data: [[0, 0, 0], [1, 0, 1], [0, 1, 2], [1, 1, 3]],
dataLabels: { enabled: true, color: '#000000' }
}],
legend: {
align: 'right', layout: 'vertical',
margin: 0, verticalAlign: 'top',
y: 32, symbolHeight: 280
}
});
// This works wrong
function update() {
var data = {
values: [[0, 0, 453], [1, 2, 625], [0, 1, 213], [0, 2, 234]],
xtitle: 'Sum',
xnames: ['300-500', '500-700'],
ytitle: 'Freq',
ynames: ['0-50', '51-100', '101-200']
};
ch1.xAxis[0].setTitle({ text: data.xtitle });
ch1.yAxis[0].setTitle({ text: data.ytitle });
ch1.xAxis[0].setCategories(data.xnames, true);
ch1.yAxis[0].setCategories(data.ynames, true);
ch1.series[0].setData(data.values);
}
// Change the values
setTimeout(update, 3000);
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/heatmap.js"></script>
<div id="chart1" style="min-width: 310px; height: 240px; margin: 0 auto"></div>
答案 0 :(得分:2)
解决方案是将最后一个参数(名为updatePoints
)设置为false
:
ch1.series[0].setData(data.values, true, true, false);
这是因为默认情况下,setData
尝试更新现有的值/实体,但是我需要完全替换它们。
有用的链接: