Why is Highcharts x axis not respecting my categories in stacked area chart - highcharts

I have created a stacked area chart in Highcharts at https://jsfiddle.net/kg3b2xyL/ I am feeding the hours as 24 categories (I guess I could have fed timestamps with an X-axis interval instead, but I think either way should work?). Each series correspondingly has 24 entries. Highcharts is charting the data okay and shows all the categories I gave it, but then it adds additional categories for some reason at the end on the right side of the chart, so that the numbers extend to 24 even though my categories started in the middle of the day and the final category in the categories list is 18. Is this a bug in Highcharts? Do I have to switch to feeding timestamps, or is there a way for this to work as I have coded it?
Thanks!
Here is my HTML:
<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; margin: 0 auto"></div>
And my JavaScript:
Highcharts.chart('container', {
chart: {
type: 'area'
},
legend: {
enabled: false
},
title: {
text: 'Calls to technical support last 24 hours'
},
xAxis: {
title: {
text: 'Time of Day'
},
categories: ['19', '20', '21', '22', '23', '24', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18']
},
yAxis: {
title: {
text: 'Calls during the hour'
},
},
tooltip: {
split: true,
},
plotOptions: {
area: {
stacking: 'normal',
lineColor: '#666666',
lineWidth: 1,
marker: {
lineWidth: 1,
lineColor: '#666666'
}
}
},
series: [
{ name: 'Jane', data: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] },
{ name: 'John', data: [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] },
{ name: 'Julie', data: [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] },
{ name: 'Walter', data: [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] },
{ name: 'Andy', data: [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] },
{ name: 'Julio', data: [2, 0, 0, 2, 0, 0, 2, 0, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] },
{ name: 'Rachel', data: [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] },
{ name: 'Steven', data: [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] },
{ name: 'Phil', data: [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] },
]
});

The issue can be resolved by deleting the zeros from Julio nad Reachel data - there are too many zeros.
Demo:
https://jsfiddle.net/BlackLabel/h50m9y72/

Related

How to remove the padding on the both ends of the HighChart

I have been trying this for hours and still have no idea.
Here is the config that I am using
chart: {
type: 'xrange',
height: 800,
},
title: {
text: 'Patient Sessions Overview'
},
xAxis: {
title: 'Time of the Day',
type: 'datetime',
tickInterval: 3600*1000,
tickPixelInterval: 200,
labels: {
formatter: function () {
return Highcharts.dateFormat('%H:%M', this.value);
},
},
min: Date.UTC(2016,1,1),
max: Date.UTC(2016,1,2),
},
yAxis: {
title: 'Day of the Month',
type: 'datetime',
tickInterval: 3600*1000*24,
//tickPixelInterval: 100,
min: Date.UTC(2016,1),
max: Date.UTC(2016,2) - 3600*1000*24
//min: 0,
//max: 31
},
plotOptions:{
series: {
pointPadding: 0,
groupPadding: 0
}
},
series: [{
name: 'Sessions',
//pointStart: Date.UTC(2000,0,1),
//pointInterval: 3600*1000,
//pointPadding: 10,
// groupPadding: 0,
borderRadius: 5,
pointWidth: 20,
data: [{
x: Date.UTC(2016, 1, 1, 0),
x2: Date.UTC(2016, 1, 1, 9),
y: Date.UTC(2016,1,4)
}, {
x: Date.UTC(2016, 1, 1, 12),
x2: Date.UTC(2016, 1, 1, 15),
y: Date.UTC(2016,1,5)
}, {
x: Date.UTC(2016, 1, 1, 8),
x2: Date.UTC(2016, 1, 1, 9),
y: Date.UTC(2016,1,14)
}, {
x: Date.UTC(2016, 1, 1, 8),
x2: Date.UTC(2016, 1, 1, 9),
y: Date.UTC(2016,1,20)
}, {
x: Date.UTC(2016, 1, 1, 8),
x2: Date.UTC(2016, 1, 1, 23),
y:Date.UTC(2016,1,25)
},],
}]
Here is the jsfiddle link
I need to remove the chart to make full use of the plot area without leaving a huge white space on both ends.
It is problem with unsorted data. In fact, you can not sort your data as Highcharts would expect, because some of the points are starting before previous one are ended. However, for such case, series.pointRange = 1 resolves all issues, take a look: http://jsfiddle.net/umndydLL/1/
Use following in your chart config:
spacingBottom: 0,
spacingTop: 0,
spacingLeft: 0,
spacingRight: 0,
margin:0,
padding:0

TCPDF alignment rendering issue

I'm getting weird alignment issues with TCPDF.
Here's a chunk of my looping code:
$pdf->setColor('text', 255, 255, 255);
$pdf->SetFontSize(20);
$pdf->Cell( 180, 25, $post->post_title, 0, 1, 'R', false, '', 3);
$pdf->Ln(1);
$pdf->setColor('text', 0, 0, 0);
$pdf->SetFontSize(14);
$pdf->Cell( 180, 8, $product->get_sku(), 0, 1, 'R', false);
$pdf->Ln(4);
$pdf->Image( $product->post->thumbnail, 15, 50, 80, 0, 'JPG', '', '', true, 150, '', false, false, 0, false, false, false);
$pdf->SetFontSize(10);
$pdf->MultiCell(90, 0, '', 1, 'C', 1, 0, '', '', true, 0, false, true, 0, 'T');
$pdf->setCellHeightRatio(1.65);
$pdf->MultiCell(90, 0, ($post->post_excerpt ? $post->post_excerpt : 'No description found.'), 1, 'C', 1, 1, '', '', true, 0, true, true, 0);
$pdf->setCellHeightRatio(0);
And here are the results which vary from first line centering for description to the more obvious title alignment even though it is from the same loop :
What gives?
Makes me wonder if I should have just stuck with FPDF...

Highcharts Gauge Chart with text labels

i have a gauge charts with defined tick positions and want to show some text labels there. e. g.:
-300 => Text 1
-200 => Text 2
-100 => Text 3
...
Is there a way to do that? Here's a fiddle of the chart.
jsfiddle.net/r8d3jnx6/
$('#container').highcharts({
chart: {
type: 'gauge',
alignTicks: false,
plotBackgroundColor: null,
plotBackgroundImage: null,
plotBorderWidth: 0,
plotShadow: false
},
title: {
text: null
},
tooltip: {
enabled: false
},
pane: {
startAngle: -70,
endAngle: 70,
background: null
},
plotOptions: {
gauge: {
dial: {
baseWidth: 2,
baseLength: '100%',
radius: '100%',
rearLength: 0
},
pivot: {
radius: 5
},
dataLabels: {
enabled: false
}
}
},
yAxis: [ {
min: -300,
max: 500,
tickPositions: [-300, -200, -100, 0, 100, 200, 300, 400, 500],
lineColor: '#933',
lineWidth: 0,
minorTickPosition: 'outside',
tickLength: 0,
minorTickLength: 0,
labels: {
distance: 12,
//rotation: 'auto'
},
//categories: ['Grunder'],
offset: 0,
plotBands: [{
from: -300,
to: 2,
thickness: 15,
color: '#55BF3B'
}, {
from: 0,
to: 202,
thickness: 15,
color: {
linearGradient: {x1: 0, x2: 1, y1: 0, y2: 0},
stops: [
[0, '#55BF3B'], //green
[1, '#DDDF0D'] //yellow
]
}
}, {
from: 200,
to: 500,
thickness: 15,
color: {
linearGradient: {x1: 0, x2: 1, y1: 0, y2: 0},
stops: [
[0, '#DDDF0D'], //yellow
[1, '#ff0000'] //red
]
}
}]
}, {
min: -200,
max: 200,
lineColor: '#339',
tickColor: '#339',
minorTickColor: '#339',
offset: -100,
lineWidth: 2,
labels: {
enabled: false
},
tickLength: 5,
minorTickLength: 5,
endOnTick: false
}],
series: [{
data: [250]
}]
});
You can use a yAxis.labels.formatter function to check what the label value is, and return a text of your choice depending on that value.
To take your example, it could look like this:
yAxis: {
labels: {
formatter: function() {
if(this.value == -300) return '-300 => Text 1';
if(this.value == -200) return '-200 => Text 2';
if(this.value == -100) return '-100 => Text 3';
return this.value;
}
}
See this updated JSFiddle of how it works. As you can see you'll have to face the potential issue of labels overlapping the gauge, but you can fix that with distance, rotation and some other attributes (see API), depending on how your labels end up looking.

how to add xAxis.tick dynamically

I'm coding a dynamic chart (a monitor app) which xAxis is datetime type, every three seconds I pull data from DB and add new point for each serie (so far so good). The problem comes with tick, every time I add a new point all ticks take the current time instead of keeping their original value when they were created this is my code
var chart1Obj = {
chart: {
renderTo: 'welcome-chart',
type: 'line',
animation: Highcharts.svg, // don't animate in old IE
// marginRight: 10,
events: {
load: function () {
// set up the updating of the chart each second
var series = this.series;
setInterval(function () {
Meteor.call("getGraphData", function (error, json) {
if (error) {
console.error("Welcome.graphData() failed\n", error);
} else {
temp = JSON.parse(json);
series[0].addPoint([temp.running], true, true);
series[1].addPoint([temp.queued], true, true);
series[2].addPoint([temp.suspended], true, true);
}
});
}, 3000);
}
}
},
title: {
text: 'Job monitoring'
},
xAxis: {
type: 'datetime',
tickPixelInterval: 150,
labels: {
formatter: function () {
var myTime = new Date();
return Highcharts.dateFormat('%H:%M:%S', myTime.getTime());
}
}
},
yAxis: {
title: {
text: 'Number of Task'
},
floor: 0,
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
exporting: {
enabled: false
},
series: [{
name: 'Running',
data: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
width: 1,
color: '#00FF00'
}, {
name: 'Queued',
width: 2,
data: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
color: '#FFFF00'
}, {
name: 'Suspended',
width: 3,
data: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
color: '#FF0000'
}]
};
Highcharts.setOptions({
global: {
useUTC: false,
}
});
var chart1 = new Highcharts.Chart(chart1Obj);
so the question is, what am I doing wrong? or what am I missing?
It's caused by this lines:
labels: {
formatter: function () {
var myTime = new Date();
return Highcharts.dateFormat('%H:%M:%S', myTime.getTime());
}
}
new Date() will create date object with actual time. Then you use that date for each label in tick labels. simply use:
return Highcharts.dateFormat('%H:%M:%S', this.value);

OpenCV Flann index save and load does not work

I am trying this simple test to check if I can store prepopulated indices to file and load them at later times. The saved and loaded mats are different. Also, knnSearch throws segfaults during the matching. I am seeing this issue only when using LSHIndexParams (for binary features).
void flannSaveAndLoadTest(Mat descriptor) {
// construct an index
flann::LshIndexParams lshIndexParams(20,10,2);
flann::Index kdtree(descriptor, lshIndexParams, cvflann::FLANN_DIST_HAMMING);
// save descriptors to file
writeMatToFile(descriptor, "before_index_save.dat");
// save index to file
kdtree.save("index.dat");
// load index from file
Mat mat = Mat(descriptor.rows, descriptor.cols, CV_8UC1);
flann::Index kdtree1(mat, flann::SavedIndexParams("index.dat"), cvflann::FLANN_DIST_HAMMING);
// save loaded mat
writeMatToFile(mat, "after_index_save.dat");
// search in this tree
Mat dists = Mat(descriptor.rows, 2, CV_32S);
Mat indices = Mat(descriptor.rows, 3, CV_32S);
kdtree1.knnSearch(descriptor, indices, dists, 2);
}
before_index_save:
%YAML:1.0
mat: !!opencv-matrix
rows: 60
cols: 32
dt: u
data: [ 10, 157, 16, 137, 81, 214, 178, 39, 45, 5, 74, 1, 172, 30, 38,
196, 144, 59, 131, 33, 84, 152, 17, 223, 39, 52, 10, 67, 18, 6,
141, 206, 11, 91, 50, 141, 119, 86, 190, 48, 45, 76, 94, 167, 236,
30, 183, 228, 246, 125, 151, 231, 197, 144, 49, 236, 39, 125, 138,
131, 14, 63, 61, 223, 15, 95, 35, 135, 119, 30, 190, 168, 45, 232,
91, 231, 204, 94, 159, 228, 246, 93, 147, 231, 197, 144, 125, 238,
38, 60, 143, 135, 14, 55, 57, 213, 10, 149, 16, 129, 81, 214, 178,
39, 45, 5, 74, 1, 172, 30, 6, 196, 144, 27, 131, 33, 22, 152, 17,
207, 39, 52, 10, 67, 18, 6, 141, 206, 124, 236, 196, 30, 137, 161,
70, 207, 210, 179, 169, 24, 99, 225, 105, 158, 9, 226, 104, 26,
58, 111, 142, 51, 184, 134, 85, 124, 243, 123, 210, 8, 10, 0, 16,
129, 81, 214, 176, 3, 45, 5, 66, 1, 140, 30, 38, 196, 128, 25,
131, 1, 4, 152, 17, 196, 7, 20, 26, 67, 2, 4, 13, 206, 244, 172,
157, 122, 137, 237, 69, 206, 210, 179, 161, 24, 115, 241, 73, 27,
9, 226, 104, 26, 58, 111, 218, 51, 217, 131, 85, 124, 240, 121,
198, 34, 197, 36, 157, 103, 128, 46, 103, 184, 112, 162, 43, 88,
215, 115, 9, 123, 17, 68, 104, 106, 49, 212, 217, 10, 237, 166,
101, 20, 192, 115, 2, 32, 252, 188, 189, 118, 137, 124, 85, 158,
179, 247, 166, 24, 223, 247, 75, 59, 129, 214, 236, 26, 56, 103,
251, 32, 219, 251, 85, 63, 194, 113, 198, 114, 196, 64, 157, 39,
1, 78, 38, 8, 40, 178, 35, 8, 214, 115, 73, 27, 144, 84, 104, 98,
96, 212, 217, 8, 197, 178, 65, 20, 0, 115, 3, 34, 11, 91, 50, 141,
119, 86, 191, 48, 13, 76, 94, 167, 236, 30, 183, 228, 246, 125,
after_index_save:
%YAML:1.0
mat: !!opencv-matrix
rows: 60
cols: 32
dt: u
data: [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 110, 100, 101,
120, 95, 115, 97, 118, 101, 46, 100, 97, 116, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 241, 1, 0, 0, 0, 0, 0, 0, 152, 169, 51, 241, 97, 127,
0, 0, 152, 169, 51, 241, 97, 127, 0, 0, 0, 0, 0, 0, 98, 101, 102,
111, 114, 101, 95, 105, 110, 100, 101, 120, 95, 115, 97, 118, 101,
46, 100, 97, 116, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0,
176, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 192, 188, 45, 1,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 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