I am trying to get the series in the highcharts from ajax call. But its not working for some reason.I do not get the data populated in the chart. Please can anyone help me with this .
$(document).ready(function() {
$('#exercise').submit(function(e) {
var form = $(e.target);
e.preventDefault();
$.ajax({
type: form.attr('method'),
url: form.attr('action'),
dataType: 'json',
data: form.serialize(),
success : function(data){
alert("parse");
alert(data);
chart4(data);
},
error : function(){
alert("Exercise Error!");
}
});
});
});
This is my ajax call
unction chart4(data){
Highcharts.setOptions({
});
alert("HIT");
var chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
defaultSeriesType: 'column',
margin: [50, 150, 60, 80]
},
title: {
text: 'Exercise',
style: {
margin: '10px 100px 0 0' // center it
}
},
xAxis: {
type: 'datetime',
dateTimeLabelFormats: {
month: '%e. %b',
year: '%b'
},
},
yAxis: {
min: 0,
title: {
text: 'Minutes'
}
},
tooltip: {
headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
'<td style="padding:0"><b>{point.y:.1f} mm</b></td></tr>',
footerFormat: '</table>',
shared: true,
useHTML: true
},
plotOptions: {
column: {
pointPadding: 0.2,
borderWidth: 0
}
},
series:[data]
});
}
[{"duration":120,"date":1418803200000},{"duration":90,"date":1418889600000},{"duration":90,"date":1418976000000},{"duration":90,"date":1419235200000},{"duration":20,"date":1419580800000},{"duration":80,"date":1419667200000},{"duration":120,"date":1419753600000},{"duration":90,"date":1419840000000},{"duration":90,"date":141992600000}]
This is my JSON response
The problem is that you have custom names in the JSON. It should be x/y instaed of durable and date fields. Morever this line: series:[data] should be replaced with series:data becasue your json is array.
Related
Probably a stupid sounding question, but I want my Highcharts column tooltip to display when I mouseover anywhere above or on the column, but I don't want to use the tooltip shared:true attribute.
I'm doing this because my client has some columns that are tiny compared to their neighbors. It would be nice if the mouseover worked before I got close to the tiny columns.
Screenshot of what I'm trying to ask:
Here is a fiddle.
Highcharts.chart('container', {
chart: {
type: 'column'
},
title: {
text: 'Find Tauntauns'
},
subtitle: {
text: 'Some site on the web'
},
xAxis: {
categories: [
'Jan'
],
crosshair: true
},
yAxis: {
min: 0,
title: {
text: 'Tauntauns'
}
},
tooltip: {
headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
'<td style="padding:0"><b>{point.y:.1f} mm</b></td></tr>',
footerFormat: '</table>',
//shared: true,
useHTML: true
},
plotOptions: {
column: {
pointPadding: 0.2,
borderWidth: 0
}
},
series: [{
name: 'Tokyo',
data: [7]
}, {
name: 'Hoth',
data: [83.6]
}, {
name: 'London',
data: [48.9]
}, {
name: 'Berlin',
data: [5]
}]
});
Unfortunately, this option is not available from the API for the column series type because the pointTracker functionality works different than for the other series like a line or scatter.
My idea to achieve the wanted result is rendering dummy/transparent rectangles which will trigger the tooltip on mouseover effect.
Demo: https://jsfiddle.net/BlackLabel/3pr4baeq/
events: {
render() {
let chart = this;
chart.series.forEach(s => {
s.points.forEach(p => {
if (p.customRect) {
p.customRect.destroy();
}
p.customRect = chart.renderer.rect(p.barX + chart.plotLeft, chart.plotTop, p.pointWidth, p.shapeArgs.y)
.attr({
//fill: 'transparent',
fill: 'yellow'
})
.add();
p.customRect.element.onmouseover = function() {
chart.tooltip.refresh(p)
}
})
})
}
}
You can change the color of the rendered rectangles to the transparent which will hide them.
API: https://api.highcharts.com/class-reference/Highcharts.SVGRenderer#rect
API: https://api.highcharts.com/highcharts/chart.events.render
I had made one highchart in that tooltip is shows date and time in format but it is showing wrong date and time.
Please go through the code below.
HTML Code
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
Javascript Code
var maxval="94";
$(function () {
var chart;
$(document).ready(function() {
chart = new Highcharts.Chart({
credits: {
enabled: false
},
chart: {
type: 'column',
renderTo: 'container',
},
title: {
text: 'Weekly Traffic'
},
xAxis: {
type: 'datetime',
labels: {
format: '{value:%d-%b-%Y}',
rotation:-45,
},
},
yAxis: {
labels:{enabled: false},
title: {
text: ''
},
},
tooltip: {
formatter: function() {
return '<b>'+ this.series.name +'</b><br/>'+': '+Highcharts.dateFormat('%Y-%m-%d %H:%M', this.x) +'<br>'+ Highcharts.numberFormat((this.y /maxval ) * 100) + '%';
}
},
plotOptions: {
line: {
enableMouseTracking: false
},
series:{
pointStart: 1444242600000,
pointInterval: 86400000,
shadow:false,
dataLabels:{
enabled:true,
formatter:function()
{
var pcnt = (this.y /maxval ) * 100;
return Highcharts.numberFormat(pcnt) + '%';
}
}
}
},
series: [{
name: 'Firefox',
data: [10,56,32,12,64,13,38],
},{
name: 'Chrome',
data: [52,59,10,60,94,3,8],
},{
name: 'Edge',
data: [22,56,20,35,14,73,38],
},{
name: 'Opera',
data: [30,36,80,65,44,53,81],
},{
name: 'Safari',
data: [40,16,50,77,34,33,36],
}],
});
});
});
The working fiddle is given
here.
you need to set utc false in global option of highcharts.
Highcharts.setOptions({
global: {
useUTC: false
}
});
see Updated fiddle here
I am using highcharts to in my app and want to add tooltip with thousand separator like I did it in data labels. I used custom formatting for tooltip, so what should I change to achieve this
tooltip options in highcharts
tooltip: {
formatter: function () {
return (this.x + ':' + this.y);
},
shared: true,
useHTML: true
},
JS FIDDLE
use thousand separator in lang
$(function () {
Highcharts.setOptions({
lang: {
decimalPoint: '.',
thousandsSep: ','
}
});
and in tooltip- formatter use like
tooltip: {
pointFormat: '<b>{point.x} :</b>' + 'Count: <b>{point.y:,.0f}</b>',
shared: true,
useHTML: true
}
Updated fiddle with separator without decimal point
Just following Nishith Kant Chaturvedi's answer, and since there is no jsfiddle example available, here you can see how to implement that answer.
Highcharts.setOptions({
lang: {
decimalPoint: '.',
thousandsSep: ','
}
});
Highcharts.chart('container', {
chart: {
type: 'column'
},
title: {
text: ''
},
xAxis: {
categories: ['Salary']
},
yAxis: {
title: {
text: ''
},
stackLabels: {
enabled: true,
format: '{total:,.2f} $us'
},
labels: {
format: "{value:,.2f} $us",
}
},
legend: {
backgroundColor: (Highcharts.theme && Highcharts.theme.background2) || 'white',
borderColor: '#CCC',
borderWidth: 1,
},
tooltip: {
headerFormat: '<b>{point.x}</b><br/>',
pointFormat: '{series.name}: {point.y}<br/>Total: {point.stackTotal}'
},
plotOptions: {
column: {
stacking: 'normal',
dataLabels: {
format: '{point.y:,.2f} $us',
enabled: true,
color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white',
}
}
},
series: [{
type: 'column',
name: 'Tomas',
data: [60000]
}, {
type: 'column',
name: 'Amy',
data: [18000]
}, {
type: 'column',
name: 'Jenny',
data: [85000]
}]
});
http://jsfiddle.net/zrc5skLy/
Use Highcharts.numberFormat() in point.x or point.y
example:
tooltip: {
enabled: true,
split: true,
shared: true,
formatter: function () {
// The first returned item is the header, subsequent items are the points
return [Highcharts.dateFormat("%Y-%m-%d %H:%M:%S", this.x)].concat(
this.points
? this.points.map(function (point) {
return (
point.series.name +
": " +
// numberFormat(data, decimal)
Highcharts.numberFormat(point.y, 2)
);
})
: []
);
},
},
My requirement is to turn out other column bar graph in highcharts to dim color when we hover over one. I looked for this on community but found no specific answer. my code is as below:
<script src="http://code.highcharts.com/modules/exporting.js"></script>
<apex:includeScript value="{!URLFOR($Resource.ios, 'jquery-1.9.1.js')}"/>
<script>
var lowerIndex;
var upperIndex;
if({!maxBarVisible}==0)
{
lowerIndex = 0;
upperIndex = 0;
}
else
{
lowerIndex = {!maxBarVisible} - ({!maxBarVisible}-1);
upperIndex = {!maxBarVisible};
}
$(function () {
var chart;
$(document).ready(function() {
chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
type: 'column',
marginRight: 50,
marginBottom: 30
},
title: {
text:''
},
credits: {
enabled: false
},
legend: {
enabled: false
},
scrollbar:{
enabled:{!showSlider}
},
xAxis: {
min:lowerIndex,
max:upperIndex,
categories: [{!x_axisMonths}]
},
yAxis: {
min: 0,
title: {
text: 'MRR($)'
}
},
colors: [
'rgb(24, 150, 212)',
'rgb(116, 187, 59)',
],
tooltip: {
headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
'<td style="padding:0"><b>{point.y:.1f} mm</b></td></tr>',
footerFormat: '</table>',
shared: true,
useHTML: true,
tip: 'bottomLeft'
},
series: [{!y_axisData}]
});
});
});
</script>
Any suggestions?
I have this code for a query in a file called querytojson.php:
if(!$query = #pg_query("SELECT AVG(\"UploadSpeed\") AS \"UploadSpeed\",
AVG(\"DownloadSpeed\") AS \"DownloadSpeed\",
AVG(\"Latency\") AS \"Latency\",
AVG(\"Jitter\") AS \"Jitter\",
AVG(\"PacketLoss\") AS \"PacketLoss\" FROM \"ZipPerformance\" "))
die("<br>Errore nella query: " . pg_last_error($query));
while($row = pg_fetch_assoc($query)){
// aggiungo all'array
$risultati[] = $row;
}
// stampo a video i risultati formattati secondo la sintassi di JSON
echo json_encode($risultati);
the json data is in this format:
[{"UploadSpeed":"0.342153197182936","DownloadSpeed":"4.35602301750153","Latency":"110.290067528565","Jitter":"0.0333323723888251","PacketLoss":"0.164373075044556"}]
Now I'd want to create a graph with Highcharts library like this, the file is called index1.html:
$(document).ready(function() {
var options = {
chart: {
renderTo: 'container',
defaultSeriesType: 'column'
},
title: {
text: 'HOBBIT'
},
tooltip: {
},
labels: {
html: 'index.html'
},
xAxis: {
categories: []
},
yAxis: {
title: {
text: 'Velocità di connessione'
}
},
series: []
};
})
I'd want to pass json data directly to index.html.
I've done somthing similar to this. The way i did it was I created the chart in a sperate js file and just called the chart as a function passing in the JSON object as a variable. This is an example of one of my scripts in use on my site. In your case the labels and values are the same variable so the loop iteration is different, but the idea is still the same.
var chart;
function pieChart(id, values, labels, animate){
if (animate === undefined ){
animate = true;
}
var arrays = new Array();
for (i=0;i<values.length;i++) {
arrays[i] = [labels[i], values[i]];
}
chart = new Highcharts.Chart({
chart: {
renderTo: id,
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false
},
credits: {
enabled: false
},
title: {
text: 'Event Occurrence',
style: {
color: '#000000'
}
},
tooltip: {
formatter: function() {
return '<b>'+ this.point.name +'</b>: '+ this.y +' %';
}
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
color: '#000000',
connectorColor: '#000000',
formatter: function() {
return '<b>'+ this.point.name +'</b>: '+ this.y +' %';
}
}
},
series: {
animation: animate
}
},
series: [{
type: 'pie',
name: 'Probability',
data: arrays
}]
});
}