Can I lay two Highcharts series side-by-side? - highcharts

Looking at this example: http://www.highcharts.com/stock/demo/candlestick-and-volume
Is there a way that I can lay these two series side-by-side rather than stacked on top?

You can use axis.width and axis.left. You will not find them in axis official API, so you may encounter some issues with it, e.g. problem with a tooltip - issue on github.
The basic config for using two x axis next to each other:
xAxis: [{
width: 200,
left: 50
}, {
width: 200,
left: 300,
linkedTo: 0,
offset: 0
}],
Workaround for a tooltip position (shared tooltip does not seem to work correctly)
tooltip: {
shared: false,
shape: 'rect',
positioner: function(w, h, p) {
return {
x: p.plotX + this.chart.hoverSeries.xAxis.left - w / 2,
y: p.plotY
}
}
},
example: http://jsfiddle.net/fqc5np5g/

Related

How to increase and decrease the height of the gridlines in advanced accessible highcharts

I am using advanced accessible high charts and I need to be able to increase and decrease the height of gridlines based on the data points for a particular series. If the data points for a particular series is less than 10 I want the height of the gridline to be 30 px else if the data points is between 10 and 15 I want the height to be 50px if the data points are more than 20 i will need the gridline height to be 100px
The only solution that came to my mind is to attach each series into an independent axis which allows setting each axis height (in percentage or pixel value).
xAxis: [{
height: '30%',
}, {
height: '60%',
top: '30%',
offset: 0
}, {
top: '80%',
height: '10%',
offset: 0
}],
series: [{
data: [2, 3, 4],
xAxis: 0
}, {
data: [10, 12],
xAxis: 1
}, {
data: [10, 12],
xAxis: 2
}]
Demo: https://jsfiddle.net/BlackLabel/8pu13s7d/
API: https://api.highcharts.com/highcharts/yAxis.height
API: https://api.highcharts.com/highcharts/yAxis.top

How can i add a html tag "sup" and "sub" in a text shape when i use Konva.Text?

KonvaJS is a excellent canvas plugin,it's easy to use ,a lot of demos,and detailed api document.
But i have a problem about Konva.Text, When I want to display fraction number like "7/8",it's show as a plain text <sup>7</sup>/<sub>8</sub> , how can i do?
As far as I know fabric has analogous method called setSuperscript and setSubscript, can our Konva.Text be achieved?
I suggest to draw it manually with three shapes:
function createFraction(sup, sub) {
const group = new Konva.Group();
group.add(new Konva.Text({
align: 'right',
width: 100,
x: -100,
text: sup
}));
group.add(new Konva.Text({
text: sub,
y: 13,
x: 2
}));
group.add(new Konva.Line({
stroke: 'black',
strokeWidth: 1,
points: [5, 4, -5, 20],
text: sub,
}));
return group;
}
const fraction = createFraction('7', '8');
fraction.position({ x: 50, y: 50});
layer.add(fraction);
https://jsbin.com/vahavimowa/edit?html,js,output

Highcharts percentage without stacking?

Is it possible to create a Highcharts chart with splines in percentages, but WITHOUT them stacking?
I would like to display lines in a relative view, but I would like them to be crossing when their percentages changes.
Basically, like this: http://jsfiddle.net/dp6pjeo9/5/
plotOptions: {
series: {
pointStart: 2010,
stacking: 'percent'
}
},
but without the lines 'stacking' behavior. Stacking is really inconvenient for lines because it is hard to tell whether they are 'absolute' values or 'stacked' values.
See here, the top line should be under then the black line in 2010.
You need to process you data before you put them in the chart config.
Calculate sums:
var data = [3, 5, 10, 15,25]
var data2 = [25,15, 10, 5, 0]
var sum = data.map((v, i) => v + data2[i]) // grab sums
Calculate percentages and set data:
series: [{
name: 'Installation',
data: data.map((v, i) => ({
y: v / sum[i] * 100,
absoluteY: v
}))
}, {
name: 'Manufacturing',
data: data2.map((v, i) => ({
y: v / sum[i] * 100,
absoluteY: v
}))
}]
Change tooltip's pointFormat so it shows absolute y value instead of percentage value
tooltip: {
pointFormat: '<span style="color:{point.color}">\u25CF</span> {series.name}: <b>{point.absoluteY}</b><br/>'
},
example: http://jsfiddle.net/dp6pjeo9/6/

Using hours and minutes as data in highcharts donut chart

I got a donut chart and want to display hours and minutes. Using highcharts pie chart with constant visible drilldown data this leads me to a big problem, please see the picture first:
The inner blue slice has the value 10.40, which stands for 10:40 as a time. The two outer slices have the values 5.50 and 4.50, which, summed up as hours and minutes, results in 10.40, but highcharts doesn't know it's a time format, so it sums that up as 10.00 which perfectly shows my problem.
I tried setting the yAxis type to datetime
type: 'datetime',
which does not change anything so far. I found other entries like Pass time values to Highcharts Column chart, which sadly left me clueless.
Did I miss something? Glad for any help.
An minimal example solution, using millisecond values to only display hours and minutes (JSFiddle):
var m = 1000 * 60;
var h = m * 60;
$('#container').highcharts({
chart: {
type: 'pie'
},
tooltip: {
formatter: function() {
return '<b>' + this.series.name +'</b><br/>' +
Highcharts.dateFormat('%H:%M', new Date(this.y));
}
},
series: [{
name: 'Inner',
data: [
{ name: 'A', y: (10 * h) + (40 * m), color: 'blue' },
{ name: 'B', y: (3 * h), color: 'red' },
],
size: '60%'
}, {
name: 'Outer',
data: [
{ name: 'A1', y: (5 * h) + (50 * m), color: 'blue' },
{ name: 'A2', y: (4 * h) + (50 * m), color: 'blue' },
{ name: 'B1', y: (3 * h), color: 'red' },
],
size: '100%',
innerSize: '60%'
}]
});
Here we just operate with time going from 0 and out. The tooltip is used to format the values in a readable format.
See this more elaborate JSFiddle demonstration using some of the pie-donut demo code to color the slices like your example picture.

Highcharts bubble chart dataLabels overlapping

As shown in the picture (which is not the same code as the fiddle, but exhibits the problem), with Highcharts new bubble charts it seems like dataLabels like to sit on top of each other. Is there an easy workaround for this? I'd be happy to manually change the z-index on a per label basis, but this doesn't seem to work for bubble charts. Here's some sample code that fails to work as expected (try it in a fiddle):
series: [{
data: [{
x: 99,
y: 36,
z: 50
}, {
x: 99,
y: 74,
z: 55,
dataLabels: {
zIndex:15,
enabled: true,
}
}, {
x: 99,
y: 76,
z: 55,
dataLabels: {
zIndex: 1,
enabled: true
}
}
]
}],
You can set useHTML: true flag, and then set z-index: x property for dataLabels, see: http://jsfiddle.net/ZLmU8/4/
Apparently there is a labelrank property on the Highcharts point objects that can be used to dictate which point labels are on top. It can be used when you're creating your data like this:
data: [{
x: 1, y: 1, labelrank: 1, name: 'A'
},{
x: 1, y: 1, labelrank: 2, name: 'B'
}]
Or it can be updated on an individual point to bring that point's dataLabel to the front by doing something like this: chart.series[0].points[0].update({labelrank: 3});
I had a similar issue and created this question on SO that just was answered.
Edit
They have added info regarding series.data.labelrank to their docs as well: http://api.highcharts.com/highcharts#series.data.labelrank

Resources