How to aligned symbol in highcharts js? - highcharts

Now it looks like this:
should be:
legend: {
floating: true,
align: 'left',
verticalAlign: 'top',
y: 0,
x: -20,
width: 150,
itemMarginTop: 12,
itemMarginBottom: 12,
alignItem: 'center',
textAlign: '40px',
itemStyle: {
fontFamily: 'Inter',
display: 'inline-block',
verticalAlign: 'middle'
},
labelFormatter() {
return `<span style="font-size: 14px;color: #595959;font-weight: 400;">${this.name}</span><br><span style="font-size: 18px;color: #1C1C1E;font-weight: 600;">${this.y}</span>`
} }

In style options for legend .highcharts-legend-item you can change position of item, there is no directly options in Highcharts for adjust symbol position related to label. In this solution, you need to use legend.useHTML to render legend items.
.highcharts-legend-item {
top: -10px !important;
}
Demo: https://jsfiddle.net/BlackLabel/6479m1y0/

Related

Use Material UI theme attributes for styling highcharts - React

I have been using Material ui themes for styled components in React. Now, We have a requirement in our application to use highcharts. But I still wanted to retain the same themeing for highcharts as well. Is there a way we could integrate Material UI theme to style highcharts chart? I did google this a lot before finally deciding to raise the question here. I know that highcharts provide their own theme. But I do not want to make the code messier with multiple themes. Is there a way to achieve this in a cleaner way? Any help would be much appreciated. Thanks in advance!
Highcharts have a possibility to set themes by Highcharts.setOptions to create schemate fit to you. That you can see there are specific sets for charts elements for that material UI it's not changing charts looks.
https://www.highcharts.com/docs/chart-design-and-style/themes#creating-your-own-theme
// set the theme
Highcharts.setOptions({
colors: ['#058DC7', '#50B432', '#ED561B', '#DDDF00', '#24CBE5', '#64E572', '#FF9655', '#FFF263', '#6AF9C4'],
chart: {
backgroundColor: {
linearGradient: [0, 0, 500, 500],
stops: [
[0, 'rgb(255, 255, 255)'],
[1, 'rgb(240, 240, 255)']
]
},
borderWidth: 2,
plotBackgroundColor: 'rgba(255, 255, 255, .9)',
plotShadow: true,
plotBorderWidth: 1
},
title: {
style: {
color: '#000',
font: 'bold 16px "Trebuchet MS", Verdana, sans-serif'
}
},
subtitle: {
style: {
color: '#666666',
font: 'bold 12px "Trebuchet MS", Verdana, sans-serif'
}
},
xAxis: {
gridLineWidth: 1,
lineColor: '#000',
tickColor: '#000',
labels: {
style: {
color: '#000',
font: '11px Trebuchet MS, Verdana, sans-serif'
}
},
title: {
style: {
color: '#333',
fontWeight: 'bold',
fontSize: '12px',
fontFamily: 'Trebuchet MS, Verdana, sans-serif'
}
}
},
yAxis: {
alternateGridColor: null,
minorTickInterval: 'auto',
lineColor: '#000',
lineWidth: 1,
tickWidth: 1,
tickColor: '#000',
labels: {
style: {
color: '#000',
font: '11px Trebuchet MS, Verdana, sans-serif'
}
},
title: {
style: {
color: '#333',
fontWeight: 'bold',
fontSize: '12px',
fontFamily: 'Trebuchet MS, Verdana, sans-serif'
}
}
},
legend: {
itemStyle: {
font: '9pt Trebuchet MS, Verdana, sans-serif',
color: 'black'
},
itemHoverStyle: {
color: '#039'
},
itemHiddenStyle: {
color: 'gray'
}
},
credits: {
style: {
right: '10px'
}
},
labels: {
style: {
color: '#99b'
}
}
});

what is the problem with my left alignment?

I use konva.js and I try to align texts with the align function but I can't do it with the left alignment (right and center works on the other hand)
my code
var text1 = new Konva.Text({
y: 26,
fontSize: 40,
text: 'ligne1',
draggable: true,
width : 550,
align: 'center',
});
layer.add(text1);
layer.draw();
Thank you
The text.align() method sets the alignment. In the snippet below I have drawn a rect around the text shape to give a visualisation of the effect.
let
// Set up a stage
stage = new Konva.Stage({
container: 'container',
width: window.innerWidth,
height: window.innerHeight
}),
layer = new Konva.Layer(),
rect = new Konva.Rect({
x: 0,
y: 26,
width: 550,
height: 40,
stroke: 'magenta'
}),
text1 = new Konva.Text({
y: 26,
fontSize: 40,
text: 'ligne1',
draggable: true,
width: 550,
align: 'center',
fill: 'cyan'
});
stage.add(layer);
layer.add(rect, text1);
layer.draw();
$('#left').on('click', function() {
text1.align('left');
layer.draw();
})
$('#center').on('click', function() {
text1.align('center');
layer.draw();
})
$('#right').on('click', function() {
text1.align('right');
layer.draw();
})
body {
margin: 10;
padding: 10;
overflow: hidden;
background-color: #f0f0f0;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://unpkg.com/konva#^3/konva.min.js"></script>
<p>Click a button to change alignment of the text.</p>
<button id='left'>Left</button>
<button id='center'>Center</button>
<button id='right'>Right</button>
<div id="container"></div>

Highcharts: stacked bar charts tooltip enable shared and keep display arrow

When I enable tooltip.shared = true, The arrow will disappear like screen shot.
tooltip: {
shared: true
},
I want to keep arrow just like tooltip.shared = false
tooltip: {
shared: false
},
DEMO in here http://jsfiddle.net/puff0211/5sbfztur/
Does anyone know to accomplish this?
Thank you!
You can prevent from skipping the tooltip anchor in case tooltip is shared by wrapping move function. More about wrapping can be here: https://www.highcharts.com/docs/extending-highcharts/extending-highcharts. Take a look at the example below.
DOCS Reference:
https://www.highcharts.com/docs/extending-highcharts/extending-highcharts
Example:
http://jsfiddle.net/u6d2bode/
You can use tooltip.formatter with some css to achieve nearly required behavior but not exactly same when shared: false .
$(document).ready(function() {
$('#container').highcharts({
chart: {
//type: 'column'
type: 'bar'
},
title: {
text: 'Stacked column chart'
},
xAxis: {
categories: ['Apples', 'Oranges', 'Pears', 'Grapes', 'Bananas']
},
yAxis: {
min: 0,
title: {
text: 'Total fruit consumption'
},
stackLabels: {
enabled: true,
style: {
fontWeight: 'bold',
color: (Highcharts.theme && Highcharts.theme.textColor) || 'gray'
}
}
},
legend: {
align: 'right',
x: -100,
verticalAlign: 'top',
y: 20,
floating: true,
backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColorSolid) || 'white',
borderColor: '#CCC',
borderWidth: 1,
shadow: false
},
tooltip: {
shared: true,
useHTML: true,
backgroundColor: null,
borderWidth: 0,
formatter: function() {
//console.log(this.points)
var points = this.points;
var pointsLength = points.length;
var tooltipMarkup = pointsLength ? '<div class="callout right" >' + points[0].key + '<br/>' : '';
var index;
var y_value;
for (index = 0; index < pointsLength; index += 1) {
y_value = (points[index].y);
tooltipMarkup += '<span style="color:' + points[index].series.color + '">\u25CF</span> ' + points[index].series.name + ': <b>' + y_value + ' </b><br/>';
}
return tooltipMarkup + '</div>';
},
/*//you can use bellow code to adjust position
positioner: function(boxWidth, boxHeight, point) {
return {x:point.plotX,y:point.plotY};
}*/
},
plotOptions: {
series: {
stacking: 'normal',
dataLabels: {
enabled: true,
color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white'
}
}
},
series: [{
name: 'John',
data: [5, 3, 4, 7, 2]
}, {
name: 'Jane',
data: [2, 2, 3, 2, 1]
}, {
name: 'Joe',
data: [3, 4, 4, 2, 5]
}]
});
});
div.callout {
background-color: rgba(247, 247, 247, 0.85);
background-image: -moz-linear-gradient(top, rgba(247, 247, 247, 0.85), rgba(247, 247, 247, 0.85));
position: relative;
color: #000;
padding: 5px;
border-radius: 3px;
box-shadow: 0px 0px 20px #444;
}
.callout::before {
content: "";
width: 0px;
height: 0px;
border: 0.8em solid transparent;
position: absolute;
}
.callout.right::before {
left: -20px;
top: 35%;
border-right: 10px solid rgba(247, 247, 247, 0.85);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<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: 400px; height: 400px; margin: 0 auto"></div>
Fiddle demo
tooltip formatter
tooltip: {
shared: true,
useHTML: true,
backgroundColor: null,
borderWidth: 0,
formatter: function() {
var points = this.points;
var pointsLength = points.length;
var tooltipMarkup = pointsLength ? '<div class="callout right" >' + points[0].key + '<br/>' : '';
var index;
var y_value;
for (index = 0; index < pointsLength; index += 1) {
y_value = (points[index].y);
tooltipMarkup += '<span style="color:' + points[index].series.color + '">\u25CF</span> ' + points[index].series.name + ': <b>' + y_value + ' </b><br/>';
}
return tooltipMarkup + '</div>';
},
css
div.callout {
background-color: rgba(247, 247, 247, 0.85);
background-image: -moz-linear-gradient(top, rgba(247, 247, 247, 0.85), rgba(247, 247, 247, 0.85));
position: relative;
color: #000;
padding: 5px;
border-radius: 3px;
box-shadow: 0px 0px 20px #444;
}
.callout::before {
content: "";
width: 0px;
height: 0px;
border: 0.8em solid transparent;
position: absolute;
}
.callout.right::before {
left: -20px;
top: 35%;
border-right: 10px solid rgba(247, 247, 247, 0.85);
}

React Native - ios - circle with border - circle background color spilling out of circle

I'm trying to create a circle with a white background in react native and i'm having an issue where the background color of the circle is seen on the outline of the border.
Check out this playground app:
https://rnplay.org/apps/TsQ-CA
If you look closely you can see that around the circle there's a thin black line. It's like the border isn't covering the entire background.
Here's the circle style:
circle: {
borderRadius: 40,
width: 80,
height: 80,
borderWidth: 5,
borderColor: 'white',
backgroundColor: 'black'
}
P.S. this only happens on iOS
Any ideas??
Thanks!
You can add different border color to a circle. try this
container: {
width: 60,
height: 60,
borderRadius: 60 / 2,
backgroundColor: 'red',
borderColor: 'black',
borderWidth: 3
}
This looks like a bug in React Native. You can work around it by using 2 circles:
class App extends React.Component {
render() {
return (
<View style={styles.container}>
<View style={styles.outerCircle}>
<View style={styles.innerCircle} />
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'white',
},
outerCircle: {
borderRadius: 40,
width: 80,
height: 80,
backgroundColor: 'white',
},
innerCircle: {
borderRadius: 35,
width: 70,
height: 70,
margin: 5,
backgroundColor: 'black'
},
});
Try setting style props as
{
overflow: 'hidden'
}
with your styling on View style.

Horizontal align of the legend. Highcharts

I am not able to do a proper horizontal align, what am I missing?.
legend: {
align: 'middle',
margin: 0,
verticalAlign: 'bottom',
y: 50,
symbolHeight: 20
},
http://jsfiddle.net/2Ajnn/
Align should be center when referred to horizontal placement and middle when referring to vertical.
http://api.highcharts.com/highcharts#legend.align
legend: {
align: 'center',
margin: 0,
verticalAlign: 'bottom',
y: 50,
symbolHeight: 20
},
Demo: http://jsfiddle.net/robschmuecker/2Ajnn/1/

Resources