Increasing padding in plotly pie chart hoverlabel - javascript - javascript

I'm trying to increase the padding of the hoverlabel property for pie charts using below method but seems not working. Has anyone tried this use case or is there any other way to do it..
hoverlabel: {
bgcolor: 'white',
bordercolor: '#e7e7e7',
font: {
color: 'black',
},
padding: {
t: '20',
b: '50',
l: '0',
r: '0'
},
borderwidth: 2
}

You can use CSS to expand the legend box, and then move the hover elements.
.legend .bg {
rx: 10px;
transform: scale(1.2, 1.2);
}
.legend .scrollbox {
transform: translate(10px, 7px);
}
Not a perfect solution but it works.

Plotly Pie Chart does not support padding property in hoverlabel
Reference - https://plotly.com/javascript/reference/#pie-hoverlabel
However you can customize your hover label by using hovertemplate property
https://plotly.com/javascript/hover-text-and-formatting/

Related

web animations api, resetting 1st animation at end of chain

I'm experimenting with the web animations API for the first time, and trying to chain some values together. I'm a little confused as for this simple animation, where it will translate 200px along the X axis, then 200px down along the Y axis once the first animation is complete.
However, at the end of the animation, it resets the X value of the initial animation. I've tried playing around with 'both' | 'forwards' for the fill mode property, as well as setting translateX to 0/200 in the second transform declaration. Feel like I'm missing something quite simple here.
const box = document.getElementById('box');
const animateRight = box.animate(
[{ transform: 'translateX(0)' }, { transform: 'translateX(200px)' }],
{
fill: 'forwards',
easing: 'ease-in-out',
duration: 2000,
}
);
animateRight.finished.then(() => {
box.animate([{ transform: 'translateY(0)' }, { transform: 'translateY(100px)' }], {
composite: 'add',
fill: 'both',
duration: 1500,
});
});
#box {
width: 100px;
height: 100px;
border: 1px solid black;
}
<div id="box"></div>

Chartist: remove all grid lines but display axis

I know there is an option to remove gridlines: showGrid: false. But that will remove all grid lines including main axes.
Is there a way to remove all gridlines except main axis like this?
It is possible to achieve that with pure css:
.ct-vertical ~ .ct-vertical {
stroke: none;
}
.ct-horizontal ~ .ct-horizontal {
stroke: none;
}

Change the font color of drillUpButton text

I wonder how to change the font color of drillUpButton text. I tried css to extract the element like: g.highcharts-button highcharts-drillup-button highcharts-button-normal text{color: blue;} However it doesn't work.
Button Picture
The drillUpButton API only provide how to change the theme of the button itself but has nothing to do with the text.
drillUpButton: {
relativeTo: 'spacingBox',
position: {
y: 10,
x: 0
},
theme: {
color: "#5ab7f5",
fill: 'white',
'stroke-width': 2,
stroke: '#5ab7f5',
r: 5,
states: {
hover: {
color: 'white',
fill: '#5ab7f5'
},
select: {
fill: '#5ab7f5'
}
}
}
},
Here is the link for reference
If someone wants to avoid using CSS selectors, you can add CSS style to text button using style property.
theme: {
style: { color: "red" },
...
}
Use this selector:
.highcharts-button-box+text {
fill: red !important;
}
Example:
http://jsfiddle.net/vwdfceLz/
You didn't quite go far enough to tspan and you're using color instead of fill. You were also missing a couple "." when selecting the class.
Creating this rule seems to work
g.highcharts-button.highcharts-drillup-button text tspan{
fill: blue;
}
If you don't want to type all of that out .highcharts-drillup-button text tspan should work as well.
DEMO
You can change the color of the text by using the highchart drillup button css styling class to apply the color to the text. The reason why simple color:red property on it wont work because it is a svg created on the run and svg also sets the fill property for the text as well which overwrites the color. On top of that you need to force your custom class colors by using the !important keyword for each property set. So just add the following class in your custom css and you drillup button text will change.
.highcharts-drillup-button text{
color: red !important;
fill: red !important;
}
Hope this helps.

Hiding an object using css

I am trying to hide a vertical bar I have created in a jQuery Flot graph when the mouse is not within the bounds of the grid. I set me horizontal bounds for the grid as such: horizontalBounds = [leftOffset, plot.width() + leftOffset];. I then used an if statement to say "if the mouse is within the vertical bounds, do this to the verticalBar.css."
if (position.pageX >= horizontalBounds[0] && position.pageX <= horizontalBounds[1]) {
if (typeof verticalBar !== "undefined" && verticalBar !== null) {
verticalBar.css({
transform: "translate(" + position.pageX + "px, 0px)"
});
}
Below is my css code (which is actually in my javascript file; don't ask...). What do I need to do to hide the verticalBar when the mouse is not within those horizontal bounds? I was thinking I could just add the attribute `visibility: hidden' to the verticalBar.css, but I can't figure out how to do that. Any hints?
verticalBar.css({
backgroundColor: "#F7E4E6",
width: "1px",
height: "100%",
position: "absolute",
padding: 0,
margin: 0,
left: 0,
transform: "translateX(" + plot.getPlotOffset().left + "px)"
});
}
try using "display:none;" in your CSS.
Depending on how you're wanting to hide the bar, you can have something as simple as display: none.
If you're wanting to add in some animations, you could use some jQuery functions to control that particular node.
You could also utilize a set of CSS class name swaps to trigger some CSS animations.
so none of those methods seemed to work for me. I ended up discovering that Flot has a crosshair plugin (flot.crosshair). The crosshair can be configured to act only on the x axis/ x coordinate as it tracks the movement of the mouse. Here is an example of the crosshair tracking in action: Flot Tracking Example.
Once the plugin was added, I was able to get the desired results; as the "vertical bar" only shows up when the cursor is on the grid. Below is really all you need to do to configure it (other than adding the plugin to the appropriate files). Hope this helps someone in the future.
plot = $.plot(
placeholder
data
grid:
clickable: true
hoverable: true
color: "white"
mouseActiveRadius: 1000
tooltip:
show: true
content: '%y'
crosshair:
mode: "x"
color: "#FFFFFF"
lineWidth: 1

Add border to doughnut chart with Chartist.js

I'm using Chartist.js in order to create a few doughnut charts. So far it's been pretty straightforward and easy to use, but I've been trying to create a border around the shapes for the last three hours (needless to say I'm unable to use the SVG stroke property since the plugin itself uses the stroke to create the donut effect).
Is there an in-plugin option to give the chart a border?
The way I'm creating the doughnut is really simple:
new Chartist.Pie('.donut-chart', {
series: [37.47, 62.53],
}, {
donut: true,
donutWidth: 8,
startAngle: 0,
total: 100,
showLabel: false
});
Of course any kind of help will be much appreciated!
EDIT: I've also tried using cdcarson's fork of the plugin (Pull request pending at https://github.com/gionkunz/chartist-js/pull/330) to generate the chart using filled shapes instead of strokes, but something seems to be broken
I "solved" it using a pie chart instead of a doughnut one, and adding strokes to the shapes. After that I created a function to append a cover for the fill:
function hideFillOfPie() {
$('.donut-chart').append('<div class="cover-fill"></div>');
var size = $('.donut-chart-holder').width();
$('.cover-fill').css({
'height' : size - 30 + 'px',
'width' : size - 30 + 'px'
});
}
$(document).ready(function() {
hideFillOfPie();
});
The parent of the chart must have set
position: relative;
And the CSS for the cover of the fill looks like this:
.cover-fill {
position: absolute;
top: 50%;
left: 50%;
right: auto;
bottom: auto;
background-color: white;
border-radius: 50%;
-webkit-transform: translate3d(-50%,-50%,0);
transform: translate3d(-50%,-50%,0);
z-index: 1;
}

Categories

Resources