Im doing a chart with 2 series. One of the series is 'scatter' type and the other is 'column' type.
The problem i have, is that when i only have the scatter series, datetime labels on x axis, starts on the extreme left, but when i add the column series, is like all labels are pushed to the center, and i dont know why.
This is my fiddle examen: https://jsfiddle.net/cswpgq8u/7/
Highcharts.chart('container', {
chart: {
},
xAxis: {
type: 'datetime',
min: 1633057200000,
max: 1634353200000,
tickPositioner: function () {
var ticklist = [];
var extremes = this.getExtremes();
var startDate = extremes.min;//this.min;
var endDate = extremes.max; // this.max;
var diff = moment.duration(endDate - startDate);
if (diff.days() * 1 > 10)
increment = moment.duration(2, 'days').asMilliseconds();
else
increment = Math.ceil((endDate - startDate) / 10);
for (var timeline = startDate; moment(timeline) <= moment(endDate); timeline += increment) {
ticklist.push(timeline);
}
return ticklist;
},
maxPadding: 0,
minPadding: 0,
crosshair: {
enabled: true,
events: {
}
},
plotLines: [{
value: 1634266800000,
color: 'green',
width: 1,
dashStyle: 'ShortDash',
label: {
text: "AHORA", // Content of the label.
verticalAlign: 'bottom',
rotate: -90,
textAlign: 'right',
x: -2,
y: 30,
style: { color: '#6d6d6d', fontSize: '8px', fontWeight: 'bold', backgroundColor: 'white' }
},
}],
plotBands: null,
labels: {
formatter: function () {
var xMin = this.axis.min;
var xMax = this.axis.max;
var labeltick = Highcharts.dateFormat('%d. %B', this.value);
if ((moment(xMax).diff(moment(xMin), 'days')) < 10) {
labeltick = Highcharts.dateFormat('%d. %B %H:%M:%S', this.value);
}
return labeltick;
},
x: -10
}
},
yAxis:[
{
plotLines: [{
id: 'ln-' + 'idEje1',
color: '#9FA0A2',
width: 0,
value: 0,
dashStyle: 'longdashdot'
}],
labels: {
enabled:true,
x: -5,
y: -3,
},
title: {
enabled: false,
},
lineColor: 'lightgray',
lineWidth: 0,
tickInterval: 1
}, {
title: {
enabled: false,
},
lineColor: 'lightgray',
opposite: true,
labels: {
enabled: false,
x: -15,
y: -3,
},
lineWidth: 0,
tickInterval: 1
}
],
plotOptions: {
},
series: [
{
yAxis: 0,
type: 'scatter',
minPointLength: 1,
allowPointSelect: false,
stack: true,
data: [{
x: 1634007600000,
y: 2,
value: 2,
marker: {
symbol: 'circle',
radius: 3,
fillColor: 'red',
},
type: "ttf"
},
{
x: 1633748400000,
y: 5,
value: 2,
marker: {
symbol: 'circle',
radius: 3,
fillColor: 'red',
},
type: "ttf"
},
{
x: 1633143600000,
y: 2,
value: 2,
marker: {
symbol: 'circle',
radius: 3,
fillColor: 'red',
},
type: "ttf"
},
{
x: 1633402800000,
y: 2,
value: 2,
marker: {
symbol: 'circle',
radius: 3,
fillColor: 'red',
},
type: "ttf"
}],
name: 'On YAxis 0',
tooltip: {
pointFormatter: function () {
var point = this;
return "Valor TTF:" + ' <b>' + point.y + ' Días</b><br/>';
},
}
},
{
yAxis: 1,
type: 'column',
allowPointSelect: false,
minPointLength: 1,
data: [{
x: 1633708800000,
y: 5,
type: "duracion",
value: 5
},
{
x: 1633881600000,
y: 3,
type: "duracion",
value: 3
}],
name: 'On YAxis1',
tooltip: {
pointFormatter: function () {
var point = this;
return "Duración:" + ' <b>' + point.y + ' minutos</b><br/>';
},
},
pointWidth: 1
}
]
});
With 2 series
With one series
I think this is happening because Column Series. But dont know how to solve it.
The additional space is caused by the default calculation of pointRange for column series. You need to define it by yourself:
series: [{
type: 'scatter',
...
},
{
type: 'column',
pointRange: 1,
...
}
]
Live demo: https://jsfiddle.net/BlackLabel/hsrxtjaw/
API Reference: https://api.highcharts.com/highcharts/series.column.pointRange
Related
A smoother line is needed (the line should rise smoothly and evenly), but the values should not change. Is it possible to build a more straight line without changing the values?
Screen with explanations: http://prntscr.com/qudf96
And my code:
<script>
function reDrawCalc(gdata, gcurr, nums = 2) {
Highcharts.chart('container', {
chart: {
height: 400,
type: 'area',
margin: [20, 0, 20, 0]
},
title: {
text: null
},
subtitle: {
text: null
},
exporting: {
enabled: false
},
xAxis: {
gridLineWidth: 1,
categories: ['One', 'Two', 'Three', 'Four', 'Five']
},
yAxis: {
gridLineWidth: 0,
},
tooltip: {
enabled: false,
crosshairs: true
},
plotOptions: {
series: {
dataLabels: {
enabled: true,
useHTML: true,
inside: false,
style: {
fontFamily: 'Rubik, sans-serif',
textTransform: 'uppercase',
fontSize: 'none',
fontWeight: 'normal',
textShadow: 'none'
},
formatter: function() {
return '<div class="chitem-time">'+ this.x+'</div>'
+'<div class="chitem-val">'+ Highcharts.numberFormat(this.y,nums)+'<sup>'+gcurr+'</sup></div>';
}
}
}
},
series: [{
type: 'areaspline',
data: gdata,
lineWidth: 5,
color: '#f0c997',
fillColor:'transparent'
}],
responsive: {
rules: [{
condition: {
maxWidth: 500
},
chartOptions: {
chart: {
height: 350,
type: 'area',
margin: [20, 0, 20, 0]
},
series: [{
type: 'areaspline',
data: gdata,
lineWidth: 3,
color: '#f0c997',
fillColor:'transparent'
}],
}
}]
}
});
}
</script>
Is it possible to do it? And how to modify my code for it?
Thank you very much in advance!
As I mentioned in the comment current line shape is at it is because of the points positions on the chart. If you don't need to keep points actual positions the solution which you can use is to use the dummy data for the points and use the correct one in the dataLabels. See:
Demo: https://jsfiddle.net/BlackLabel/fshx3n50/
data: [{
y: 5,
z: 0.20
}, {
y: 10,
z: 1.40
}, {
y: 18,
z: 6.20
}, {
y: 30,
z: 18.00
}, {
y: 50,
z: 73.00
}],
I also changed the formatter function to display the z value in dataLabel:
formatter: function() {
return '<div class="chitem-time">' + this.x + '</div>' +
'<div class="chitem-val">' + Highcharts.numberFormat(this.point.z) + '<sup>REM</sup></div>';
}
Here is a sample fiddle (1) that shows the series name along the line body
(Sessions, Users). How do I make similar label for a highstock chart?
(The label seems to be appearing due to the data module that does the csv processing)
(1) https://jsfiddle.net/4restw8a/9/
Highcharts.chart('container', {
chart: {
scrollablePlotArea: {
minWidth: 700
}
},
data: {
csvURL: 'https://cdn.rawgit.com/highcharts/highcharts/' +
'057b672172ccc6c08fe7dbb27fc17ebca3f5b770/samples/data/analytics.csv',
beforeParse: function (csv) {
return csv.replace(/\n\n/g, '\n');
}
},
title: {
text: 'Daily sessions at www.highcharts.com'
},
subtitle: {
text: 'Source: Google Analytics'
},
xAxis: {
tickInterval: 7 * 24 * 3600 * 1000, // one week
tickWidth: 0,
gridLineWidth: 1,
labels: {
align: 'left',
x: 3,
y: -3
}
},
yAxis: [{ // left y axis
title: {
text: null
},
labels: {
align: 'left',
x: 3,
y: 16,
format: '{value:.,0f}'
},
showFirstLabel: false
}, { // right y axis
linkedTo: 0,
gridLineWidth: 0,
opposite: true,
title: {
text: null
},
labels: {
align: 'right',
x: -3,
y: 16,
format: '{value:.,0f}'
},
showFirstLabel: false
}],
legend: {
align: 'left',
verticalAlign: 'top',
borderWidth: 0
},
tooltip: {
shared: true,
crosshairs: true
},
plotOptions: {
series: {
cursor: 'pointer',
point: {
events: {
click: function (e) {
hs.htmlExpand(null, {
pageOrigin: {
x: e.pageX || e.clientX,
y: e.pageY || e.clientY
},
headingText: this.series.name,
maincontentText: Highcharts.dateFormat('%A, %b %e, %Y', this.x) + ':<br/> ' +
this.y + ' sessions',
width: 200
});
}
}
},
marker: {
lineWidth: 1
}
}
},
series: [{
name: 'All sessions',
lineWidth: 4,
marker: {
radius: 4
}
}, {
name: 'New users'
}]
});
This comes from the series label module, which you can use by including series-label.js:
<script src="https://code.highcharts.com/modules/series-label.js"></script>
See this JSFiddle example of a Highstock chart with it included.
See this API documentation for its settings.
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();
});
}
Im trying to create plotbands but does not work correctly.
Here is my fiddle and code.
https://jsfiddle.net/z0h85fku/
Javascript
$(function() {
categories = ["09/07/2016 00:00", "09/07/2016 00:01", "09/07/2016 00:02", "09/07/2016 00:03", "09/07/2016 00:04"]
rate_1 = [0.8, 0.54, 0.6, 0.3, 0.4]
rate_2 = [0.33, 0.16, 0.33, 0.3, 0.38]
rate_3 = [0.03, 0.04, 0.05, 0.03, 0.01]
var addCallout = function(chart) {
$('.callout').remove();
var xAxis = chart.xAxis[0],
yAxis = chart.yAxis[0],
series = chart.series[0],
point = series.data[0];
console.log('xAxis == ', xAxis)
console.log('yAxis == ', yAxis.toPixels)
console.log('series == ', series)
console.log('point == ', point)
console.log(point.plotY)
console.log(point.plotX)
var a = chart.renderer.label('<div class="callout top">This is the callout text!</div>', point.plotX + chart.plotLeft - 20,
point.plotY + chart.plotTop - 70, 'callout', null, null, true).add();
};
$('#container').highcharts({
chart: {
// type: 'bar',
events: {
load: function() {
addCallout(this);
},
redraw: function() {
addCallout(this);
},
}
},
title: {
text: 'Spikes Graph',
x: -20 //center
},
subtitle: {
text: '',
x: -20
},
events: {
load: function() {
// addCallout(this);
},
redraw: function() {
addCallout(this);
},
},
series: [{
turboThreshold: 2000 // to accept point object configuration
}],
xAxis: {
categories: categories,
<!-- tickInterval: 60,-->
plotBands: [{
color: 'orange', // Color value
// from: Date.UTC(09/07/2016 02:00), // Start of the plot band
// Date.UTC(year,month,day,hours,minutes,seconds,millisec)
from: Date.UTC(2016,9,7,0,0),
to: Date.UTC(2016,9,7,4,0)
// to: '09/07/2016 05:00' // End of the plot band
}],
type:'datetime'
},
yAxis: {
title: {
text: 'Error Rate'
},
min: 0,
max: 5,
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}],
labels: {
format: '{value} %'
}
},
tooltip: {
valueSuffix: '°C'
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'middle',
borderWidth: 0
},
series: [
// {turboThreshold: 2000 },
{
name: 'Rate-1',
data: rate_1,
turboThreshold: 2000,
lineWidth: 1,
dataLabels: {
enabled: true,
useHTML: true,
style: {
fontWeight: 'bold'
},
},
}, {
name: 'Rate-2',
data: rate_2,
turboThreshold: 2000,
lineWidth: 1
}, {
name: 'Rate-3',
data: rate_3,
turboThreshold: 2000,
lineWidth: 1
}
]
});
});
I have some problem with IE 7 to show the chart I designed by Highstock.
When I've tried to design the chart and see it on Chrome, it does not have any problem.
Here is the chart which is exactly I want to see.
http://211.47.191.60/temp/Cap_origin_from_chrome
However, when I've tried to see it on IE 7, it shows like this.
http://211.47.191.60/temp/Cap_from_IE7
Here is the javascript source I've designed through using Fiddle.
$(function () {
// Create the chart
window.chart = new Highcharts.StockChart({
chart: {
renderTo: 'container',
type: 'areaspline',
backgroundColor: '#FFFFFF',
shadow: true
},
credits: {
enabled: false
},
rangeSelector: {
buttons: [{
type: 'day',
count: 1,
text: '1D'
}, {
type: 'day',
count: 15,
text: '2W'
}, {
type: 'month',
count: 1,
text: '1M'
}, {
type: 'month',
count: 3,
text: '3M'
}, {
type: 'month',
count: 6,
text: '6M'
}, {
type: 'year',
count: 1,
text: '1Y'
}, {
type: 'all',
text: '전체'
}],
inputStyle: {
color: '#039'
},
labelStyle: {
color: 'silver'
},
selected: 1
},
navigator: {
enabled: false
},
xAxis: {
//categories: ['1회차', '2회차', '3회차', '4회차', '5회차', '6회차', '7회차'], // 동적으로 늘려야 함
showFirstLabel: false,
showLastLabel: true,
tickPixelInterval: 150,
tickColor: 'green',
tickLength: 10,
tickWidth: 2,
tickPosition: 'inside',
//type: 'datetime',
//dateTimeLabelFormats: {
// day: '%Y<br/>%m-%d',
// week: '%Y<br/>%m-%d',
// month: '%Y-%m',
// year: '%Y'
//},
labels: {
rotation: -30,
y: 10
}
},
yAxis: {
tickPixelInterval: 40,
tickColor: 'gray',
tickLength: 10,
tickWidth: 2,
tickPosition: 'inside',
gridLineWidth: 1,
gridLineDashStyle: 'longdash',
minorGridLineColor: '#FFF0F0',
minorGridLineWidth: 1,
minorTickInterval: 'auto',
min: 0,
max: 100,
plotLines: [{
value: 90, // DB 에서 평가 기준 받아와 저장 필요
width: 3,
color: 'red',
dashStyle: 'dash',
label: {
text: '평가기준',
align: 'top',
y: -4,
x: 12
}
}],
title: {
align: 'high',
offset: 0,
text: '종합품질점수',
rotation: 0,
y: -10
},
labels: {
formatter: function () {
return this.value + ' 점';
},
x: -30
}
},
plotOptions: {
series: {
marker: {
enabled: true
}
}
},
scrollbar: {
enabled: true,
minWidth: 5,
barBackgroundColor: 'gray',
barBorderRadius: 7,
barBorderWidth: 0,
buttonBackgroundColor: 'gray',
buttonBorderWidth: 0,
buttonArrowColor: 'yellow',
buttonBorderRadius: 7,
rifleColor: 'yellow',
trackBackgroundColor: 'white',
trackBorderWidth: 1,
trackBorderColor: 'silver',
trackBorderRadius: 7
},
series: [{
name: '종합품질점수',
data: [{
name: '1회차',
color: 'red', //평가 기준 만족 시 blue, 불만족시 red
events: {
click: function () {
alert("!!!!");
}
},
x: Date.UTC(2013, 0, 1),
y: 32
}, {
name: '2회차',
color: 'red', //평가 기준 만족 시 blue, 불만족시 red
events: {
click: function () {
alert("####");
}
},
x: Date.UTC(2013, 0, 2),
y: 41
}, {
name: '3회차',
color: 'red', //평가 기준 만족 시 blue, 불만족시 red
events: {
click: function () {
alert("####");
}
},
x: Date.UTC(2013, 0, 3),
y: 54
}, {
name: '4회차',
color: 'red', //평가 기준 만족 시 blue, 불만족시 red
events: {
click: function () {
alert("$$$$");
}
},
x: Date.UTC(2013, 0, 4),
y: 67
}, {
name: '5회차',
color: 'red', //평가 기준 만족 시 blue, 불만족시 red
events: {
click: function () {
alert("%%%%");
}
},
x: Date.UTC(2013, 0, 5),
y: 74
}, {
name: '6회차',
color: 'blue', //평가 기준 만족 시 blue, 불만족시 red
events: {
click: function () {
alert("^^^^");
}
},
x: Date.UTC(2013, 0, 6),
y: 85
}, {
name: '7회차',
color: 'blue', //평가 기준 만족 시 blue, 불만족시 red
events: {
click: function () {
alert("&&&&");
}
},
x: Date.UTC(2013, 0, 7),
y: 91
}],
type: 'area',
pointStart: Date.UTC(2013, 0, 1),
pointInterval: 24 * 3600 * 1000,
showInLegend: true,
threshold: null,
tooltip: {
valueDecimals: 2
},
fillColor: {
linearGradient: {
x1: 0,
y1: 0,
x2: 1,
y2: 1
},
stops: [
[0, Highcharts.getOptions().colors[0]],
[1, 'rgba(0,0,0,0)']
]
}
}]
});
});
There is some Korean character, please do not mind about it.
Can anyone help me to solve this problem?
It looks like bug with plotLines in Highcharts, reported: https://github.com/highslide-software/highcharts.com/issues/1478
Possible workaround is to add plotLine in callback, see example: http://jsfiddle.net/f9aTL/12/ (still not perfect solution)
Callback:
function (chart) {
chart.yAxis[0].addPlotLine({
value: 90, // DB 에서 평가 기준 받아와 저장 필요
width: 3,
color: 'red',
dashStyle: 'Dash',
label: {
text: '평가기준',
align: 'top',
y: -4,
x: 12
}
});
});