I want to create a time line chart with year,if we select year from dropdown then the has to display that particular year chart.once check above image
Here is a example with arrows, which lets you select time interval:
const options = {
chart: {
type: 'column',
panning: true,
events: {
load: function () {
const chart = this
const moveLeft = () => {
let {min, max, dataMin} = chart.xAxis[0].getExtremes()
if (min - 3 >= dataMin) {
min -= 3
max -= 3
}
chart.xAxis[0].setExtremes(min, max)
}
const moveRight = () => {
let {min, max, dataMax} = chart.xAxis[0].getExtremes()
if (max + 3 <= dataMax) {
min += 3
max += 3
}
chart.xAxis[0].setExtremes(min, max)
}
const leftArrowUrl = 'https://egiveusa.com/appdev/images/icons/icomoon/svg/arrow-left3.svg'
const rightArrowUrl = 'http://egiveusa.com/appdev/images/icons/icomoon/svg/arrow-right3.svg'
const leftArrow = chart.renderer.image(leftArrowUrl, 0, 150, 30, 30).attr({ zIndex: 10 })
const rightArrow = chart.renderer.image(rightArrowUrl, 600, 150, 30, 30).attr({ zIndex: 10 })
leftArrow.on('click', moveLeft).add()
rightArrow.on('click', moveRight).add()
}
}
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'
],
max: 2
},
yAxis: {
title: {
text: '·'
}
},
series: [...Array(5)].map(() => {
return {
data: [...Array(12)].map(() => Math.round(Math.random() * 300))
};
})
}
const chart = Highcharts.chart('container', options)
https://jsfiddle.net/j59o5e6k/
Methods which you want to use are setExtremes and getExtremes:
http://api.highcharts.com/highcharts/Axis.getExtremes
http://api.highcharts.com/highcharts/Axis.setExtremes
Related
I recently upgraded highcharts v2.3.3 to 4.0.3, and find my xAxis cannot display correctly after this.
I have a 3 year monthly chart like this: JSFiddle example
After zoom to a detail level, and then reset zoom the xAxis label in the selected area disappear:
Is there any method to fix the problem? thanks a lot!
I found that the maxStaggerLines caused the problem, but I don't want it separate into 2 lines. How can I solve this?
I also find that if I set maxStaggerLines: 1 in another chart, some label will disappear. Can I turn the auto stagger line/auto detect label overlap function off?
My chart code:
$(function () {
var startYear = '2012';
var dataSet = [];
for (var i = 0; i < 36; i++)
dataSet.push(15);
var series = [];
series.push({data: dataSet});
var xCategoriesMonth = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
var xCategoriesYear = [];
for (var i = parseInt(startYear) ; i < (parseInt(startYear) + 3) ; i++)
for (var x = 0; x < 12 ; x++)
xCategoriesYear.push(i);
$('#container').highcharts({
chart: {
zoomType: 'x',
type: 'line',
height: 380,
},
xAxis: {
type: "category",
labels: {
formatter: function () {
var ex = this.axis.getExtremes();
if ((ex.max - ex.min) > 12) {
if (this.value % 3 == 0) {
if (xCategoriesMonth[this.value] == "Jan")
return xCategoriesMonth[this.value] + '<br>' + xCategoriesYear[this.value];
else
return xCategoriesMonth[this.value];
}
}
else {
if (this.value % 3 == 0)
return xCategoriesMonth[this.value] + '<br>' + xCategoriesYear[this.value];
else
return xCategoriesMonth[this.value];
}
},
maxStaggerLines: 1,
},
tickPixelInterval: $('#container').width() / 36,
title: {
text: 'testing',
offset: 50
},
showLastLabel: false,
startOnTick: false,
endOnTick: true,
minPadding: 0,
maxPadding: 0,
},
yAxis: {
lineWidth: 1,
},
plotOptions: {
series: {
allowPointSelect: true,
lineWidth: 1,
connectNulls: true,
},
},
series: series,
});
});
I had similar issue. For me solution was to add tickInterval: 1 option.
Look to this ticket
https://github.com/highslide-software/highcharts.com/issues/4399
Friends ,
i want to show contineous line between Two points of series even
if any y axis value missing from serries .
As i have attached code for upper series "tokio" march month y axis
value is missing .I want line should be contineous .
Below is my code .
Can any one have idea about this,please help.
$(function () {
var seriesdata = [];
var options = {
chart: {
type: 'spline'
},
title: {
text: 'Monthly Average Temperature',
x: -20 //center
},
subtitle: {
text: 'Source: WorldClimate.com',
x: -20
},
xAxis: {
categories: [],
min: 0
},
yAxis: {
title: {
text: 'Temperature (°C)'
}
},
tooltip: {
valueSuffix: '°C'
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'middle',
borderWidth: 0
},
series: [{ name: 'tokio', data: [['Jan', 7.0], ['Feb', 6.9], ['Mar', null],['Apr', 18.2]] },
{ name: 'NewYork', data: [['Jan', -0.2], ['Feb', 0.8], ['Mar', 5.7], ['Apr', 11.3], ['May', 17.0]] }
]
};
///To pass category from json object
var dataarrey = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
var items = [];
var item;
for (i = 0; i < dataarrey.length; i++) {
item = { data: dataarrey[i] };
items.push(item);
}
for (i = 0; i < items.length; i++)
{
options.xAxis.categories[i] = items[i].data;
}
$('#container').highcharts(options);
});
Take a look at the connectNulls property:
http://api.highcharts.com/highcharts#plotOptions.area.connectNulls
Just remove the point with the null value:
series: [
{
name: 'tokio',
data: $.grep([['Jan', 7.0],['Feb', 6.9],['Mar', null],['Apr', 18.2]],
function(i){
return i[1] != null;
})
},
{
name: 'NewYork',
data: [['Jan', -0.2], ['Feb', 0.8], ['Mar', 5.7], ['Apr', 11.3], ['May', 17.0]]
}
]
I have an irregular set of data with empty intervals, but I have no way of knowing.
Is there any way to highlight them on the graph?
Example: http://i.stack.imgur.com/fzZ4f.jpg
I use xAxis: {ordinal: false} for the graph line, but I need to highlight empty points, for example like this: http://i.stack.imgur.com/xTZbZ.jpg
In the series, the points are missing, and do not receive null points. And I can't set to null. Code script with graph:
// Example data:
data = [[x1,y1],[x2,y2],[x6,y6]]; // x3,x4 and x5 are missing.
function changeData(min, max) {
var chart = $('#{{div_id}}').highcharts();
chart.showLoading('Actualizando datos...');
var params = {type:'{{type}}', id: '{{id}}', from: min, to: max};
$.post("{{url('dashboardmetric')}}", {metric: 'getDataGraphMetric', params: params},
function(data) {
$.each(data, function(i, v){
chart.series[i].setData(data[i], true); //Seteo de datos de la serie
});
chart.hideLoading(); //Se libera el bloquero
}, "json");
}
$(function() {
Highcharts.setOptions({
lang: {
months: ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'],
shortMonths: ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Oct', 'Nov', 'Dic'],
weekdays: ['Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado']
},
global: {
useUTC: false
}
});
$('#{{div_id}}').highcharts('StockChart', {
chart: {
borderColor: '#DDDDDD',
borderWidth: 1,
borderRadius: 10
},
title: {
text: '{{title}}'
},
credits: {
enabled: false
},
navigator: {//Es la serie historica y completa
adaptToUpdatedData: false,
height: 45,
series: {data: {{navigator}}}
},
scrollbar: {
liveRedraw: false
},
rangeSelector: {
buttons: [{type: 'hour', count: 6, text: '6H'},
{type: 'day', count: 1, text: '1D'},
{type: 'day', count: 2, text: '2D'},
{type: 'week', count: 1, text: '1S'},
{type: 'month',count: 1, text: '1M'},
{type: 'year', count: 1, text: '1A'},
{type: 'year', count: 2, text: '2A'},
{type: 'all',text: 'Todo'}]
},
xAxis: {
ordinal: false,
events: {
setExtremes: function(e) {
changeData(e.min, e.max);
}
}
},
yAxis: {
min: 0
},
plotOptions: {
series: {
lineWidth: 1,
states: {
hover: {
lineWidth: 1
}
},
marker: {
enabled: false,
lineWidth: 1,
states: {
hover: {
enabled: false
}
}
}
}
},
tooltip: {
formatter: function() {
shortMonths = new Array('Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Oct', 'Nov', 'Dic');
weekdays = new Array('Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado');
var date = new Date(this.x);
num_day = date.getDate();
index_weekday = date.getDay();
index_shortMonths = date.getUTCMonth();
if(date.getHours() < 10) {h = "0" + date.getHours();} else {h = date.getHours();}
if(date.getMinutes() < 10) {m = "0" + date.getMinutes();} else {m = date.getMinutes();}
var s = '<span style="font-size:10px">' + weekdays[index_weekday] + ', ' + shortMonths[index_shortMonths] + ' ' + num_day + ', ' + h + ':' + m + '</span>';
$.each(this.points, function(i, point) {
bits = point.y;
if(bits>=1000000000) {bits=(bits/1000000000).toFixed(2)+' Gb';}
else if(bits>=1000000) {bits=(bits/1000000).toFixed(2)+' Mb';}
else if(bits>=1000) {bits=(bits/1000).toFixed(2)+' Kb';}
else if(bits>1) {bits=bits+' bits';}
else if(bits==1) {bits=bits+' bit';}
else {bits='0 bits';}
serie = point.series;
s += '<br/><span style="color:'+serie.color+'">'+ serie.name +'</span>: <b>'+ bits +'</b>';
});
return s;
},
borderColor: '#FFA500',
valueDecimals: 0
{# valueSuffix: ' {{unit}}' #}
},
series: [
{% for serie in series %}
{
name: '{{serie.name | raw}}',
data: {{serie.data}},
color: '{{serie.color | raw}}',
marker: {
symbol: '{{serie.symbol | raw}}'
}
},
{% endfor %}
]
});
});
I am trying to use Highcharts to generate our website's availability information.
The Y axis is availability in percentage, the expected labels are:
[100, 99.9, 99, 90, 0]
code:
http://jsfiddle.net/2E9vF/1/
$(function () {
$('#container').highcharts({
chart: {
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
yAxis: {
title: {
text: "AVAILABILITY %"
},
labels: {
formatter: function() {
return 100-this.value;
}
},
type: 'logarithmic',
reversed:true,
min:0.01,
plotLines: [{
color: '#CCCCCC',
width: 2,
value: 0.1,
dashStyle: 'ShortDot'
},{
color: 'red',
width: 2,
value: 1,
dashStyle: 'ShortDot'
},{
color: '#CCCCCCC',
width: 2,
value: 10,
dashStyle: 'ShortDot'
}],
},
tooltip: {
formatter: function() {
return 'x:'+ this.x +'<br>'+
'y:'+ (100-this.y);
}
},
series: [{
// real data:
// [90, 98, 99.7, 100, 100, 99.9, 99.7, 90, 91, 98, 96, 97.3]
data: [10, 2, 0.3, 0, 0, 0.1, 0.3, 10, 9, 2, 4, 2.7]
}]
});
});
However, I have two issues that I need help with:
I cannot draw 100 in the y axis
Orginal data with value 100 cannot be shown in the chart
Here is the expected chart:
http://www.shareimage.ro/images/0j1o0bnccavkqds8icuy.jpg
In general negative numbers and zero-based are not supported, but you can workaround this: http://jsfiddle.net/2E9vF/2/
In steps:
Assume that value 0 will be represented as other one, for example 0.001 (or lower)
Set min for yAxis to that value
Update formatters for tooltip and yAxis.labels accordingly:
tooltip: {
formatter: function() {
if(this.y === 0.001) {
return 'x:'+ this.x +'<br>'+ 'y:100';
} else {
return 'x:'+ this.x +'<br>'+ 'y:'+ (100-this.y);
}
}
},
And:
yAxis: {
labels: {
formatter: function() {
if(this.isFirst) {
return 100;
}
return 100-this.value;
}
}
}
Is there a way in timeline chart to fill different colors from one point to another point, depending on the value of y?
In this example http://jsfiddle.net/highcharts/PMyHQ/
I want to apply the following rules:
y <= 2 = fill color blue
y <= 5 = fill color red
y <= 9 = fill color yellow
So:
April to May area color should be blue
May to June area color should be red
June to July area color should be yellow
jsfiddle code:
function applyGraphGradient() {
// Options
var threshold = 0,
colorAbove = '#EE4643',
colorBelow = '#4572EE';
// internal
var series = this.series[0],
i,
point;
if (this.renderer.box.tagName === 'svg') {
var translatedThreshold = series.yAxis.translate(threshold),
y1 = Math.round(series.yAxis.len - translatedThreshold),
y2 = y1 + 2; // 0.01 would be fine, but IE9 requires 2
// Apply gradient to the path
series.graph.attr({
stroke: {
linearGradient: [0, y1, 0, y2],
stops: [
[0, colorAbove],
[1, colorBelow]
]
}
});
// Apply gradient to the area
if (series.area) {
series.area.attr({
fill: {
linearGradient: [0, y1, 0, y2],
stops: [
[0, colorAbove],
[1, colorBelow]
]
}
});
}
}
// Apply colors to the markers
for (i = 0; i < series.data.length; i++) {
point = series.data[i];
point.color = point.y < threshold ? colorBelow : colorAbove;
if (point.graphic) {
point.graphic.attr({
fill: point.color
});
}
}
// prevent the old color from coming back after hover
delete series.pointAttr.hover.fill;
delete series.pointAttr[''].fill;
}
// Initiate the chart
var chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
events: {
load: applyGraphGradient
},
type: 'area'
},
title: {
text: 'Average monthly temperature'
},
yAxis: {
plotLines: [{
value: 0,
color: 'silver',
width: 2,
zIndex: 2
}],
title: {
text: 'Temperature (°C)'
}
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
series: [{
name: 'Temperature (°C)',
data: [-2, -3, -2, 2, 5, 9, 11, 11, 10, 8, 4, -1]
}]
});
Are there any plans on supporting the ability to apply different colors on specific areas (bounded by x and y coordinates) in the line chart, maybe for future releases?