highcharts heatmap with getjson - highcharts

I need help with this heatmap chart
$(document).ready(function(){
var grf_heatmap = {
chart: {
type: 'heatmap',
renderTo:'map',
height: 600,
marginTop: 40,
marginBottom: 40
},
title: {
text: 'heatmap'
},
xAxis: {
categories: []
},
yAxis: {
categories: []
},
colorAxis: {
min: 0,
minColor: '#FFFFFF',
maxColor: '#990041'
},
legend: {
align: 'right',
layout: 'vertical',
margin: 0,
verticalAlign: 'top',
y: 25,
symbolHeight: 320
},
series: [{
turboThreshold:0,
borderWidth: 1,
point: {
events: {
click: function(e) {
//this.slice();
//console.log(e);
location.href = e.point.options.url;
e.preventDefault();
}
}
},
data:[],
dataLabels: {
enabled: true,
color: 'black',
style: {
textShadow: 'none',
HcTextStroke: null
}
}
}]}
$.getJSON("data.php", function(json) {
grf_heatmap.yAxis.categories = json[0]['data'];
grf_heatmap.xAxis.categories = json[2]['data'];
grf_heatmap.series[0].data = json[1]['data'];
chart = new Highcharts.Chart(grf_heatmap);
});
})
data.php retuns a json like this
[{"name":"EjeY",
"data":["NameA"]},
{"name":"datos",
"data":["{x:0,y:0,value:1,url:'test.php'}",
"{x:1,y:0,value:3,url:'test.php'}"]},
{"name":"EjeX",
"data":["1","2"]}
]
but the result is a blank chart.
what am i doing wrong?,
if i use only the json for xAxis and yAxis categories and complete the chart with this data
data[{x:0,y:0,value:1,url:'test.php'},{x:1,y:0,value:3,url:'test.php'}],
it works
Tanks,

Related

How to label xAxis with series data using Highcharts?

I'm newbie to highchart and I've got a demo for polar chart using highcharts
Highcharts.chart('container', {
chart: {
polar: true,
type: 'area'
},
accessibility: {
description: 'ASDFR'
},
title: {
text: '',
x: -120
},
pane: {
size: '100%',
startAngle:-42
},
xAxis: {
categories: ['ATT', 'TEC', 'TAC', 'DEF', 'CRE'],
tickmarkPlacement: 'on',
lineWidth: 0,
labels:{
formatter: function(){
return this.value + '???'
}
}
},
yAxis: {
gridLineInterpolation: 'polygon',
},
tooltip: {
shared: true,
pointFormat: '<span style="color:{series.color}">{series.name} <b>{point.y:,.0f}</b></span>'
},
legend: {
align: 'right',
verticalAlign: 'middle',
layout: 'vertical'
},
series: [{
name: '',
data: [73, 80, 80, 54, 92],
}],
responsive: {
rules: [{
condition: {
maxWidth: 500
},
chartOptions: {
legend: {
align: 'center',
verticalAlign: 'bottom',
layout: 'horizontal'
},
pane: {
size: '70%'
}
}
}]
}
});
How can I show the value of the series right in the xAxis label e.g ATT 73, TEC 80, TAC 80...
You can get the associated value through series data. Example:
xAxis: {
...,
labels: {
formatter: function() {
return this.value + ' ' + this.chart.series[0].yData[this.pos];
}
}
}
Live demo: https://jsfiddle.net/BlackLabel/pyohzk8c/
API Reference: https://api.highcharts.com/highcharts/xAxis.labels.formatter

dashStyle property is not working in angular 4

I'm making a chart which has two x-axis and two y-axis on it.
It's a line chart with smooth curve. It should have lines from two series as dash or longdash but when I use dashStyle it throws error.
I have seen many examples where it's working in jsFidler or Plunker.
Below is my code. I'm using Angular 4 with typescript.enter image description here
var ctx = document.getElementById("PumpCurveEvolutionChart") as HTMLElement;
var chart = Highcharts.chart(ctx, {
chart:{
height: 350,
width: 700,
marginTop: 30,
},
title: { text: 'Flow (l/S)', verticalAlign: 'bottom'}
,
xAxis: [{
categories: this.getPumpCurveEvolution.OEMFlow,
},
{
categories: this.getPumpCurveEvolution.CurrentFlow,
opposite: true,
labels: { enabled: false },
minorTickLength: 0,
tickLength: 0
}],
yAxis:[{
min: 0,
max: 100,
labels: { enabled: true},
title: { text: 'Head (m)'},
},{
min: 0,
max: 110,
opposite: true,
labels: { enabled: true},
title: { text: 'Efficiency (%)'}
}],
plotOptions: {
series: {marker: { enabled: false}, lineWidth: 2},
//line: { dashStyle: 'dash'}
},
legend: {enabled: false,
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -30,
y: 100,
borderWidth: 0
},
series: [{
xAxis:0,
yAxis:0,
data: this.getPumpCurveEvolution.OEMHead,
},
{
xAxis:0,
yAxis:1,
data: this.getPumpCurveEvolution.OEMHydrEfficiency,
},
{
xAxis:1,
yAxis:0,
data: this.getPumpCurveEvolution.CurrentHead,
},
{
xAxis:1,
yAxis:1,
data: this.getPumpCurveEvolution.CurrentHydrHead,
}]
});
You can use dashStyle by extending HighCharts.IndividualSeriesOptions:
export interface IHighChartCustomSeries extends Highcharts.IndividualSeriesOptions {
dashStyle?: string
}

Highcharts:Add image to legend

I have this chart. I want to add some check icons in the rectangle from the legend, when it is selected.
How can I do this?
var chart = new Highcharts.Chart({
chart: {
renderTo: this,
type: 'pie'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: false
},
showInLegend: true
}
},
series: [{
data: jsonChart
}],
legend: {
symbolWidth: 40,
align: 'right',
layout: 'vertical',
verticalAlign: 'top',
x: 40,
y:0,
width: 150,
},
});
});The chart
You can use Renderer to render an image in the chart.
function drawTicks() {
const {
translateX: tx,
translateY: ty
} = this.legend.group;
this.series[0].points.forEach(p => {
let img = p.img;
if (!img) {
p.img = img = this.renderer.image('http://icons.iconarchive.com/icons/visualpharm/must-have/256/Check-icon.png', -9999, 0, 15, 15).attr({
zIndex: 10
}).add();
}
const bbox = p.legendSymbol.getBBox();
const x = p.legendGroup.translateX + tx;
const y = p.legendGroup.translateY + ty;
img.attr({
x: x,
y: y
});
});
}
on load/redraw draw ticks
chart: {
events: {
load: drawTicks,
redraw: drawTicks
}
},
on legendItemClick change the img's visibility
series: [{
type: 'pie',
name: 'Browser share',
point: {
events: {
legendItemClick: function() {
this.img.attr({
visibility: !this.visible ? 'visibile' : 'hidden'
});
}
}
},
example: http://jsfiddle.net/3348yjrq/

Highcharts JSON load issue

I have a sample Highchart that I'm try to load JSON data without any luck. I see the data return in firebug but the chart bar and line doesn't get drawn. You can see my chart here jsfiddle.net. I know I'm missing something, but I can't seem to put my fingers on it. Any help would greatly appreciated, thank you in advance.
This is my code:
$(function() {
var options = {
chart: {
renderTo: 'container',
zoomType: 'xy'
},
title: {
text: 'JSON Chart'
},
subtitle: {
text: '2012 vs 2011'
},
credits: false,
xAxis: [{
categories:['1','2','3','4','5','6','7','8','9','10']
}],
yAxis: [{ // Primary yAxis
min: 0,
max: 15000,
tickInterval: 1000,
labels: {
formatter: function() {
return Highcharts.numberFormat(this.value, 0);
},
style: {
color: '#89A54E'
}
},
title: {
text: '2012',
style: {
color: '#89A54E'
}
}
}, { // Secondary yAxis
min: 0,
max: 15000,
tickInterval: 1000,
labels: {
formatter: function() {
return Highcharts.numberFormat(this.value, 0);
},
style: {
color: '#4572A7'
}
},
title: {
text: '2011',
style: {
color: '#4572A7'
}
},
opposite: true
}],
tooltip: {
formatter: function() {
return Highcharts.numberFormat(this.y, 0);
}
},
legend: {
layout: 'vertical',
align: 'left',
x: 80,
verticalAlign: 'top',
y: 40,
floating: true,
backgroundColor: '#FFFFFF'
},
series: [{
name: '2011',
type: 'column',
yAxis: 1,
data: []
}, {
name: '2012',
type: 'spline',
data: []
}]
};
});
$.getJSON('data.cfm', function(json) {
options.series = json;
var chart = new Highcharts.Chart(options);
})
Here's what data.cfm return:
[[9233,14837,11442,8080,10302,5373,2450,9612,18656,8999],[7963,7845,8646,5130,2570,8936,17487,9141,6728,6046]];
Shoulnt it be?
options.series[0].data=json[0];
options.series[1].data=json[1];
This might be of use: http://livecoding.gabrielflor.it/3351656

highcharts graph no show yaxis values

The graph does not show the y-axis values​​. Could anyone help me with this? thanks.
If I put the value of prueba in the series data, everything worsk correctly
the prueba array and the dinero array are displayed correctly.
Thanks,
$.getJSON('http://localhost/jquery/grafica4.php', function(data) {
var dinero = [];
var categories = [];
var prueba = [79, 71, 66,44,42,38,32,10];
$.each(data, function(index, value) {
categories.push(data[index].producto_id);
dinero.push(data[index].cantidad);
alert("hola");
});
alert(dinero);
alert(prueba);
chart4 = new Highcharts.Chart({
chart: {
renderTo: 'container3',
type: 'column'
},
title: {
text: 'Productos más vendidos'
},
xAxis: {
categories: categories
},
yAxis: {
min: 0,
title:
text: 'Cantidad'
},
labels: {
formatter: function() {
return this.value; // clean, unformatted
}
}
},
legend: {
layout: 'vertical',
backgroundColor: '#FFFFFF',
align: 'left',
verticalAlign: 'top',
x: 100,
y: 70,
floating: true,
shadow: true
},
tooltip: {
formatter: function() {
return ''+
'<b>'+'Producto:'+this.x +'</b>'+'<br/>'+ this.y+ ' unidades';
}
},
plotOptions: {
column: {
pointPadding: 0.3,
borderWidth: 0
}
},
series: [{
name: 'Cantidad',
data: dinero
}],
exporting: {
filename: 'Facturacion-de-empleados'
}
});
});

Resources