I have been creating a Highstock chart and I am facing problem in fixing xAxis interval in date/time formatter code here according to live stock data on 30 minutes interval.
Here is the code of my chart:
Highcharts.setOptions({
global: {
timezoneOffset: 4 * 60
}
});
var dataObject = {
chart: {
renderTo: 'container',
defaultSeriesType: 'area',
width: '1280',
height: '640'
},
plotOptions: {
series: {
lineWidth: 1
}
},
xAxis: {
type: 'datetime',
dateTimeLabelFormats: {
second: '<br/>%H:%M:%S',
minute: '<br/>%H:%M:%S',
hour: '<br/>%H:%M:%S',
day: '%Y<br/>%b-%d',
week: '%Y<br/>%b-%d',
month: '%Y-%b',
year: '%Y'
},
tickPositions:['09:00:000','12:00:00','15:00:00','18:00:00']
},
yAxis: {
minPadding: 0.2,
maxPadding: 0.2,
min: minRange,
max: maxRange,
tickInterval: 0.5,
title: {
text: 'Last',
margin: 40
}
},
series: [{
name: 'AAPL',
fillColor : {
linearGradient : {
x1: 0,
y1: 0.8,
x2: 0,
y2: 0
},
stops : [
[0, Highcharts.getOptions().colors[0]],
[1, Highcharts.Color(Highcharts.getOptions().colors[0]).setOpacity(0).get('rgba')]
]
},
data: [[1440161106000,112.65],[1440161931000,112.65],[1440162841000,112.65],[1440163745000,112.65],[1440164584000,111.41],[1440164704000,111.11],[1440165543000,111.51],[1440166443000,110.96],[1440167345000,110.66],[1440168183000,109.29],[1440168300000,109.5],[1440169144000,109.17],[1440170038000,108.29],[1440170945000,108.92],[1440171784000,108.48],[1440171904000,108.61],[1440172743000,108.81],[1440173640000,108.6],[1440174544000,107.72],[1440175385000,108.03],[1440175503000,107.99],[1440176338000,108],[1440177245000,108.24],[1440178143000,108.4],[1440178983000,108.28],[1440179104000,108.21],[1440179915000,108.2],[1440180844000,108.3],[1440181743000,108.06],[1440182585000,107.71],[1440182705000,107.51],[1440183543000,107.5],[1440184444000,106.53],[1440185345000,106.08],[1440186184000,106.61]] }]
};
chart = new Highcharts.StockChart(dataObject),function(chart){
$('#container').bind("mousewheel",function(event,delta){
var x = event.originalEvent.wheelDelta /120;
console.log(x);
if (delta > 0) {
var min = chart.xAxis[0].getExtremes().min,
max = chart.xAxis[0].getExtremes().max;
chart.xAxis[0].setExtremes((min + 12 * 3600 * 1000),(max - 12 * 3600 * 1000));
} else {
var min = chart.xAxis[0].getExtremes().min,
max = chart.xAxis[0].getExtremes().max;
chart.xAxis[0].setExtremes((min - 12 * 3600 * 1000),(max + 12 * 3600 * 1000));
}
});
};
JSFiddle : jsfiddle.net/zubairsultan/cvnzkv0s/5
You can fix minTickInterval to 3600000 so your xAxis will be "hourly based":
xAxis: {
type: 'datetime',
dateTimeLabelFormats: {
second: '<br/>%H:%M:%S',
minute: '<br/>%H:%M:%S',
hour: '<br/>%H:%M:%S',
day: '%Y<br/>%b-%d',
week: '%Y<br/>%b-%d',
month: '%Y-%b',
year: '%Y'
},
minTickInterval: 3600000
},
See your JSFiddle modified here: http://jsfiddle.net/cvnzkv0s/9/
Is that what you want ?
Related
Highstock has a time range selector below the main graph that contains dates and times. For example 10. Oct in this example: https://www.highcharts.com/demo/stock/intraday-area
How can I format those, eg to say '10/10' instead?
As I understand you want to change the navigator date format, under the chart.
You can add "navigator" to your chart options like this;
navigator: {
xAxis: {
labels: {
formatter: function() {
var d = new Date(this.value),
month = '' + (d.getMonth() + 1),
day = '' + d.getDate(),
year = d.getFullYear();
if (month.length < 2)
month = '0' + month;
if (day.length < 2)
day = '0' + day;
return [day,month,year].join('/');
}
}
}
}
You can find full code snippet below and change formatter function.
Highcharts.getJSON('https://cdn.jsdelivr.net/gh/highcharts/highcharts#v7.0.0/samples/data/new-intraday.json', function (data) {
// create the chart
Highcharts.stockChart('container', {
title: {
text: 'AAPL stock price by minute'
},
subtitle: {
text: 'Using ordinal X axis'
},
xAxis: {
gapGridLineWidth: 0
},
navigator: {
xAxis: {
labels: {
formatter: function() { // You can change the function according to your needs.
var d = new Date(this.value);
var month = '' + (d.getMonth() + 1);
var day = '' + d.getDate();
var year = d.getFullYear();
if (month.length < 2)
month = '0' + month;
if (day.length < 2)
day = '0' + day;
return [day,month].join('/');
}
}
}
},
rangeSelector: {
buttons: [{
type: 'hour',
count: 1,
text: '1h'
}, {
type: 'day',
count: 1,
text: '1D'
}],
selected: 1,
inputEnabled: false
},
series: [{
name: 'AAPL',
type: 'area',
data: data,
gapSize: 5,
tooltip: {
valueDecimals: 2
},
fillColor: {
linearGradient: {
x1: 0,
y1: 0,
x2: 0,
y2: 1
},
stops: [
[0, Highcharts.getOptions().colors[0]],
[1, Highcharts.color(Highcharts.getOptions().colors[0]).setOpacity(0).get('rgba')]
]
},
threshold: null
}]
});
});
<div id="container" style="height: 400px; min-width: 310px"></div>
<script src="https://code.highcharts.com/stock/highstock.js"></script>
<script src="https://code.highcharts.com/stock/modules/data.js"></script>
<script src="https://code.highcharts.com/stock/modules/exporting.js"></script>
<script src="https://code.highcharts.com/stock/modules/export-data.js"></script>
I have a series that is composed of:
Daily values, until a certain date
6-monthly values, from that date
onward
I'd like to increase the tick interval exclusively for the second part of the chart, so I can compact the data. To be clear, I want the same space that represents one month on the left side of the chart to represent 6 months on the right side.
I'm not sure if Highcharts allows this... I think there can be two different approaches:
Create two series with two different axis and set one axis after the other
Set different tickInterval for the same axis.
Using tickPositions and tickPositioner I've only managed to show more or less ticks, but always keeping their position on the time axis.
This is my code:
Highcharts.chart('container', {
chart: {
zoomType: 'xy',
animation: false
},
title: {
text: 'Some data'
},
legend: {
verticalAlign: 'bottom',
borderWidth: 0
},
xAxis: {
type : 'datetime',
tickInterval: 30 * 24 * 3600 * 1000,
labels: {
useHTML: true,
rotation: -90
},
dateTimeLabelFormats: { // don't display the dummy year
month: '%b-%y',
year: '%Y'
},
plotLines: [{
color: 'gray',
dashStyle: 'longdashdot',
value: 1536278400000,
width: 1,
label: {
text: 'Selected Date'
}
}]
},
yAxis: {
title: {
text: null
},
maxZoom: 0.1
},
series: jsonData
});
Here's a jsfiddle with a subset of my original data.
Which would be the best way to achieve this?
Highcharts does not allow it by default, but you can use a workaround. You can create two xAxis with right size proportion and two series, like in an example below:
xAxis: [{
type: 'datetime',
endOnTick: false,
tickInterval: 30 * 24 * 3600 * 1000,
max: 1536278400000,
width: '65%',
labels: {
useHTML: true,
rotation: -90
},
dateTimeLabelFormats: { // don't display the dummy year
month: '%b-%y',
year: '%Y'
},
plotLines: [{
color: 'gray',
dashStyle: 'longdashdot',
value: 1536278400000,
width: 1,
label: {
text: 'Selected Date'
}
}]
}, {
min: 1536278400000,
startOnTick: false,
offset: 0,
type: 'datetime',
tickInterval: 180 * 24 * 3600 * 1000,
labels: {
useHTML: true,
rotation: -90
},
dateTimeLabelFormats: { // don't display the dummy year
month: '%b-%y',
year: '%Y'
},
width: '35%',
left: '65%'
}]
Live demo: https://jsfiddle.net/BlackLabel/zxd4j5tn/
I'm new to highcharts, but I seem to have an issue with the display of the large heatmap. The colors in the legend don't seem to match the colors in the actual chart.
The following is my chart configuration code.
function load_team_effort_by_day_of_week_heat_map(ele, config)
{
var self = $(ele);
var days = ["Monday", "Tuesday", "Wednesday", "Thursday","Friday", "Saturday", "Sunday"]
load_data(self, function(response)
{
var div = $("<pre/>")
.attr("id","csv")
.css("display","none");
div.html(response.data);
$("body").append(div);
var chart_container = self.attr("chart-container");
$("#"+chart_container).css("width","100%");
var min = new Date(response.min)
var max = new Date(response.max)
var max_value = response.max_range
var mid_range = parseFloat(max_value/4);
Highcharts.chart(chart_container, {
data: {
csv: document.getElementById('csv').innerHTML
},
chart: {
type: 'heatmap',
margin: [60, 10, 80, 50]
},
boost: {
useGPUTranslations: true
},
title: {
text: '',
align: 'left',
x: 40
},
subtitle: {
text: '',
align: 'left',
x: 40
},
xAxis: {
title: {
text: config.xlabel
},
type: 'datetime',
min: Date.UTC(min.getFullYear(), min.getMonth(), min.getDate()),
max: Date.UTC(max.getFullYear(), max.getMonth(), max.getDate()),
labels: {
align: 'left',
x: 5,
y: 14,
format: '{value:%b-%d-%Y}' // long month
},
showLastLabel: false,
tickLength: 16
},
yAxis: {
title: {
text: config.ylabel
},
labels: {
format: '{value}'
},
minPadding: 0,
maxPadding: 0,
startOnTick: false,
endOnTick: false,
tickPositions: [0, 1, 2, 3, 4, 5, 6],
tickWidth: 1,
min: 0,
max: 6,
reversed: true
},
colorAxis: {
stops: [
[0, '#EEEEEE'],
[mid_range, '#00ee33'],
[max_value, '#00ee33']
],
min: 0,
max: max_value,
startOnTick: false,
endOnTick: false,
labels: {
format: '{value}'
}
},
tooltip: {
formatter: function () {
var d = new Date(this.point.x)
var todate=d.getDate();
var tomonth=d.getMonth()+1;
var toyear=d.getFullYear();
var original_date=tomonth+'/'+todate+'/'+toyear;
return '<b>' + original_date + ', <b>' +
this.point.value + '</b> on <br><b>' + days[this.point.y] + '</b>';
}
},
series: [{
boostThreshold: 100,
borderWidth: 0,
nullColor: '#EEEEEE',
colsize: 7 * 24 * 36e5, // one week
turboThreshold: Number.MAX_VALUE // #3404, remove after 4.0.5 release
}]
});
self.parents('.white-background').removeClass("loadingdv");
self.parents('.white-background').find(".lodimg").remove();
//Remving extra div for legends on rite side
self.parents('.white-background').find(".legendcontainer").remove();
});
}
I have fiddle here
fiddle
What I want is to display all the days of jan 2012 on X-axis. i.e 1.jan,2.jan, and so on.I dont want interwal between two days.
this is x-axis code.
xAxis: {
type: 'datetime',
min: Date.UTC(2012, 0, 1),
max: Date.UTC(2012, 0, 31),
labels: {
step: 1,
style: {
fontSize: '13px',
fontFamily: 'Arial,sans-serif'
}
},
dateTimeLabelFormats: { // don't display the dummy year
month: '%b \'%y',
year: '%Y'
}
},
This can be done with the xAxis.tickInterval property. As it says right in the docs that to get an interval of 1 day you would do:
xAxis: {
type: 'datetime',
min: Date.UTC(2012, 0, 1),
max: Date.UTC(2012, 0, 31),
tickInterval: 24 * 3600 * 1000, // 1 day
labels: {
step: 1,
style: {
fontSize: '13px',
fontFamily: 'Arial,sans-serif'
}
},
As you can see it causes an overlap of your xAxis labels. You would then have to find the correct xAxis.labels formatting that suits your needs.
I did not able to get labels like [12:00,12:15,12:30,12:45,01:00,01:15,..] on X axis.
I got only 00:00 on X axis.I was not able to display increasing time values on X axes.
I want to start default from 12:00.
I used following code.
xAxis: {
type: 'datetime',
tickInterval : 1.5 * 3600 * 1000,
dateTimeLabelFormats : {
day : '%H:%M'
}
}
This worked for me in Dynamic Highchart.
$(document).ready(function () {
chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
defaultSeriesType: 'spline',
events: {
load: requestData
}
},
title: {
text: 'Sensor Data Vs. Time'
},
xAxis: {
type: 'datetime',
tickPixelInterval: 150,
maxZoom: 20 * 1000
},
yAxis: {
minPadding: 0.2,
maxPadding: 0.2,
title: {
text: 'Value',
margin: 80
}
},
series: [{
name: 'Sensor Data',
data: []
}]
});
});
With this I am displaying Hours, Minutes and seconds as well.
You haven't shown us what data you are supplying. Something like this works:
series: [{
name: 'Temperatures',
pointStart: new Date().getTime(),
pointInterval: 24 * 3600 * 1000,
data: [1.5 * 60 * 1000,1.2 * 60 * 1000,2.5 * 60 * 1000,1.9 * 60 * 1000,],
}]
http://jsfiddle.net/Fusher/pQ5EC/12/