Highcharts Demo
author(s): Torstein Hønsi
by jeffgw
HTML
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/heatmap.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.slim.min.js"></script>
<h1><span style="color:#444">Dependent Variable:</span> <span id="dvar">88</span>%</h1>
<hr>
<div id="container" style="height: 500px; min-width: 310px; max-width: 800px; margin: 0 auto"></div>
<p>Variables: <span id="va"></span></p>
<p>Range of variables: <span id="ra"></span></p>
<p>Combinations: <span id="c"></span></p>
JavaScript
Xes = 2;
Yes = 2;
range = 5;
dvar = Math.floor(Math.random()*(110-68+1)+68);
$('#dvar').text(dvar);
font = '12px';
if(Xes*Yes < 30){
font = '35px';
}
x = [];
y = [];
for (i = 1; i <= Xes; i++) {
x.push('Class-'+i);
};
for (i = 1; i <= Yes; i++) {
y.push('Measure-'+i);
};
$('#c').text(Math.pow(range,(Xes*Yes)));
$('#va').text(Xes*Yes);
$('#ra').text(range);
dataSet = [];
$.each(x, function(a,b) { // index,value
$.each(y, function(c,d) { // index,value
v = Math.floor(Math.random() * range) + 1;
dataSet.push([a,c,v])
});
});
Highcharts.chart('container', {
chart: {
type: 'heatmap',
marginTop: 40,
marginBottom: 80,
plotBorderWidth: 1
},
credits:{
enabled:false
},
title: {
text: 'Independent Variables'
},
xAxis: {
categories: x
},
yAxis: {
categories: y,
title: null
},
colorAxis: {
min: 1,
max:range,
stops: [
[.1, '#ea9999'],
[.5, '#e1ff39'],
[1, '#8eeca6']
]
},
plotOptions: {
series: {
dataLabels: {
enabled: true,
style: {
fontWeight: 'bold',
fontSize:font,
textOutline:null
}
}
}
},
legend: {
align: 'right',
layout: 'vertical',
margin: 0,
verticalAlign: 'top',
y: 25,
symbolHeight: 280
},
series: [{
name: 'Sales per employee',
borderWidth: 1,
data: dataSet,
dataLabels: {
enabled: true,
color: '#000000'
}
}]
});