Highcharts sizing bars in a Grouped and stacked barcharts - highcharts

In a previous question, Paweł Fus was so kind to come up with a grouped stack bar chart solution for me. You can find the question and answer here for context: Grouping a stacked bar chart in Highcharts
I am now attempting to use this approach and i am plagued with issues because this doesn't seem to scale well at all. In the scenario in the previous post there was only two bars per group to keep it a simple example. In reality there could be any number of bars. With the approach laid out in Pawel Fus's answer, just adding a a third bar breaks it. The reason is that the pointPlacement is dependent on the number of bars which is an easy fix but you'll quickly realize that the bars are not getting automatically adjusted to account for the width. Take a look at this jsfiddle for a simple demo of what im talking about:JsFiddle
Mandatory random code block to make Stack overflow happy... just ignore this code block.
So my questions are:
is there a better solution to my original question that would avoid all this?
Assuming that this is the correct approach, how do i calculate and set the width of these bars accordingly then set the correct pointplacments. I did find that i can get the chart height but not till the Highcharts object is created and i'm programatically creating this Highcharts config so i don't have access to it at that point.

You can try different approach, but formatting data isn't so obvious: http://jsfiddle.net/1ktmb2d2/3/ (or this one: http://jsfiddle.net/1ktmb2d2/4/) - now each vertical columns are different stacks, and names of that stacks doesn't really matter (formatter must be changed).
Note: when displaying different number of columns per category, it will always create a gap in the category where the number of columns is the lowest.
Simplified data:
series: [{
name: 'Happy',
id: 'Happy',
stack: 'Corolla',
color: 'blue',
data: [20, 30],
}, {
id: 'Unhappy',
name: 'Unhappy',
stack: 'Corolla',
color: 'black',
data: [10, 30],
}, {
linkedTo: 'Happy',
stack: 'Prius',
color: 'blue',
data: [30, 30],
}, {
linkedTo: 'Unhappy',
stack: 'Prius',
data: [30, 30],
color: 'black',
}, {
linkedTo: 'Happy',
stack: 'Highlander',
color: 'black',
data: [30],
}]

So we have tried many things but have decided that Highcharts just isn't meant to do this sort of thing. We have given this feedback to our UX team as a limitation of what we can implement with Highcharts at this time. In the mean time we have made our labels more informative as a stop gap. This comes at the cost of making those labels very bulky.
I do agree with the UX design that sometimes it makes sense to group our stacked bars within our charts to make a clear and readable chart for our end user. I looked around at other charting frameworks and i didn't see anyone offering a way to do this. I would not say highcharts is lagging behind it's competitors but it could definitely differentiate it's self if it chose to implement a easy to use feature like this

Related

Highcharts symbol not appearing in chart (opacity set to 0, it appears)

I'm using HighCharts to display a couple of graphs on my Pregnancy Calculator. They were working perfectly until recently. Now, for some strange reason, the Symbol image of the teddy bear on the second chart is appearing (in the Highcharts code) as opacity:0 until you mouse over the space (at which point the teddy bear appears). I can't understand why it's suddenly doing this or seem to find a way to set it to opacity:1
https://www.thecalculatorsite.com/health/pregnancy-calculator.php
(you'll need to click 'calculate' and then scroll down to the second graph, marked as 'probability of birth by this day' - you'll see a gap in the graph where there isn't a green marker. The teddy bear symbol should be there, but isn't appearing until mouse-over).
Thanks for your help.
Set opacity to 1 for normal state:
series: [{
...,
data: [..., {
y: 54.805615550756,
marker: {
...,
states: {
normal: {
opacity: 1
}
}
}
}, ...]
}]
Live demo: https://jsfiddle.net/BlackLabel/zrp4tfdk/2/
API Reference: https://api.highcharts.com/highcharts/series.line.data.marker.states.normal

How to add extra tears(ticks) in highcharts?

HIGH CHARTS
In addition to this question, I would like to ask another question here in this thread.
How to add extra tears(ticks), in such a way, the green bar dataLabel, does stay inside plotting area, rather, going out of plotting area or made hidden. JSFIDDLE
There are lots of ways to do this. But quickest one is adding a max value to yAxis with using yAxis.max.
yAxis: {
allowDecimals: false,
max: 6000
},
Here is the working example: jsFiddle.
OR
You can use the combination of yAxis.tickAmount and yAxis.tickInterval like this;
yAxis: {
allowDecimals: false,
tickAmount: 10,
tickInterval: 1000
},
Here is the working example: jsFiddle.
Besides setting a new max property or trying a different combination of ticks, you can simply set overflow property with 'none' value and crop with false. This way you can display data labels outside the plot area.
API Reference:
http://api.highcharts.com/highcharts/plotOptions.series.dataLabels.overflow
http://api.highcharts.com/highcharts/plotOptions.series.dataLabels.crop
Example:
http://jsfiddle.net/2qtpx0rL/

In HighStock, linking secondary yAxis to master yAxis can cause secondary values to be cropped outside the chart

Simplifying my story, consider 2 series where I link their yAxes. In other words on the second yAxis there is a property linkedTo: 0
So the first yAxis is the master, hence sets extremes for both series.
However sometimes the second series has high values which are too high to be plotted in the visible area and so they get cropped.
To make matters worse, when the yAxes are linked to each other, the legend doesn't play ball: clicking on the master series name in the legend will hide both series. Clicking on the secondary series name will hide none.
Check out this JSFiddle - values on the right are cropped, legend functionality is broken.
What am I missing? How can I get both series to scale together and be all visible? How do I get the legend to work as expected? (click on series name should toggle it)
Thanks!
EDIT: As it turns out, if I remove yAxis.id (JSFiddle here) the chart and legend work as expected. However linking series to yAxis based on position in the array (I think?) instead of by some ID (string) sounds less than ideal.
Ideas?
Why you are trying assigning second series to axis which is just copy of proper one? I advice to set both series to master yAxis, and second yAxis use just as extra info on the right side of a chart.
Otherwise I don't understand the purpose of linking second axis to get THE SAME extremes as master yAxis, and then expecting to scale that yAxis according to series you have attached to that yAxis.
Something like this I think is better approach, see: http://jsfiddle.net/zYpcm/15/
series: [{
name: 'master',
data: self.masterData,
yAxis: 'master'
}, {
name: 'secondary',
data: self.secondaryData,
//yAxis: 'secondary'
}],
yAxis: [{
id: 'master'
}, {
id: 'secondary',
opposite: true,
linkedTo: 0
}]

How to increase spacing between sideway bar charts in highcharts?

I am trying to increase the space between charts in this link however i have used minPadding/maxPadding in xAxis and pointWidth: 90/pointPadding: 0 but nothing works. It seems to me that there is forced spacing at the top and bottom of the chart area which is causing this.
http://jsfiddle.net/j7NMC/2/
/*What i have tried */
series:{
pointWidth: 90,
pointPadding: 0
}
xAxis: {minPadding:0, maxPadding:0,}
Any ideas?
Thank you :)
I would suggest changing your data setup. Instead of 3 different series, use 1 series and 3 categories:
series: [{
data: [973,133,107]
}]
example: http://jsfiddle.net/j7NMC/4/
What this does for you:
1) eliminates that wasted space on the chart
2) eliminates need for legend by putting the labels right on the axis next to the bar (drastically improves usability of chart, makes comprehension much easier for user)
3) eliminates need for multiple colors for the bars (drastically improves usability of chart, makes comprehension much easier for user)
EDIT:{
you can try setting the groupPadding to 0 to remove some of the space, as the the 3 series you have displayed are grouped, and extra space is being added because of that.
The options need to be in the 'bar' section of plotOptions, and you don't need a series entry in plotOptions i.e. like this:
plotOptions: {
bar: {
dataLabels: {
enabled: true
},
pointWidth: 10,
pointPadding: 0
}
},
http://jsfiddle.net/A8dpf/

Highcharts columnrange with strange height/width for columns

I'm trying to create a column chart (Highcharts) with a fixed width (range) for all the columns. I have around 300 columns, and I want to draw them actually as lines, and that's why I assign a very small range (0.001) for each of them.
The data format is basically like this: [numberId, min, max].
However, sometimes the height is shown correctly... but some other times it appears with strange height, not even the same for all the columns. I have tried many different things but I didn't manage to find the problem.
This is the jfiddle http://jsfiddle.net/deSSf/3/ (if you resize the area for the chart you will probably see the effect). The fiddle is actually using HighStock, but this chart should be from highcharts lib.
I have screenshos but can't post them.
The code is very simple:
chart: {
renderTo: 'container',
type: 'columnrange',
},
series: [{
data: [[1,0,0.001],......]]
}
There is huge difference between Highcharts and Highstock. In Highstock you have access to dataGrouping which collects data and groups when there is to many points to display on a chart.
Disable it to have working example: http://jsfiddle.net/deSSf/4/
dataGrouping: {
enabled: false
}

Resources