Hide inactive dates from datetime X-Axis - highcharts

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/

Related

HighCharts Polar Labels in between of sectors of circle

I am working ReactHigh charts on polar graphs, I want my labels to come in between the sectors of the circle, they are coming on points but i dont want them to come there.
JSfiddle : https://jsfiddle.net/ra73mp0c/12/
Also I want a background color on each of the labels.
Graph as of now :
Desried Outcome :
Please help me .
Config of graph :
const config = {
chart: {
polar: true,
type: 'line',
width: 700,
backgroundColor: 'transparent',
plotBorderWidth: null,
margin: [0, 0, 0, 0],
spacingTop: 0,
spacingBottom: 0,
spacingLeft: 0,
spacingRight: 0
},
title: {
text: null
},
pane: {
size: '80%'
},
xAxis: {
categories: [
'Sales',
'Sales',
'Sales',
'Sales',
'Marketing',
'Development',
'Customer Support',
'Customer Support',
'Customer Support',
'Information Technology'
],
labels: {
style: {
fontSize: '13px',
fontFamily: 'Verdana, sans-serif'
}
},
tickmarkPlacement: 'on'
},
yAxis: {
gridLineInterpolation: 'polygon',
min: 0,
tickInterval: 1,
max: 6
},
tooltip: {
shared: true
},
legend: {
enabled: false
},
credits: { enabled: false },
series: [
{
name: 'Allocated Budget',
data: [1, 2, 3, 1, 4, 3, 1, 2, 4, 1],
pointPlacement: 'between'
},
{
name: 'Actual Spending',
data: [2, 4, 2, 1, 3, 4, 2, 2, 1, 4],
pointPlacement: 'between'
}
]
}
Thanks a lot, It would be helpful ig you can edit the fiddle Link https://jsfiddle.net/ra73mp0c/12/
Creating that kind of background for x axis labels is not supported in Highcharts.
As a workaround you can create a phantom series that mimics their look:
{
showInLegend: false,
type: 'polygon',
name: 'Labels background',
data: [
[1, 5],
[2, 5],
[2, 6],
[1, 6]
],
zIndex: -9999
}
labels.distance should be a negative value to make it work.
Demo: https://jsfiddle.net/BlackLabel/63nc1csv/

Center tooltip for highcharts area chart

Since highcharts does not have a column chart where I can set height and width of each column, I have to use an area chart to accomplish this. So basically I am using area charts to draw rectangles. The problem with area charts is that the tooltip is not centered but is always shown above one edge of the rectangle. Plus, I am drawing multiple rectangles on top of each other causing to show the tooltip of the wrong rectangle.
$('#container').highcharts({
chart: {
type: 'area',
zoomType: 'x'
},
xAxis: {
type: 'datetime'
},
yAxis: {
title: {
enabled: false
}
},
plotOptions: {
area: {
marker: {
enabled: false,
states: {
hover: {
enabled: false
}
}
},
fillOpacity: 1
}
},
tooltip: {
enabled: true
},
series: [{
name: 'Year',
color: '#0d233a',
data: [
[Date.UTC(2017, 0, 1), 0],
[Date.UTC(2017, 0, 1), 4],
[Date.UTC(2017, 11, 31), 4],
[Date.UTC(2017, 11, 31), 0]
],
zIndex: 4,
fillColor: '#0d233a',
lineColor: '#fff'
}, {
name: 'Half year',
id: 'Half',
color: '#2f7ed8',
data: [
[Date.UTC(2017, 0, 1), 0],
[Date.UTC(2017, 0, 1), 10],
[Date.UTC(2017, 5, 31), 10],
[Date.UTC(2017, 5, 31), 0]
],
zIndex: 3,
fillColor: '#2f7ed8',
lineColor: '#fff'
}, {
name: 'Half year',
linkedTo: 'Half',
data: [
[Date.UTC(2017, 6, 1), 0],
[Date.UTC(2017, 6, 1), 6],
[Date.UTC(2017, 11, 31), 6],
[Date.UTC(2017, 11, 31), 0]
],
zIndex: 3,
fillColor: '#2f7ed8',
lineColor: '#fff'
}]
});
For an example see this fiddle.
You can see that the tooltip is not centered and that a wrong tooltip is shown when hovering the dark blue rectangle. Does anyone know how to fix this?
If all the columns within one series are the same width, you can try to do this with a normal column chart, using tightly packed columns and multiple xAxis:
...
xAxis: [{
type: 'datetime',
}, {
type: 'datetime',
}],
plotOptions: {
column: {
grouping: false,
groupPadding: 0,
pointPadding: 0,
pointPlacement: 'between',
},
},
series: [{
name: 'Year',
data: [
[Date.UTC(2016, 0, 1), 3],
[Date.UTC(2017, 0, 1), 4],
],
zIndex: 4,
color: '#222'
}, {
name: 'Half year',
xAxis: 1,
data: [
[Date.UTC(2016, 0, 1), 8],
[Date.UTC(2016, 6, 1), 11],
[Date.UTC(2017, 0, 1), 10],
[Date.UTC(2017, 6, 1), 6],
],
zIndex: 3,
color: 'royalblue',
}],
http://jsfiddle.net/j1fnkt01/3/
Note: Zooming won't work properly until the x-axes can be properly linked (linkedTo), and this issue prevents us from doing that right now.
You can use tooltip.followPointer to get desired result
Whether the tooltip should follow the mouse as it moves across columns, pie slices and other point types with an extent. By default it behaves this way for scatter, bubble and pie series by override in the plotOptions for those series types.
For touch moves to behave the same way, followTouchMove must be true also.
Defaults to false.
Tooltip will be
tooltip: {
enabled: true,
followPointer: true
},
Fiddle demo
Update
Use plotOptions.area.trackByArea to show tooltip properly
So plotOptions will be
plotOptions: {
area: {
marker: {
enabled: false,
states: {
hover: {
enabled: false
}
}
},
fillOpacity: 1
},
series: {
trackByArea: true,
stickyTracking: false,
}
},
updated fiddle

Labels on the Y axis and grids

I'm trying to plot a chart using highcharts that looks like this. Could somebody please provide a simple example.
I've tried this:
$(function () {
$('#container').highcharts({
chart: {
type: 'scatter',
zoomType: 'xy'
},
title: {
text: 'Positioning Today'
},
subtitle: {
text: 'XXX XXX'
},
xAxis: {
title: {
enabled: true,
text: 'Compliance'
},
startOnTick: true,
endOnTick: true,
showLastLabel: true
},
yAxis: {
title: {
text: 'Category'
}
},
legend: {
layout: 'vertical',
align: 'left',
verticalAlign: 'top',
x: 100,
y: 70,
floating: true,
backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF',
borderWidth: 1
},
plotOptions: {
scatter: {
marker: {
radius: 5,
states: {
hover: {
enabled: true,
lineColor: 'rgb(100,100,100)'
}
}
},
states: {
hover: {
marker: {
enabled: false
}
}
},
tooltip: {
headerFormat: '<b>{series.name}</b><br>',
pointFormat: '{point.x} cm, {point.y} kg'
}
}
},
series: [{
name: 'Acme',
color: 'rgba(223, 83, 83, .5)',
data: [[3, 4], [3, 5], [4, 2], [3, 2]]
}, {
name: 'Competitive Landscape',
color: 'rgba(119, 152, 191, .5)',
data: [[4, 3], [5, 3], [2, 4], [2, 3]]
}]
});
});
http://jsfiddle.net/u6gbd6bx/3/
However, I'm struggling to get the grid and labels on the Y axis.
To get the categories on the Y axis, you need to specify the categories in the axis properties:
http://api.highcharts.com/highcharts#yAxis.categories
To get the grid, you can specify a width and a color for the gridlines for each axis:
http://api.highcharts.com/highcharts#yAxis.gridLineColor
http://api.highcharts.com/highcharts#yAxis.gridLineWidth
Note that grid lines on a chart are very often a distraction from the data - make them subtle if they are truly necessary.
To line the grid lines up with the categories, you can use the tickmarkPlacement property:
http://api.highcharts.com/highcharts#yAxis.tickmarkPlacement
And lastly, to get your data to line up correctly with your categories, you need to provide the category array index as the y value.
So, if your first category is "Support", you provide an x value of 0 for any data point in the Support category, etc.
Note also, that by default y axis categories run from bottom to top - if you want them to run from top to bottom, you can set reversed: true on your y axis.
Example:
http://jsfiddle.net/jlbriggs/6a5jdvyy/
Check the following example: http://jsfiddle.net/mushigh/qr815f25/2/
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<div id="container" style="min-width: 310px; height: 400px; max-width: 800px; margin: 0 auto"></div>
$(function() {
$('#container').highcharts({
chart: {
type: 'scatter',
zoomType: 'xy'
},
title: {
text: 'Positioning Today'
},
subtitle: {
text: 'XXX XXX'
},
xAxis: {
title: {
enabled: true,
text: 'Compliance'
},
gridLineWidth: 2,
startOnTick: true,
endOnTick: true,
showLastLabel: true
},
yAxis: {
title: {
text: 'Category'
},
categories: ['', 'Support', 'Compliance', 'Risk', 'Fast', 'Easy to Get Started'],
},
legend: {
layout: 'horizontal',
align: 'center',
verticalAlign: 'bottom',
floating: true,
backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF',
y: 15
},
plotOptions: {
scatter: {
marker: {
radius: 5,
states: {
hover: {
enabled: true,
lineColor: 'rgb(100,100,100)'
}
}
},
states: {
hover: {
marker: {
enabled: false
}
}
},
tooltip: {
headerFormat: '<b>{series.name}</b><br>',
pointFormat: '{point.x} cm, {point.y} kg'
}
}
},
series: [{
name: 'Acme',
color: 'rgba(223, 83, 83, .5)',
data: [
[3, 4],
[3, 5],
[4, 2],
[3, 2]
]
}, {
name: 'Competitive Landscape',
color: 'rgba(119, 152, 191, .5)',
data: [
[4, 3],
[5, 3],
[2, 4],
[2, 3]
]
}]
});
});

Negative Fill color in AreaSpline Graph

I want to fill area color above the spline in area spline chart.
I have tried to set negative fill color but no result.
Can anyone let me know how to fill area color above the spline rather then below?
Any help will be appreciated.
$(function () {
$('#container').highcharts({
chart: {
type: 'areaspline'
},
title: {
text: 'Average fruit consumption during one week'
},
legend: {
layout: 'vertical',
align: 'left',
verticalAlign: 'top',
x: 150,
y: 100,
floating: true,
borderWidth: 1,
backgroundColor: '#FFFFFF'
},
xAxis: {
categories: [
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday',
'Sunday'
],
plotBands: [{ // visualize the weekend
from: 4.5,
to: 6.5,
color: 'rgba(68, 170, 213, .2)',
}]
},
yAxis: {
title: {
text: 'Fruit units'
}
},
tooltip: {
shared: true,
valueSuffix: ' units'
},
credits: {
enabled: false
},
plotOptions: {
areaspline: {
fillOpacity: 0.5
}
},
series: [{
name: 'John',
data: [3, 4, 3, 5, 4, 10, 12],
negativeFillColor: '#000000'
}, {
name: 'Jane',
data: [1, 3, 4, 3, 3, 5, 4],
negativeFillColor: '#000000'
}]
});
})
;
Thanks,
M
Well, threshold should work. Just you need to set
endOnTick: false
maxPadding: 0
threshold: max_value_in_data
See: http://jsfiddle.net/3bQne/1076/
Code:
var data = [3, 4, 3, 5, 4, 10, 12];
Array.prototype.max = function() {
return Math.max.apply(null, this);
}
$('#container').highcharts({
chart: {
type: 'areaspline'
},
yAxis: {
endOnTick: false,
maxPadding: 0
},
plotOptions: {
areaspline: {
threshold: data.max(),
}
},
series: [{
data: data,
negativeFillColor: 'rgba(255, 0, 0, 0.5)'
}]
});

Highcharts - equal spacing between X-axis values having tickPositioner

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.

Resources