Highcharts - equal spacing between X-axis values having tickPositioner - highcharts

I am passing some values for the x-axis through the tickPositioner attribute. These values are not equally spaced from each other. My requirement is that I want these values to be equally spaced from one another even though they are not having equal difference from each other. Pls see my code below:
var chart = new Highcharts.Chart({
chart: {
renderTo: 'container'
},
credits: {
enabled: false
},
title: {
text: 'Duration vs Productive Hours'
},
xAxis: [{
allowDecimals: false,
title: {
text: 'Hours'
},
labels: {
rotation: -90,
align: 'right',
style: {
fontSize: '10px'
}
},
tickPositioner: function () {
var pos;
tickPositions = [];
tickStart = 100000;
for (pos = tickStart; pos <= 1000000000; pos *= 10) {
tickPositions.push(pos);
}
return tickPositions;
}
}],
exporting: {
width: 1024,
filename: 'Duration_vs_Productive_Hours',
buttons: {
exportButton: {
menuItems: [{
text: 'Export to PNG image',
onclick: function () {
this.exportChart();
}
}, {
text: 'Export to JPEG image',
onclick: function () {
this.exportChart({
type: 'image/jpeg'
});
}
}, {
text: 'Export to PDF file',
onclick: function () {
this.exportChart({
type: 'application/pdf'
});
}
},
null]
}
}
},
yAxis: [{
min: 0,
tickInterval: 10,
max: 60,
labels: {
formatter: function () {
return this.value;
},
style: {}
},
showEmpty: true,
alternateGridColor: '#f7f7f7',
gridLineColor: '#e7e7e7',
allowDecimals: false,
title: {
text: 'Duration (Months)',
style: {}
}
}],
tooltip: {
crosshairs: true,
formatter: function () {
if (this.series.type == 'line') {
return '' + this.x;
} else {
return '' + this.x + ': ' + this.y;
}
}
},
legend: {
layout: 'horizontal',
align: 'center',
verticalAlign: 'bottom',
backgroundColor: '#FFFFFF'
},
series: [{
name: 'Other Projects',
type: 'scatter',
data: [
[560000, 13],
[185250, 11],
[3625788, 23],
[1648510, 21],
[265000, 14],
[13000000, 43],
[28000000, 34],
[1567000, 19],
[1190000, 20],
[21000000, 31],
[7000000, 33],
[3805200, 30],
[17000000, 29],
[1503267, 21],
[11332332, 29],
[1485067, 20],
[5000000, 30],
[5400000, 22],
[13000000, 23],
[3810000, 26],
[810000, 18],
[27528218, 26],
[377319, 14],
[840000, 22],
[550000, 13],
[2643142, 26],
[412800, 13],
[2500000, 22],
[4510000, 19],
[523116, 15],
[17600000, 28],
[2500000, 21],
[21000000, 29],
[3500000, 17],
[620000, 15],
[163000000, 46],
[134000000, 41],
[45000000, 39],
[13677454, 31],
[167000000, 52],
[47000000, 33],
[49000000, 38],
[31000000, 38]
]
}, {
name: 'User Data',
type: 'line',
data: [
[4050000, 0],
[4050000, 60]
]
}] });

It sounds like you are trying to make the axis logarithmic. Try setting
xAxis:{
type:"logarithmic"
And remove the. Tickpositioner.
http://api.highcharts.com/highcharts#xAxis.type
If you do this, you get this: http://jsfiddle.net/TsaMA/ with the xAxis ticks equally spaced at 1M, 10M and 100M.
There are two xAxis settings which may: tickInterval and tickPixelInterval.
http://api.highcharts.com/highcharts#xAxis.tickInterval
If you set
tickInterval:1
You get 1M, 10M and 100M, which is the closest I can get to what you want.
tickPixelInterval is useful if you know the width of your chart. If your chart is 1000px wide you can set tickPixelInterval:250.

Related

Highcharts basic line chart - Y-axis label name

Highcharts Basic Line chart, Y-axis label how need to show ?
Here is my code
var seriesData = [["O", 42], ["N", 35], ["D", 20], ["J", 47], ["F", 45], ["M", 65]];
var seriesDataY = [['O', 50], ['14', 22], ["D", 30], ["J", 42], ["F", 44], ["M", 65]];
Highcharts.chart('linechart', {
title: {
text: ' '
},
yAxis: {
title: {
text: '(6 mth period)'
},
labels: {
enabled: true,
formatter: function () { return seriesDataY[0][this.value]; },
}
},
xAxis: {
tickInterval: 1,
labels: {
enabled: true,
formatter: function () { return seriesData[this.value][0]; },
}
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'middle'
},
plotOptions: {
series: {
label: {
connectorAllowed: false
},
pointStart: 0
}
},
series: [{
name: 'Voluntary',
data: seriesData
}, {
name: 'Involuntary',
data: seriesDataY
//data: [null, null, 7988, 12169, 15112, 22452]
}],
responsive: {
rules: [{
condition: {
maxWidth: 500
},
chartOptions: {
legend: {
layout: 'horizontal',
align: 'center',
verticalAlign: 'bottom'
}
}
}]
}
});
Images attached:
Y-axis label is missing:
0, 14 , 28,42, 56,70
As per the above value, i need to show the Y-axis. What is the option to show the Y-axis label name?
Notice that yAxis takes values (this.value) from the data y numbers. That's why it is different than for xAxis. Also, notice that the amount of the labels for yAxis is calculated differently, so it has to be set.
I think that something like this should fit your requirements:
let i = 0;
Highcharts.chart('container', {
title: {
text: ' '
},
...
labels: {
enabled: true,
formatter: function() {
i++;
return seriesDataY[i - 1][0];
},
}
...
Demo: https://jsfiddle.net/BlackLabel/zsou1Lye/

Step serie for navigator

Is it possible to use "step" in the navigator serie? As documented in the API it should be possible, but for some reason is not working for me.
I'm making a "Gantt" chart with Highstock, and I don't like the default navigator behavior for charts with multiple panes (by default the navigator "borrow" the first serie data). That's why I'm supplying the navigator series data
Fiddle
$(function () {
var data1 = [[1, 0, 1], [2, 0, 1], [2, null, null], [3, 0, 1], [5, 0, 1], [5, null, null], [6, 0, 1], [10, 0, 1]]
var data2 = [[1, null, null], [2, 0, 1], [4, 0, 1], [10, null, null]]
var dataNavigator = [[1, 1], [3, 2], [4, 1], [5, 0], [6, 1], [10, 1]]
$('#container').highcharts('StockChart', {
chart: {
type: 'arearange'
},
xAxis : {
ordinal: false
},
navigator : {
series : {
step: true,
data: dataNavigator
}
},
yAxis: [{
gridLineWidth: 0,
opposite: false,
height: '50%',
offset: 0,
lineWidth: 2,
labels: {enabled: false},
title : {
text: "y0"
}
}, {
gridLineWidth: 0,
opposite: false,
top: '50%',
height: '50%',
offset: 0,
lineWidth: 2,
labels: {enabled: false},
title : {
text: "y1"
}
}],
rangeSelector: {
selected: 2
},
title: {
text: 'Temperature variation by day'
},
tooltip: {
pointFormat: '<span style="color:{point.color}">\u25CF</span> {series.name}<br/>'
},
series: [{
name: 'Serie Name 1',
data: data1,
step: true,
yAxis: 0
}, {
name: 'Serie Name 2',
data: data2,
step: true,
yAxis: 1,
id: 'series1'
}]
});
});
As step is defined for series of type line you have to manually define it. Also, the values for step are 'left', 'right' and 'center'. For example:
navigator : {
series : {
type: 'line',
step: 'left',
data: dataNavigator
}
}
See this JSFiddle demonstration of how it looks.

Highcharts Bug. Why does heatmap on highcharts doesn't render correctly the rectangles if not all coordinates are provided?

As it is written in the Title i try to render a heatmap charts using highcharts.
I added a click event to change the color of one point when it is clicked.
But not all coordinates have data. As a result the points are not rendering correctly.
if i try to click the top left rectangle from the datalabel and below the wrong point is being colored.
Is this a bug?
Do i have to provide the whole set of coordinates in my data?
Here is a fiddle example of my problem
error example
(this doesn t apply to all scenarios where you don't the whole set of coordinates in your data. for example this works working example)
$(function () {
$('#container').highcharts({
chart: {
type: 'heatmap',
marginTop: 40,
marginBottom: 80
},
title: {
text: 'Sales per employee per weekday'
},
xAxis: {
categories: ['Alexander', 'Marie', 'Maximilian', 'Sophia', 'Lukas', 'Maria', 'Leon', 'Anna', 'Tim', 'Laura']
},
yAxis: {
categories: ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'],
title: null
},
colorAxis: {
min: 0,
minColor: '#FFFFFF',
maxColor: Highcharts.getOptions().colors[0]
},
legend: {
align: 'right',
layout: 'vertical',
margin: 0,
verticalAlign: 'top',
y: 25,
symbolHeight: 280
},
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>';
}
},
plotOptions: {
heatmap: {
cursor: 'pointer',
allowPointSelect: true,
events: {
click: function (event) {
if (event.point.shapeArgs && event.point.shapeArgs.fill == 'red') {
event.point.update({
color: null,
})
} else {
event.point.update({
color: 'red',
})
}
}
},
}
},
series: [{
name: 'Sales per employee',
borderWidth: 1,
data: [[0, 4, 67], [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: '#000000'
}
}]
});});

Hide inactive dates from datetime X-Axis

I have created fiddle to show my current graph:
http://jsfiddle.net/LLExL/4445/
The code is
$('#container').highcharts({
chart: {
backgroundColor: 'none',
spacingRight: 20,
zoomType: 'x'
},
credits: {
enabled: false
},
exporting: {
enabled: false
},
legend: {
borderWidth: 0,
enabled: true,
verticalAlign: 'top',
y: 25
},
plotOptions: {
series: {
animation: false,
marker: {
enabled: false,
states: {
hover: {
enabled: true,
radius: 5
}
}
}
},
},
title: {
text: 'Points'
},
tooltip: {
shared: true
},
xAxis: {
labels: {
format: '{value: %d/%m}'
},
type: 'datetime'
},
yAxis: {
title: {
text: null
},
showFirstLabel: true
},
series: [{
type: 'column',
name: 'Reached',
data: [
[1427328000000, 198],
[1427414400000, 127],
[1427673600000, 104],
[1427760000000, 107],
[1427846400000, 102],
[1427932800000, 1],
[1428278400000, 1],
[1428364800000, 55],
[1428451200000, 83],
[1428537600000, 77],
[1428624000000, 107],
[1428883200000, 99],
[1428969600000, 140],
[1429056000000, 134],
[1429142400000, 108],
[1429228800000, 104],
[1429488000000, 113],
[1429574400000, 115],
[1429660800000, 115],
[1429747200000, 97],
]
}, {
type: 'line',
name: 'Target',
color: 'red',
lineWidth: 2,
data: [
[1427328000000, 123],
[1427414400000, 123],
[1427673600000, 123],
[1427760000000, 123],
[1427846400000, 143],
[1427932800000, 0],
[1428278400000, 0],
[1428364800000, 143],
[1428451200000, 143],
[1428537600000, 143],
[1428624000000, 114],
[1428883200000, 143],
[1428969600000, 143],
[1429056000000, 143],
[1429142400000, 143],
[1429228800000, 114],
[1429488000000, 143],
[1429574400000, 143],
[1429660800000, 143],
[1429747200000, 143],
]
} ]
});
I want to remove inactive dates from the X-axis, ex. the dates BETWEEN 02/04 and 06/04 (but not these 2, since they have a value).
The only solution I have found working is to declare the dates myself via Categories and then going away from the datetime type axis. This is not the right solution for me tho, since the axis then won't fit correctly on smaller screens.
Is this anyhow possible to remove no-value-dates?
In Highcharts there is no ordinal option for axis, but it can be set if you are using Highstock. This options hides values from x axis that do not have points.
You could use Highstock to create Highcharts chart with axis that have ordinal x axis.
Load Highstock JS file instead of Highcharts:
<script src="http://code.highcharts.com/stock/highstock.js"></script>
In axis options set ordinal to true:
xAxis: {
ordinal: true,
jsFiddle: http://jsfiddle.net/LLExL/4451/

Highcharts Legend: Overlapping Chart on Small Screens

I've created an area chart that should be one-size-fits-all for various screen sizes. The issue comes in when viewing the chart on a phone. The legend overlaps the chart.
Here is the current config:
chart: {
backgroundColor: '#EFEFEF',
margin: [50,10,60,50]
},
credits: {
enabled: false
},
title: {
text: 'Engagement Index Score',
style: {
color: '#555555',
fontWeight: 'normal',
fontSize: 13
}
},
legend: {
borderWidth: 0,
symbolPadding: 10,
itemMarginBottom: 10,
itemDistance: 20,
itemStyle: {
color: '#555555',
cursor: 'default'
},
itemHoverStyle: {
color: '#555555'
}
},
yAxis: {
min: 0,
title: {
text: '% of U.S. Workers',
style: {
color: '#555555',
fontWeight: 'normal',
fontSize: 13
},
margin: 15
}
},
xAxis: {
min: 5,
max: 100
},
plotOptions: {
area: {
connectNulls: true
},
scatter: {
color: '#565656',
dashStyle: 'dash',
lineWidth: 2,
zIndex: 100,
events: {
legendItemClick: function () {
return false;
}
},
enableMouseTracking: false,
events: {
legendItemClick: function () {
return false;
}
}
}
},
series: [{
type: 'scatter',
name: ['You!'],
data: [[80,21]],
marker: {
symbol: 'url(img/star.png)'
}
}, {
type: 'scatter',
name: null,
data: [[80,0], [80,20]],
marker: {
enabled: false
},
showInLegend: false
}, {
type: 'area',
name: ['Disengaged'],
data: [[5,0],[10,4],[15,4],[20,3],[25, 3],[30, 7],[35, 7],[40, 9], [45, 9], [49.5, 14]],
color: '#EA2428',
marker: {
enabled: false
}
}, {
type: 'area',
name: ['Under Engaged'],
data: [[49.5, 14], [55,14], [60, 14], [65, 13], [70, 13], [74.5, 18]],
color: '#F79420',
marker: {
enabled: false
}
}, {
type: 'area',
name: ['Moderately Engaged'],
data: [[74.5, 18], [80, 18], [85, 8], [90, 8], [95, 8], [99.5, 20]],
color: '#18AFE6',
marker: {
enabled: false
}
}, {
type: 'area',
name: ['Fully Engaged'],
data: [[99.5, 20], [100, 20]],
color: '#5C2E8F',
marker: {
enabled: false
}
}]
Here is a fiddle with the current config:
http://jsfiddle.net/gabezeck/8Beea/
Adjust the width of the rendered code to see how it would look in mobile.
Does anyone have a good solution? Can the legend grow down instead of up?
Creating a static HTML version of the legend is not an option, nor is a solution that displays all data series in the chart. We need to hide one, as one of them has the sole function of drawing that dotted line that you see.
Thanks for the help!
Remove the Margin, and it will take dynamic Margins, and adjust the Legend's Position by itself, Check this updated Fiddle
Only what comes to my mind is catch resize event or chekcing width and then position legend.

Resources