How to set Y axis with equal interval in Highcharts? - highcharts

I know this question has been asked before on StackOverflow. However, I have slightly different ask so please read it before you mark it as Duplicate.
I am trying to set y-axis to 0,1,2,4,8,16,32,64,128.... also, the spacing between those tickPoints should be equal. I have tried setting various interval but it didn't help below is my code.
$("#ClickSmu_man").click(function () {
var theModal = $("#ModalSmu_man").modal({
show: false
});
Highcharts.chart('container_man', {
chart: {
type: 'column'
},
title: {
text: 'In Progress weekly pending Avg. Age per DE Manager Count'
},
xAxis: {
categories: [
<?php foreach($smu_top_manager as $topma){ ?>
'<?php echo $topma['name']; ?>',
<?php } ?>
]
},
yAxis: {
min: 0,
tickInterval: 1,
title: {
text: 'Platform'
},
stackLabels: {
enabled: false,
style: {
fontWeight: 'bold',
color: (Highcharts.theme && Highcharts.theme.textColor) || 'gray'
}
}
},
tooltip: {
headerFormat: '<b>{point.x}</b><br/>',
pointFormat: '{series.name}: {point.y}<br/>'
},
plotOptions: {
column: {
stacking: 'normal',
dataLabels: {
enabled: false,
color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white'
}
}
},
series: [
{
name: 'Age',
data: [<?php echo implode(',', $age_manager); ?>],
},
{
name: 'asr9k_px',
data: [<?php echo implode(',', $asr9k_px_manager); ?>],
},
{
name: 'asr9k_x64',
data: [<?php echo implode(',', $asr9k_x64_manager); ?>],
},
{
name: 'crs_px',
data: [<?php echo implode(',', $crs_px_manager); ?>],
},
{
name: 'ncs5500',
data: [<?php echo implode(',', $ncs5500_manager); ?>],
},
{
name: 'ncs5500_sysadmin',
data: [<?php echo implode(',', $s5500_sysadmin_manager); ?>],
},
{
name: 'ncs5k',
data: [<?php echo implode(',', $ncs5k_manager); ?>],
},
{
name: 'ncs6k',
data: [<?php echo implode(',', $ncs6k_manager); ?>],
},
{
name: 'xr12000',
data: [<?php echo implode(',', $xr12000_manager); ?>],
},
{
name: 'xrv9k',
data: [<?php echo implode(',', $xrv9k_manager); ?>],
},
{
name: 'xrv9k_sysadmin',
data: [<?php echo implode(',', $xrv9k_sysadmin_manager); ?>],
}
]
});
});

Use yAxis.tickPositions to define ticks in your chart.
xAxis: {
tickPositions: [0,2,4,8,16,32,64],
},
example: http://jsfiddle.net/f94hdLqt/
If you want to set ticks dynamically, you can use tickPositioner.

Related

use abbreviated state names

I have a map of the US and its 600 x 400. How do I force it to use the Abbreviated State names which I see in the examples but am unable to reproduce in my own code.
I'm using the below code with some sample data to show the format of the code I'm passing. I'm having to parse the data out of a larger json response.
var data = [{"code":"AK","value":225}, {...} ];
This is the map:
$('#ha-worst-map-1').highcharts('Map', {
title : {
text : result.data[1][2] + ': ' + result.data[1][4]
},
subtitle : {
text : 'stuff and things'
},
mapNavigation: {
enabled: true,
buttonOptions: {
verticalAlign: 'top'
}
},
colorAxis: {
min: 0
},
credits: {
text: '',
href: ''
},
series : [{
data : data,
mapData: Highcharts.maps['countries/us/us-all'],
joinBy: ['postal-code', 'code'],
name: 'metric',
states: {
hover: {
color: '#BADA55'
}
},
dataLabels: {
enabled: true,
format: '{point.name}'
},
tooltip: {
valueSuffix: ''
}
}, {
name: 'Separators',
type: 'mapline',
data: Highcharts.geojson(Highcharts.maps['countries/us/us-all'], 'mapline'),
color: 'silver',
showInLegend: true,
enableMouseTracking: true
}]
});

Highchart data series on wrong y-axis

I am struggling to solve this issue where I have a Highcharts graph with temperature and humidity.
It has two y-axis, one for temperature and one for humidity.
I have specified that humidity should go to the y-axis id 1, but it does not.
It puts the line in, but it is 'plotted' to the temperature axis values.
See this jsfiddle
$(function () {
$('#container').highcharts({
chart: {
zoomType: 'x',
type: 'spline'
},
title: {
text: 'Temperatures - Vdrivhus'
},
subtitle: {
text: 'last hour'
},
xAxis: {
type: 'datetime',
// dateTimeLabelFormats.setOption("minute", "%H:%M");
dateTimeLabelFormats: { // don't display the dummy year
day: '%e %b',
week: '%e %b %y',
month: '%b %y',
year: '%Y'
}
},
yAxis: [{ // Primary yAxis
labels: {
format: '{value}°C',
style: {
color: '#89A54E'
}
},
title: {
text: 'Temperature',
style: {
color: '#89A54E'
}
}
}, { // Secondary yAxis
title: {
text: 'Humidity',
style: {
color: '#4572A7'
}
},
labels: {
format: '{value} %',
style: {
color: '#4572A7'
}
},
min: 50,
max: 100,
opposite: true
}],
tooltip: {
shared: true
},
series: [{
name: 'Temperature',
// Define the data points.
marker: {
enabled: false
},
yaxis: 0,
tooltip: {
valueSuffix: '°C'
},
data: [
[1387521917000, 5],
[1387522299000, 5.2],
[1387522531000, 5.1],
[1387522809000, 5.1],
[1387523536000, 4.8],
[1387523745000, 4.7],
[1387524008000, 4.7],
[1387524303000, 4.8],
[1387524667000, 4.9],
[1387524904000, 4.9],
[1387525245000, 5]
]
}, {
name: 'Humidity',
marker: {
enabled: false
},
yaxis: 1,
tooltip: {
valueSuffix: '%'
},
data: [
[1387521917000, 74.4],
[1387522299000, 73.6],
[1387522531000, 74],
[1387522809000, 74],
[1387523536000, 82.5],
[1387523745000, 82.4],
[1387524008000, 78.7],
[1387524303000, 75.9],
[1387524667000, 74.6],
[1387524904000, 74.5],
[1387525245000, 74.2]
]
}, ]
});
});
//]]>
Can anyone help me solve this?
It is very simple, yaxis option should be yAxis since JS is case-sensitive.
I think that's it: jsFiddle

How to make stacked column graph to show total data value on top

I want to show total of all stacks of column to display on top of each column below is the link how i want to get the chart.
http://jsfiddle.net/gh/get/jquery/1.9.1/highslide-software/highcharts.com/tree/master/samples/highcharts/demo/column-stacked/
Below is the code i am using.
$(function () {
$('#container').highcharts({
chart: {
type: 'column'
},
title: {
text: 'Total fruit consumtion, grouped by gender'
},
xAxis: {
categories: ['Apples', 'Oranges', 'Pears', 'Grapes', 'Bananas']
},
yAxis: {
allowDecimals: false,
min: 0,
title: {
text: 'Number of fruits'
}
},
tooltip: {
formatter: function() {
return '<b>'+ this.x +'</b><br/>'+
this.series.name +': '+ this.y +'<br/>'+
'Total: '+ this.point.stackTotal;
}
},
plotOptions: {
column: {
stacking: 'normal',
dataLabels: {
enabled: true,
color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white'
}
}
},
series: [{
name: 'John',
data: [5, 3, 4, 7, 2],
stack: 'male'
}, {
name: 'Joe',
data: [3, 4, 4, 2, 5],
stack: 'male'
}, {
name: 'Jane',
data: [2, 5, 6, 2, 1],
stack: 'female'
}, {
name: 'Janet',
data: [3, 0, 4, 4, 3],
stack: 'female'
}]
});
});
You have to use stackLabels. You missed it in your code. You can find it in yAxis -> stackLabels
stackLabels: {
enabled: true,
style: {
fontWeight: 'bold',
color:'gray'
}
}
Here is how:
yAxis: {
allowDecimals: false,
min: 0,
title: {
text: 'Number of fruits'
},
stackLabels: {
enabled: true,
style: {
fontWeight: 'bold',
color:'gray'
}
}
},

Highcharts add points but not to all categories

I would like to add points to my highcharts without expecting to fulfill all the categories.
is it possible? any work around?
I've done the same when X data is based on time, but could it be done with other kind of data?
For example one serie could be just Apples and Oranges, but not the other categories. See code:
$(function () {
$('#container').highcharts({
chart: {
type: 'column'
},
title: {
text: 'Stacked column chart'
},
xAxis: {
categories: ['Apples', 'Oranges', 'Pears', 'Grapes', 'Bananas']
},
yAxis: {
min: 0,
title: {
text: 'Total fruit consumption'
},
stackLabels: {
enabled: true,
style: {
fontWeight: 'bold',
color: (Highcharts.theme && Highcharts.theme.textColor) || 'gray'
}
}
},
legend: {
align: 'right',
x: -70,
verticalAlign: 'top',
y: 20,
floating: true,
backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColorSolid) || 'white',
borderColor: '#CCC',
borderWidth: 1,
shadow: false
},
tooltip: {
formatter: function() {
return '<b>'+ this.x +'</b><br/>'+
this.series.name +': '+ this.y +'<br/>'+
'Total: '+ this.point.stackTotal;
}
},
plotOptions: {
column: {
stacking: 'normal',
dataLabels: {
enabled: true,
color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white'
}
}
},
series: [{
name: 'John',
data: [[Apples,5], [Oranges, 6]]
}, {
name: 'Jane',
data: [[Grapes,2]]
}, {
name: 'Joe',
data: [[Grapes,2], [Bananas, 4]]
}]
});
});
You can use the indexes into your categories: http://jsfiddle.net/BwyAj/
var categories = ['Apples', 'Oranges', 'Pears', 'Grapes', 'Bananas']
...
series: [{
name: 'John',
data: [[categories.indexOf('Apples'),5], [categories.indexOf('Oranges'), 6]]
}, {
name: 'Jane',
data: [[categories.indexOf('Grapes'),2]]
}, {
name: 'Joe',
data: [[categories.indexOf('Grapes'),2], [categories.indexOf('Bananas'), 4]]
}]

Tooltip in Scatter

I having problem adding unix timestamp as extra point in tooltip.
My code is showing no graph. Help!
Here is part of my code:
My data array: $data[] = "[x:$valDE,y:$valDN,z:$datetime]";
And my javascript:
var <?php echo $chart ?> = new Highcharts.Chart({
chart: {
type: 'scatter',
renderTo: '<?php echo $container ?>',
zoomType: '',
marginLeft: 50,
borderWidth: 1
},
title: {
text: '<?php echo "$gps $location"; ?>',
style: {
fontSize: '<?php echo $sizeTitle ?>'
}
},
subtitle: {
text: 'Data is average pr. day - viewing <?php if($range == "All"){echo "ALL DATA";}else if($range == "1 YEAR"){echo "LAST YEAR";}else{ echo "last ".$range;} ?>',
style: {
fontSize: '<?php echo $sizeSubTitle ?>'
}
},
xAxis: {
title: {
enabled: true,
text: 'EW',
align: 'high'
},
min:-<?php echo $maxAxis ?>,
max:<?php echo $maxAxis ?>,
offset: <?php echo $offSetX ?>,
tickInterval: <?php echo $tickInterval ?>
},
yAxis: {
title: {
text: 'NS',
align: 'high'
},
min:-<?php echo $maxAxis ?>,
max:<?php echo $maxAxis ?>,
offset:<?php echo $offSetY ?>,
lineWidth:1,
tickInterval: <?php echo $tickInterval ?>
},
legend: {
layout: 'vertical',
align: 'left',
verticalAlign: 'top',
x: <?php echo $legendX ?>,
y: <?php echo $legendY ?>,
floating: true,
backgroundColor: '#FFFFFF',
borderWidth: 1,
itemStyle: {
fontSize: '<?php echo $legendSize ?>'
}
},
plotOptions: {
scatter: {
marker: {
radius: <?php echo $lineWidth ?>,
states: {
hover: {
enabled: false,
lineColor: 'rgb(100,100,100)'
}
},
symbol: "circle"
},
states: {
hover: {
marker: {
enabled: false
}
}
},
tooltip: {
headerFormat: '<b>{series.name}</b><br>',
pointFormat: 'EW: {this.x} mm<br>NS: {this.y} mm<br>Date: {this.point.z}'
}
}
},
series: [{
color: '#990000',
name: '<?php echo $legFive ?>',
data:[<?php echo join(${$da}, ',') ?>]
},{
color: '#ff0000',
name: '<?php echo $legFour ?>',
data:[<?php echo join(${$da4}, ',') ?>]
},{
color: '#ffcc33',
name: '<?php echo $legThree ?>',
data:[<?php echo join(${$da3}, ',') ?>]
},{
color: '#66ff66',
name: '<?php echo $legTwo ?>',
data:[<?php echo join(${$da2}, ',') ?>]
},{
color: '#3300ff',
name: 'Last',
data:[<?php echo join(${$da1}, ',') ?>]
}]
});
<?php }//for ?>
});
See this example for how to go about it:
http://jsfiddle.net/jlbriggs/fbMQf/
You need to supply the data as an object with key->value pairs, and call accordingly in your formatter.
see fiddle for code
UNIX timestamps should be multiply by 1000, and be sorted by x ascending. Could you attach your example series data: "echo join(${$da1}, ',')" ?

Resources