Related
`
<html>
<head>
<script src="https://cdn.plot.ly/plotly-1.58.5.min.js"></script>
<style>
.graph-container {
display: flex;
justify-content: center;
align-items: center;
}
.main-panel {
width: 70%;
float: left;
}
.side-panel {
width: 30%;
background-color: lightgray;
min-height: 300px;
overflow: auto;
float: right;
}
</style>
</head>
<body>
<div class="graph-container">
<div id="myDiv" class="main-panel"></div>
<div id="lineGraph" class="side-panel"></div>
</div>
<script>
var nodes = [
{ x: 0, y: 0, z: 0, value: [1, 2, 3] },
{ x: 1, y: 1, z: 1, value: [4, 5, 6] },
{ x: 2, y: 0, z: 2, value: [7, 8, 9] },
{ x: 3, y: 1, z: 3, value: [10, 11, 12] },
{ x: 4, y: 0, z: 4, value: [13, 14, 15] }
];
var edges = [
{ source: 0, target: 1 },
{ source: 1, target: 2 },
{ source: 2, target: 3 },
{ source: 3, target: 4 }
];
var x = [];
var y = [];
var z = [];
for (var i = 0; i < nodes.length; i++) {
x.push(nodes[i].x);
y.push(nodes[i].y);
z.push(nodes[i].z);
}
const edge_x = [];
const edge_y = [];
const edge_z = [];
for (var i = 0; i < edges.length; i++) {
const a = nodes[edges[i].source];
const b = nodes[edges[i].target];
edge_x.push(a.x, b.x, null);
edge_y.push(a.y, b.y, null);
edge_z.push(a.z, b.z, null);
}
var traceNodes = {
x: x, y: y, z: z,
mode: 'markers',
// marker: { size: 12, color: 'red' },
// marker: { size: 12, color: Array.from({length: nodes.length}, () => 'red') },
text: [0, 1, 2, 3, 4],
// add the color gradient to the nodes from red to blue
// marker: { size: 12, color: Array.from({length: nodes.length}, () => 'red'), colorscale: 'Viridis'},
marker:{color: [1,2,3,4,5],colorscale: [[0, 'rgb(255, 0, 0)'], [1, 'rgb(0, 0, 255)']], showscale: true, size: 12},
hoverinfo: 'text',
hoverlabel: {
bgcolor: 'white'
},
customdata: nodes.map(function(node) {
if (node.value !== undefined)
return node.value;
}),
type: 'scatter3d'
};
var traceEdges = {
x: edge_x,
y: edge_y,
z: edge_z,
//add the color gradient to the lines from red to blue
// line: { color: Array.from({length: edge_x.length}, () => 'red'), width: 5, colorscale: 'Viridis'},
line: {
color: [4,1,4,1,4,1],
colorscale: [[0, 'rgb(255, 0, 0)'], [1, 'rgb(0, 0, 255)']],
showscale: true,
width: 5
},
type: 'scatter3d',
mode: 'lines',
// line: { color: 'red', width: 2, arrow: {size: 50, color: 'black', end:1}},
// line: { color: 'red', width: 2, shape: 'spline', arrow: {size: 500, color: 'black', end:1}},
//add color gradient to the lines
// line: { width: 2, shape: 'spline', arrow: {size: 500, color: 'black', end:1}, colorscale: 'Viridis'},
opacity: 2.8
//add cones shape to the end of the lines
};
var layout = {
margin: { l: 0, r: 0, b: 0, t: 0 }
};
// var traceCone = {
// type: "cone",
// x: [1], y: [1], z: [1],
// u: [1], v: [1], w: [0]
// };
//add the cones shape at the middle of the lines and they are pointing to the end of the lines
var traceCone = {
type: "cone",
x: [0.5, 1.5, 2.5, 3.5], y: [0.5, 0.5, 0.5, 0.5], z: [0.5, 1.5, 2.5, 3.5],
u: [1,1,1,1], v: [1,-1,1,-1], w: [1,1,1,1],
//set the size of the cones
sizemode: "absolute",
sizeref: 0.5,
// give color to cone which have co-oridnates (0.5,0.5,0.5)
colorscale: [[0, 'rgb(255, 0, 0)'], [1, 'rgb(0, 0, 255)']],
// color: [1,2,3,4], // color array
// colorscale: 'Viridis',
showscale: false
// colorscale: 'Viridis',
// color: [1,4,1,1,4,1],
// showscale: false,
};
Plotly.newPlot('myDiv', [traceNodes, traceEdges,traceCone],layout, { displayModeBar: false });
// max y value for the line plot
const ymax = Math.max(...nodes.map(n => n.value).flat());
document.getElementById('myDiv').on('plotly_click', function(data){
var nodeIndex = data.points[0].pointNumber;
var values = nodes[nodeIndex].value;
//change the color of the clicked node to blue and when clicked on another node, change the color of the previous node to red
var update = {
//give the color of the nodes to the initial color
// marker: { color: Array.from({length: nodes.length}, () => 'red') }
//give the color of the nodes to the color gradient
marker: { color: [1,2,3,4,5],colorscale: [[0, 'rgb(255, 0, 0)'], [1, 'rgb(0, 0, 255)']], showscale: true, size: 12}
};
update.marker.color[nodeIndex] = 'blue';
setTimeout(function() {
Plotly.restyle('myDiv', update);
}, 50);
Plotly.newPlot('lineGraph', [{
type: 'scatter',
mode: 'lines',
x: [0, 1, 2],
y: values
}], {
margin: { t: 0 },
yaxis: {autorange: false, range: [0, ymax + 1]}
});
});
</script>
</body>
</html>
The code above shows how to display a 3D network graph , and cones were used as an arrow of the edge.Basically we wanted to give different colors to the cones,but its not working...
Please help us to way out of this problem.
So,the code that I have shown ,assign same color to all the cones (which I dont want), is there any way out?
Unlike scatter traces, cone traces don't have a color property where you can specify an array of numbers that are mapped to a color scale. You can only define what the colorscale is, and its bounds in the color space using cmin and cmax.
The thing (number) that determines the color of a cone is its u/v/w norm in the vector field, and it seems that it's not possible to decide arbitrarily - regardless of that norm - how each cone should be colored.
If I'm not wrong the u/v/w norm is computed as follows :
const norm = Math.sqrt(u**2 + v**2 + w**2);
In your example, all cones are assigned the same color because they all have the same norm, which is √3. If you try to assign different u/v/w values, it should change accordingly.
Is it possible to scale Chart.js background Image so that when the page is resized, the background image is also resized?
Followed the chartjs.org example, but it doesn't resize either.
I've tried CSS on the image object...
Could possibly tie image to around chart that sizes with page.
Suggestions?
//setup block
const data = {
datasets: [{
label: "Elevation",
radius: 0,
borderWidth: 2,
pointBorderColor: 'blue',
pointBackgroundColor: 'red',
data: [{
x: "03/02/2022",
y: "659.63"
}, {
x: "03/03/2022",
y: "659.6"
}, {
x: "03/04/2022",
y: "659.6"
}, {
x: "03/05/2022",
y: "659.63"
}, {
x: "03/06/2022",
y: "659.81"
}, {
x: "03/07/2022",
y: "659.86"
}, {
x: "03/08/2022",
y: "659.99"
}, {
x: "03/09/2022",
y: "660.29"
}, {
x: "03/10/2022",
y: "660.38"
}, {
x: "03/11/2022",
y: "660.39"
}, {
x: "03/12/2022",
y: "660.78"
}, {
x: "03/13/2022",
y: "660.95"
}, {
x: "03/14/2022",
y: "660.95"
}, {
x: "03/15/2022",
y: "661.01"
}, {
x: "03/16/2022",
y: "661.48"
}, {
x: "03/17/2022",
y: "661.39"
}, {
x: "03/18/2022",
y: "661.24"
}, {
x: "03/19/2022",
y: "661.34"
}, {
x: "03/20/2022",
y: "661.44"
}, {
x: "03/21/2022",
y: "661.34"
}, {
x: "03/22/2022",
y: "661.12"
}, {
x: "03/23/2022",
y: "661.27"
}, {
x: "03/24/2022",
y: "661.29"
}, {
x: "03/25/2022",
y: "661.29"
}, {
x: "03/26/2022",
y: "661.29"
}, {
x: "03/27/2022",
y: "661.29"
}, {
x: "03/28/2022",
y: "661.52"
}, {
x: "03/29/2022",
y: "661.53"
}, {
x: "03/30/2022",
y: "661.44"
}, {
x: "03/31/2022",
y: "661.36"
}, {
x: "04/01/2022",
y: "661.0"
}, {
x: "04/02/2022",
y: "660.68"
}, {
x: "04/03/2022",
y: "660.41"
}, {
x: "04/04/2022",
y: "660.247"
}, {
x: "04/05/2022",
y: "660.31"
}, {
x: "04/06/2022",
y: "660.46"
}, {
x: "04/07/2022",
y: "660.7"
}, {
x: "04/08/2022",
y: "660.73"
}, {
x: "04/09/2022",
y: "660.73"
}, {
x: "04/10/2022",
y: "660.73"
}, {
x: "04/11/2022",
y: "660.85"
}, {
x: "04/12/2022",
y: "660.87"
}, {
x: "04/13/2022",
y: "660.83"
}, {
x: "04/14/2022",
y: "660.75"
}, {
x: "04/15/2022",
y: "660.73"
}],
fill: false,
borderColor: 'blue'
}]
};
//plugin block
const chartAreaBorder = {
id: 'chartAreaBorder',
beforeDraw(chart, args, options) {
const {
ctx,
chartArea: {
left,
top,
width,
height
}
} = chart;
ctx.save();
ctx.strokeStyle = options.borderColor;
ctx.lineWidth = options.borderWidth;
ctx.setLineDash(options.borderDash || []);
ctx.lineDashOffset = options.borderDashOffset;
ctx.strokeRect(left, top, width, height);
ctx.restore();
}
};
const image = new Image();
image.src = 'castle.png';
const imgPlugin = {
id: 'custom_canvas_background_image',
beforeDraw: (chart) => {
if (image.complete) {
const ctx = chart.ctx;
const {
top,
left,
width,
height
} = chart.chartArea;
const x = left + width / 2 - image.width / 2;
const y = top + height / 2 - image.height / 2;
ctx.drawImage(image, x, y);
} else {
image.onload = () => chart.draw();
}
}
};
var GradientBgPlugin = {
beforeDraw: function(chart, args, options) {
const ctx = chart.ctx;
const canvas = chart.canvas;
const chartArea = chart.chartArea;
// Chart background
var gradientBack = canvas.getContext("2d").createLinearGradient(0, 0, 0, 250);
gradientBack.addColorStop(0, "rgba(255, 255, 255, 0.7)");
gradientBack.addColorStop(1, "rgba(200, 204, 255, 0.7)");
ctx.fillStyle = gradientBack;
ctx.fillRect(chartArea.left, chartArea.bottom, chartArea.right - chartArea.left, chartArea.top - chartArea.bottom);
}
};
//config block
const config = {
type: 'line',
data: data,
options: {
responsive: true,
plugins: {
legend: {
display: true,
position: 'bottom'
},
title: {
display: true,
text: "HARTWELL PROJECT ",
font: {
size: 20
}
},
},
scales: {
x: {
type: 'time',
time: {
parser: 'MM/dd/yyyy',
unit: 'month',
displayFormats: {
month: 'MMM yyyy'
}
},
title: {
display: true,
text: 'Date'
}
},
y: {
title: {
position: 'left',
display: true,
text: 'Elevation (FT-MSL)'
}
}
},
chartAreaBorder: {
borderColor: 'black',
borderWidth: 10,
//borderDash: [5, 5],
borderDashOffset: 5
},
imgPlugin: {}
},
plugins: [chartAreaBorder, imgPlugin, GradientBgPlugin]
};
// render block
const myChart = new Chart(
document.getElementById('myChart'),
config
);
.chartBox {
position: relative;
margin: auto;
height: 80vh;
width: 80vw;
}
<div class="chartBox">
<canvas id="myChart"></canvas>
</div>
<script src="https://cdn.jsdelivr.net/npm/chart.js/dist/chart.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-date-fns/dist/chartjs-adapter-date-fns.bundle.min.js"></script>
When drawing the image inside the beforeDraw hook, you should should specify its width and height depending on the size of the canvas.
const x = left + width / 2 - height / 2;
const y = top + height / 2 - height / 2;
ctx.drawImage(image, x, y, height, height);
Please take a look at your amended code and see how it works.
const data = {
datasets: [{
label: "Elevation",
radius: 0,
borderWidth: 2,
pointBorderColor: 'blue',
pointBackgroundColor: 'red',
data: [{
x: "03/02/2022",
y: "659.63"
}, {
x: "03/03/2022",
y: "659.6"
}, {
x: "03/04/2022",
y: "659.6"
}, {
x: "03/05/2022",
y: "659.63"
}, {
x: "03/06/2022",
y: "659.81"
}, {
x: "03/07/2022",
y: "659.86"
}, {
x: "03/08/2022",
y: "659.99"
}, {
x: "03/09/2022",
y: "660.29"
}, {
x: "03/10/2022",
y: "660.38"
}, {
x: "03/11/2022",
y: "660.39"
}, {
x: "03/12/2022",
y: "660.78"
}, {
x: "03/13/2022",
y: "660.95"
}, {
x: "03/14/2022",
y: "660.95"
}, {
x: "03/15/2022",
y: "661.01"
}, {
x: "03/16/2022",
y: "661.48"
}, {
x: "03/17/2022",
y: "661.39"
}, {
x: "03/18/2022",
y: "661.24"
}, {
x: "03/19/2022",
y: "661.34"
}, {
x: "03/20/2022",
y: "661.44"
}, {
x: "03/21/2022",
y: "661.34"
}, {
x: "03/22/2022",
y: "661.12"
}, {
x: "03/23/2022",
y: "661.27"
}, {
x: "03/24/2022",
y: "661.29"
}, {
x: "03/25/2022",
y: "661.29"
}, {
x: "03/26/2022",
y: "661.29"
}, {
x: "03/27/2022",
y: "661.29"
}, {
x: "03/28/2022",
y: "661.52"
}, {
x: "03/29/2022",
y: "661.53"
}, {
x: "03/30/2022",
y: "661.44"
}, {
x: "03/31/2022",
y: "661.36"
}, {
x: "04/01/2022",
y: "661.0"
}, {
x: "04/02/2022",
y: "660.68"
}, {
x: "04/03/2022",
y: "660.41"
}, {
x: "04/04/2022",
y: "660.247"
}, {
x: "04/05/2022",
y: "660.31"
}, {
x: "04/06/2022",
y: "660.46"
}, {
x: "04/07/2022",
y: "660.7"
}, {
x: "04/08/2022",
y: "660.73"
}, {
x: "04/09/2022",
y: "660.73"
}, {
x: "04/10/2022",
y: "660.73"
}, {
x: "04/11/2022",
y: "660.85"
}, {
x: "04/12/2022",
y: "660.87"
}, {
x: "04/13/2022",
y: "660.83"
}, {
x: "04/14/2022",
y: "660.75"
}, {
x: "04/15/2022",
y: "660.73"
}],
fill: false,
borderColor: 'blue'
}]
};
//plugin block
const chartAreaBorder = {
id: 'chartAreaBorder',
beforeDraw(chart, args, options) {
const {
ctx,
chartArea: {
left,
top,
width,
height
}
} = chart;
ctx.save();
ctx.strokeStyle = options.borderColor;
ctx.lineWidth = options.borderWidth;
ctx.setLineDash(options.borderDash || []);
ctx.lineDashOffset = options.borderDashOffset;
ctx.strokeRect(left, top, width, height);
ctx.restore();
}
};
const image = new Image();
image.src = 'https://i.stack.imgur.com/S7tJH.png';
const imgPlugin = {
id: 'custom_canvas_background_image',
beforeDraw: (chart) => {
if (image.complete) {
const ctx = chart.ctx;
const {
top,
left,
width,
height
} = chart.chartArea;
const x = left + width / 2 - height / 2;
const y = top + height / 2 - height / 2;
ctx.drawImage(image, x, y, height, height);
} else {
image.onload = () => chart.draw();
}
}
};
var GradientBgPlugin = {
beforeDraw: function(chart, args, options) {
const ctx = chart.ctx;
const canvas = chart.canvas;
const chartArea = chart.chartArea;
// Chart background
var gradientBack = canvas.getContext("2d").createLinearGradient(0, 0, 0, 250);
gradientBack.addColorStop(0, "rgba(255, 255, 255, 0.7)");
gradientBack.addColorStop(1, "rgba(200, 204, 255, 0.7)");
ctx.fillStyle = gradientBack;
ctx.fillRect(chartArea.left, chartArea.bottom, chartArea.right - chartArea.left, chartArea.top - chartArea.bottom);
}
};
//config block
const config = {
type: 'line',
data: data,
options: {
responsive: true,
plugins: {
legend: {
display: true,
position: 'bottom'
},
title: {
display: true,
text: "HARTWELL PROJECT ",
font: {
size: 20
}
},
},
scales: {
x: {
type: 'time',
time: {
parser: 'MM/dd/yyyy',
unit: 'month',
displayFormats: {
month: 'MMM yyyy'
}
},
title: {
display: true,
text: 'Date'
}
},
y: {
title: {
position: 'left',
display: true,
text: 'Elevation (FT-MSL)'
}
}
},
chartAreaBorder: {
borderColor: 'black',
borderWidth: 10,
//borderDash: [5, 5],
borderDashOffset: 5
},
imgPlugin: {}
},
plugins: [chartAreaBorder, imgPlugin, GradientBgPlugin]
};
// render block
const myChart = new Chart(
document.getElementById('myChart'),
config
);
<script src="https://cdn.jsdelivr.net/npm/chart.js/dist/chart.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-date-fns/dist/chartjs-adapter-date-fns.bundle.min.js"></script>
<div class="chartBox">
<canvas id="myChart"></canvas>
</div>
I am new to using highcharts.js. I want to create an activity gauge chart using data from a json file or url. I have understood how they draw the chart but failed to understand the data format used in json to display the chart.
Here is my code
var options = {
chart: {
type: 'solidgauge',
marginTop: 50
},
title: {
text: 'Activity',
style: {
fontSize: '24px'
}
},
tooltip: {
borderWidth: 0,
backgroundColor: 'none',
shadow: false,
style: {
fontSize: '16px'
},
pointFormat: '{series.name}<br><span style="font-size:2em; color: {point.color}; font-weight: bold">{point.y}%</span>',
positioner: function (labelWidth, labelHeight) {
return {
x: 200 - labelWidth / 2,
y: 180
};
}
},
pane: {
startAngle: 0,
endAngle: 360,
background: [{ // Track for Move
outerRadius: '112%',
innerRadius: '88%',
backgroundColor: Highcharts.Color(Highcharts.getOptions().colors[0]).setOpacity(0.3).get(),
borderWidth: 0
}, { // Track for Exercise
outerRadius: '87%',
innerRadius: '63%',
backgroundColor: Highcharts.Color(Highcharts.getOptions().colors[1]).setOpacity(0.3).get(),
borderWidth: 0
}, { // Track for Stand
outerRadius: '62%',
innerRadius: '38%',
backgroundColor: Highcharts.Color(Highcharts.getOptions().colors[2]).setOpacity(0.3).get(),
borderWidth: 0
}]
},
yAxis: {
min: 0,
max: 100,
lineWidth: 0,
tickPositions: []
},
plotOptions: {
solidgauge: {
borderWidth: '34px',
dataLabels: {
enabled: false
},
linecap: 'round',
stickyTracking: false
}
},
series: []
};
var gauge1;
$.getJSON('bryan.json', function(json){
console.log(json)
options.chart.renderTo = 'container';
options.series.data = json
gauge1 = new Highcharts.Chart(options);
});
/**
* In the chart load callback, add icons on top of the circular shapes
*/
function callback()
{
// Move icon
this.renderer.path(['M', -8, 0, 'L', 8, 0, 'M', 0, -8, 'L', 8, 0, 0, 8])
.attr({
'stroke': '#ffffff',
'stroke-linecap': 'round',
'stroke-linejoin': 'round',
'stroke-width': 2,
'zIndex': 10
})
.translate(190, 26)
.add(this.series[2].group);
// Exercise icon
this.renderer.path(['M', -8, 0, 'L', 8, 0, 'M', 0, -8, 'L', 8, 0, 0, 8, 'M', 8, -8, 'L', 16, 0, 8, 8])
.attr({
'stroke': '#ffffff',
'stroke-linecap': 'round',
'stroke-linejoin': 'round',
'stroke-width': 2,
'zIndex': 10
})
.translate(190, 61)
.add(this.series[2].group);
// Stand icon
this.renderer.path(['M', 0, 8, 'L', 0, -8, 'M', -8, 0, 'L', 0, -8, 8, 0])
.attr({
'stroke': '#ffffff',
'stroke-linecap': 'round',
'stroke-linejoin': 'round',
'stroke-width': 2,
'zIndex': 10
})
.translate(190, 96)
.add(this.series[2].group);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="container" style="width: 400px; height: 400px; margin: 0 auto">
</div>
And here is my json data which i thout might be rendered but it didnot.
data.json
First of all, instead of options.series.data = json, you need to create the first series and then populate its data array with your data. Also, set in each point different radius and innerRadius properties. Take a look at the example below.
API Reference:
http://api.highcharts.com/highcharts/series.solidgauge.data.radius
http://api.highcharts.com/highcharts/series.solidgauge.data.innerRadius
Example:
http://jsfiddle.net/x3cne1ng/
var gaugeOptions = {
chart: {
type: 'solidgauge'
},
title: null,
pane: {
center: ['50%', '85%'],
size: '140%',
startAngle: -90,
endAngle: 90,
background: {
backgroundColor: (Highcharts.theme && Highcharts.theme.background2) || '#FADCB5',
innerRadius: '60%',
outerRadius: '100%',
shape: 'arc'
}
},
exporting: {
csv:{
columnHeaderFormatter:function(item, key, series){
if(key === 'y'){
return 'Total Stock (%)';
}else if(key === '' || key === undefined){
return 'Micromarket';
}
}
},
buttons:{
contextButton:{
menuItems: [{
textKey: 'downloadCSV',
onclick: function (){
this.downloadCSV();
}
}]
}
}
},
tooltip: {
enabled: false
},
// the value axis
yAxis: {
stops: [
[0.1, '#F2A23C'], // orange
[0.5, '#F2A23C'],
[0.9, '#F2A23C']
],
lineWidth: 0,
minorTickInterval: null,
tickPixelInterval: 400,
tickWidth: 0,
title: {
y: -70
},
labels: {
y: 16
}
},
plotOptions: {
solidgauge: {
dataLabels: {
y: 5,
borderWidth: 0,
useHTML: true
},
}
}
};
// The speed gauge
$('#container').highcharts(Highcharts.merge(gaugeOptions, {
yAxis: {
min: 0,
max: 100,
title: {
text: ''
}
},
credits: {
enabled: false
},
series: [{
name: 'Speed',
data: [18.41],
includeInCSVExport:false,
dataLabels: {
format: '<div style="text-align:center"><span style="font-size:25px;color:' +
((Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black') + '">{}</span><br/>' +
'<span style="font-size:12px;color:silver"></span></div>'
},
tooltip: {
valueSuffix: ' %'
}
},{
name: 'Foo',
type: 'gauge',
data: [18.41]
}]
}));
// Bring life to the dials
setInterval(function () {
// Speed
var chart = $('#container-speed').highcharts(),
point,
newVal,
inc;
if(chart){
point = chart.series[0].points[0];
inc = Math.round((Math.random() - 0.5) * 100);
newVal = point.y + inc;
if(newVal < 0 || newVal > 100){
newVal = point.y - inc;
}
point.update(newVal);
point = chart.series[1].points[0];
point.update(newVal);
}
}, 2000);
Hi
There is issue with my csv export for gauge chart.
when I export a chart as a csv it downloades the chart as first column with value 0.
Is there any way to avoid that and get only one column for gauge type charts.
currently my csv contains data like below after downloading :
e.g. Micromarket | total stock (%)
0 | 18.41
But i want data should be like this after download :
e.g. total stock (%)
18.41
Please refer my below JS fiddle link for reference.
https://jsfiddle.net/pc9ggjm4/1/
how to make a heatmap's plot area as transparent.
i would like to remove all the white blocks in the chart and make it transparent, so that background colors are visible.
refer this fiddle
$(function () {
$('#container').highcharts({
chart: {
type: 'heatmap',
marginTop: 40,
marginBottom: 40,
backgroundColor: {
linearGradient: { x1: 1, y1: 0, x2: 0, y2: 1 },
stops: [
[0.23, 'rgb(240, 59, 9)'],
[0.5, 'rgb(255, 224, 80)'],
[0.67, 'rgb(54, 64, 207)'],
[0.99, 'rgb(13, 163, 35)'],
[1, 'rgb(217, 186, 50']
]
},
},
title: {
text: 'Sales per employee per weekday'
},
xAxis: {
categories: ['Alexander', 'Marie', 'Maximilian', 'Sophia', 'Lukas', 'Maria', 'Leon', 'Anna', 'Tim', 'Laura']
},
yAxis: {
categories: ['< 1%', '2-10%', '11-50%', '51-90%', '91-100%'],
title: null
},
colorAxis: {
min: 0,
minColor: '#FFFFFF',
maxColor:'#FFFFFF'
//maxColor: Highcharts.getOptions().colors[0]
},
legend: {
align: 'right',
layout: 'vertical',
margin: 0,
verticalAlign: 'top',
y: 25,
symbolHeight: 320
},
tooltip: {
formatter: function () {
return '<b>' + this.series.xAxis.categories[this.point.x] + '</b> sold <br><b>' +
this.point.value + '</b> items on <br><b>' + this.series.yAxis.categories[this.point.y] + '</b>';
}
},
series: [{
name: 'Sales per employee',
borderWidth: 1,
data: [[0,0,0],[0,1,19],[0,2,8],[0,3,24],[0,4,67],[1,0,92],[1,1,58],[1,2,78],[1,3,117],[1,4,48],[2,0,35],[2,1,15],[2,2,123],[2,3,64],[2,4,52],[3,0,72],[3,1,132],[3,2,114],[3,3,19],[3,4,16],[4,0,38],[4,1,5],[4,2,8],[4,3,117],[4,4,115],[5,0,88],[5,1,32],[5,2,12],[5,3,6],[5,4,120],[6,0,13],[6,1,44],[6,2,88],[6,3,98],[6,4,96],[7,0,31],[7,1,1],[7,2,82],[7,3,32],[7,4,30],[8,0,85],[8,1,97],[8,2,123],[8,3,64],[8,4,84],[9,0,47],[9,1,114],[9,2,31],[9,3,48],[9,4,91]],
dataLabels: {
enabled: true,
color: 'black',
style: {
textShadow: 'none'
}
}
}]
});
});
Here is the fiddle solution
$(function () {
$('#container').highcharts({
chart: {
type: 'heatmap',
marginTop: 40,
marginBottom: 40,
plotBackgroundColor: {
linearGradient: { x1: 1, y1: 0, x2: 0, y2: 1 },
stops: [
[0.03, 'rgb(247, 88, 45)'],
[0.5, 'rgb(255, 224, 80)'],
[0.67, 'rgb(54, 64, 207)'],
[0.99, 'rgb(13, 163, 35)'],
[1, 'rgb(217, 186, 50']
]
}
},
title: {
text: 'Sales per employee per weekday'
},
xAxis: {
categories: ['Insignificant', 'Minimum', 'Significant', 'Material', 'Critical']
},
yAxis: {
categories: ['< 1%', '2-10%', '11-50%', '51-90%', '91-100%'],
title: null
},
colorAxis: {
min: 0,
minColor: 'transparent',
maxColor:'transparent'
//maxColor: Highcharts.getOptions().colors[0]
},
legend: {
align: 'right',
layout: 'vertical',
margin: 0,
verticalAlign: 'top',
y: 25,
symbolHeight: 320
},
tooltip: {
formatter: function () {
return '<b>' + this.series.xAxis.categories[this.point.x] + '</b> sold <br><b>' +
this.point.value + '</b> items on <br><b>' + this.series.yAxis.categories[this.point.y] + '</b>';
}
},
series: [{
name: 'Sales per employee',
borderWidth: 1,
data: [[0,0,0],[0,1],[0,2,8],[0,3,24],[0,4,67],[1,0,92],[1,1,58],[1,2,78],[1,3,117],[1,4,48],[2,0,35],[2,1,15],[2,2,123],[2,3,64],[2,4,52],[3,0,72],[3,1,132],[3,2,114],[3,3,19],[3,4,16],[4,0,38],[4,1,5],[4,2,8],[4,3,117],[4,4,115]],
dataLabels: {
enabled: true,
color: 'black',
style: {
textShadow: 'none'
}
}
}]
});
});