Highcharts Gantt - Set max height and scrollbar on yAxis - javascript

I'm doing a project using Highcharts Gantt, and I'm having a little trouble mastering it at the moment, especially the management of its height and Y axis.
Here Sandbox : https://codesandbox.io/s/nice-microservice-fuv76?file=/src/GanttMain.jsx:334-352
Let me explain:
What I want to do is set a maximum height and use scrollablePlotArea to make the y-axis scroll, while keeping the X-axis header.
The problem is: if I define a minHeight in scrollablePlotArea, the Y axis cuts the events until the minimum height defined (see sandbox), if I increase minHeight, it will cut less events, but the number is dynamic, so impossible to put a fixed value...
My question is: How to define a maximum height, while keeping a Y scroll that displays all events, While not changing the line height?
I tried several possibilities with the documentation, but nothing works...
I hope I made myself understood...
Thank you very much for your help.

This problem is a bug in Highcharts Gantt and it is similar to this issue: https://github.com/highcharts/highcharts/issues/13884
As a workaround you can dynamically set minHeight for scrollable plot area, example:
let allowChartUpdate = true;
Highcharts.ganttChart('container', {
chart: {
animation: false,
scrollablePlotArea: {
minHeight: 450
},
events: {
render: function() {
if (allowChartUpdate) {
allowChartUpdate = false;
this.update({
chart: {
scrollablePlotArea: {
minHeight: ...
}
}
});
allowChartUpdate = true;
}
}
}
},
...
});
Live demo: http://jsfiddle.net/BlackLabel/ywt2cmkn/
API Reference: https://api.highcharts.com/gantt/chart.events.render

Related

Center Highcharts tooltip in the middle of donut chart in a responsive way

In Highcharts, I know you can put your tooltip in a fixed position using:
tooltip: {
positioner: function () {
return { x: 50, y: 50 };
},
},
But how would I center it in the same way that margin: 0 auto would center it? I am trying to get the tooltip text to stay in the middle of a donut chart. The solution is probably something obvious but I have yet to figure out what it is. Thanks in advance!
You can make use of chart plotHeight and plotWidth to get access to current chart height and width and adjust the tooltip x and y accordingly as below:
positioner:function(){
return { x: chart.plotWidth/2, y: chart.plotHeight/2 };
}
A working demo here: https://angular-raebwk.stackblitz.io

Highstock/chart - On resize, don't crop chart

How to keep the chart from cropping on resize, but instead just change its viewport?
I find it a a bit hard to explain, so please let me know if more explanation is needed.
The chart on the first screenshot look nice, they have a 'normal spacing between them and the bars are not cropped. This one has a 1000px width.
Chart box wide
On the second screenshot, the chart is only 300px wide, and the candlesticks become 'cropped'..
Chart box cropped
Instead I would like to only change the viewport, so that the bars are never cropped and are always te same size.. Only the date-range (Viewport) changes.. You see more bars on a wider chart, but it doesn't meen the bars itself should grow or shrink.
I tried it with simple algoritme, but its very prone to error.
let parentW = this._elementRef.nativeElement.parentNode.clientWidth,
data = this.chart.xAxis[0].series[0].data,
barW = 10,
barsToShow = Math.ceil(parentW / barW),
firstBar = (data[data.length - barsToShow] || data[0]),
lastBar = data[data.length - 1];
this.chart.xAxis[0].setExtremes(firstBar.x, lastBar.x, redraw);
I couldn't find any setting in the Highcharts doc and google didn't help much either. Many thanks
Desired behaviour can be achieved with the changing data grouping groupPixelWidth property.
When the chart has smaller width than, e.g. 300px, groupPixelWdith can be set to a higher value.
responsive: {
rules: [{
chartOptions: {
plotOptions: {
series: {
dataGrouping: {
groupPixelWidth: 30
}
}
}
},
condition: {
maxWidth: 300
}
}]
}
example: http://jsfiddle.net/b894z8ug/1/

In Highcharts, how to avoid auto tick interval in a container with limited height

I found out that, when the container's height is very small, the y-axis' tick interval will be different from what you have assigned to yAxis.tickInterval.
Here is an example: https://jsfiddle.net/scottszb1987/9qgzerwn/
As you can see, even with yAxis.tickInterval set to 4, the appearance of the interval is 12 in the example.
I'm wondering, is this a Highcharts' mechanism to prevent axis label / grid line overlapping? Is there any way we could force the tick interval to display as what we set up regardless on the height of the container?
If you want to have equal interval between ticks.
You can use the tickPositioner function
yAxis: {
tickPositioner: function () {
var positions = [];
for(var i = 0; i < this.dataMax; i+=4){
positions.push(i);
}
return positions;
}
},
I've updated your FIDDLE
I hope I've helped you

Cannot set dimensions for a resizable donut chart

I'm using kendo-ui to draw a donut chart like in this example
but I want it to resize when the container div resizes.
Not trouble if you don't set size or sizeHole since it ill automatic scale to fit the div.
Now I want my donut to be thin (outter radius slight greater than inner radius).
If I try to set the size to 25 pixels the donut now don't fills all my div and wort only the sizeHole resizes.
seriesDefaults: {
type: "donut",
size: 25,
...
If I try to set the sizehole to 250 it ill no more resizes
seriesDefaults: {
type: "donut",
sizeHole: 250,
...
If I try to set both attibutes ill affect each other and at the donut don't resizes at all
What I really need is to fix the donut dimensions to some % of the container, lets say size to 50% and sizeHole to 5% and let user drag/rezise the browser and keep the size/sizeHole/Container size aspect ratio.
I tried something using
$(window).resize(Resize(element));
...
function Resize(element) {
var minContainerSize = element[0].clientHeight;
if (minContainerSize > element[0].clientWidth || minContainerSize == 0)
minContainerSize = element[0].clientwidth;
return function () {
var chart = element.data("kendoChart");
var pieSeries = chart.options.seriesDefaults;
pieSeries.size = minContainerSize * 0.13;
//pieSeries.holeSize = minContainerSize * 0.299;
chart.refresh();
}
};
But it not worked out since I ill need to get the container size AFTER the resize event ends to get the new container size.
I can try to implement something like this after resize solution
but code is turning in a mess fast.
There's any nice (unknow for me) property to simple set the donut "thickness" in as percentual or proportional to the whole size (in a way it keeps resizing) or any workaroud not involving setTimeout?
I think you should be using holeSize not sizeHole.
http://www.telerik.com/forums/donut-chart-set-inner-and-outer-radius

Highcharts Gauge - start/endAngle and height

I have a gauge chart that is revered.
If i set charts { height : 300 } and { startAngle: -76,endAngle: 234 } i get a nice centered gauge.
But if i change { height : 400 } start and end get all messed up and when i change them i get wierd results ...
This is with { height : 300 }
http://jsfiddle.net/v2Tz6/2/
This is with { height : 400 }
http://jsfiddle.net/v2Tz6/3/
Can someone please explane to me what is going on and how can i fix it ?
Also the start animation is messed up.Thats not so important,i guess i can just turn it of,but it would be nice to get a fix for that too.
Thanks.
You cannot use reversed parameter and plotbands in dicreasing order.

Categories