high charts - lost animation when pie chart sliced is programmatically set - javascript

As you can see from this basic example, http://www.highcharts.com/demo/pie-basic
when you select a pie, the selected pie got pulled out slowly with animation.
and that is handled by this option.
pie: {
allowPointSelect: true
}
However, I don't want mouse click to select Point. I have, say, a button outside of the pie chart, when I press the button, the first pie/Point should be selected.
I have the following
$scope.SAWChartConfig.series[0].data[0].selected = true;
$scope.SAWChartConfig.series[0].data[0].sliced = true;
programatically set the first point as selected when button clicked. It works fine, but it lost the animation (where it should slowly pull outward).
My questions are:
how can i add the animation back?
series[0].data contains a few data points, I would need to reset data[i].sliced to false for each of them after button is clicked. Is there a easy way to do it instead of loop through all items?
.controller('spendingPieChartCtrl', ['$scope', '$q',
'TransactionService', 'CategoryService','chartColors', function
($scope, $q, TransactionSvc, CategorySvc, chartColors) {
if(typeof $scope.height === 'undefined') {
$scope.height = 140;
}
$scope.SAWChartConfig = {
options: {
chart: {
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false,
type: 'pie',
margin: [0, 0, 0, 0],
spacingTop: 0,
spacingBottom: 0,
spacingLeft: 0,
spacingRight: 0,
height: $scope.height
},
plotOptions: {
pie: {
dataLabels: {
enabled: false
},
size: '100%',
borderWidth: 0
},
series: {
states: {
hover: {
enabled: false
}
}
}
},
title:{
text: null
},
tooltip: {
enabled: false
}
},
series: [{
data: []
}]
};
$q.all([
TransactionSvc.get(),
CategorySvc.get()
]).then(function() {
var spendingCategories = TransactionSvc.getTopCategories();
//redraw the chart by updating series data
$scope.SAWChartConfig.series = [{data: spendingCategories}];
});
$scope.$on('talkToOne', function( event, data ){
$scope.SAWChartConfig.series[0].data[index].select();
//$scope.SAWChartConfig.series[0].data[index].sliced = true;
});
I am using ng-hightcharts, and here is the directive call

chart.series[0].data[index].select() will do the select/deselect of the slices without loosing animation.
See the working example here
By using above code your second problem will also get fixed, since the next select call will automatically deselect other selected slices in the chart.

Related

Customize Stacked column chart in highChart

I am trying to customize stacked column chart like this
Here i did all the remaining things but i Don't know how to give that bar lines above every column........I need that bar lines in both positive and negative axis
My code
$(document).ready(function () {
$('#div1').highcharts({
chart: { type: 'column', backgroundColor: 'transparent' },
title: { text: null },
subtitle: { text: null },
credits: {
enabled: false
},
xAxis: {
categories: categories,
labels: {
rotation: 0,
style: {
fontWeight: 'normal',
fontSize: '0.9vw',
fontFamily: 'Verdana, sans-serif',
color: "black"
}
}
},
yAxis: {
title: {
enabled: false
},
lineWidth: 0,
gridLineWidth: 1,
labels: {
enabled: true
},
// gridLineColor: 'transparent',
plotLines: [{
color: '#ddd',
width: 1,
value: 0
}],
},
plotOptions: {
series: {
stacking: 'normal'
}
},
series:seriesforSeniorUPT
});
});
});
Link
Fiddle
To elaborate on Sebastian Bochan's helpful comment, here's an updated version of your fiddle with two "dummy" series to serve as the patterned background: https://jsfiddle.net/brightmatrix/hc8rLy18/2/
A few items to note:
There are two "dummy" series: one for the positive numbers and one for the negative numbers.
Both series have showInLegend and enableMouseTracking set to false so the user cannot interact with them.
Both series have stacking set to false so they will not be part of the "real" data you want to show.
Both series have zIndex set to 0. I explain why below the code block.
The code for the "dummy" series is as follows.
// background for positive values
obj = {};
obj["name"] = 'patternFill';
obj["data"] = [120, 120];
obj["color"] = 'url(#highcharts-default-pattern-3)';
obj["grouping"] = false;
obj["zIndex"] = 0;
obj["enableMouseTracking"] = false;
obj["stacking"] = false;
obj["showInLegend"] = false;
seriesforSeniorUPT.push(obj);
// background for negative values
obj = {};
obj["name"] = 'patternFill';
obj["data"] = [-80, -80];
obj["color"] = 'url(#highcharts-default-pattern-3)';
obj["grouping"] = false;
obj["zIndex"] = 0;
obj["enableMouseTracking"] = false;
obj["stacking"] = false;
obj["showInLegend"] = false;
seriesforSeniorUPT.push(obj);
For the three "real" data series, I set zIndex to 10 to they will appear over the "dummy" series we're using for our patterend backgrounds.
For all of the series, I set grouping to false so they will appear one atop the other, not next to one another.
Here's a screenshot of the output. I hope this is helpful!

Adding buttons in qualtrics

I have inserted a highchart graph in qualtrics for a question I wanted to ask. Respondents answer the question by dragging the line.
I wanted to add a button to reset the values of the line to the initial values I showed them as default, or to show them specific values.
Here are the html elements of the question
<div id="container" style="height: 400px"> </div>
<button id="button">Set new data</button>
Whereas here is the js
Qualtrics.SurveyEngine.addOnload(function()
{
var chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
animation: false
},
legend: {
enabled: false
},
xAxis: {
categories: ['1', '2', '3']
},
yAxis: {
min: -2,
max: 10,
tickInterval: 2,
lineWidth: 1,
title: {
text: '\% points'
},
},
plotOptions: {
series: {
point: {
events: {
drag: function (e) {
// Returning false stops the drag and drops. Example:
/*
if (e.newY > 300) {
this.y = 300;
return false;
}
*/
j('#drag').html(''
'Dragging <b>' + this.category + '</b> to <b>' + Highcharts.numberFormat(e.y,2) + '\% </b>');
},
drop: function () {
j('#drop').html(''
this.category + '</b> was set to <b>' + Highcharts.numberFormat((Math.ceil(this.y*20)/20),2) + '\% </b>');
}
}
},
tooltip: {
valueDecimals:2
},
stickyTracking: true,
getExtremesFromAll: true,
marker: {
radius: 6
}
},
/* line: {
cursor: 'ns-resize'
}*/
},
tooltip: {
yDecimals: 2
},
series: [{
data: [0, 0, 0],
dragMinY:-2,
dragMaxY:10,
draggableY: true,
cursor: 'ns-resize'
}],
});
j('#button1').click(function () {
chart.series[0].setData([5, 6, 2] );
});
j('#button2').click(function () {
chart.series[0].setData([0, 0, 0]);
});
});
(Notice that, since Jquery(preloaded in the header) conflicts with prototype I reset the $ to j to prevent conflicts).
Now, the buttons should work, they should do what they are meant to, but something is odd: if I click on the graph to drag the line, the first button is automatically clicked, and I do not understand why. If I click the second both are clicked. What's worst, every time I click the page reloads. This is specific to Qualtrics only, I tried to implement this in jfiddle (https://jsfiddle.net/tg35u440/) and everything seemed to be fine.
So, do you know what I actually have to do to prevent qualtrics from reloading the oage everytime a button is clicked on? And why are the buttons creating a conflict with the dragging function on screen in Qualtrics?
Thank you very much!

Display points with minimum number in HighChart

In Highchart I want to set the number of plot points that are to be shown in the dynamic graph.
For example, if I set the number to 10, only 10 points in the dynamic series will be shown.
I have implemented another graph and it shows only 6 points but I want to display at least 10 points.
JsFiddle
$(function () {
var chart;
$(document).ready(function () {
chachart = new Highcharts.Chart({
chart: {
renderTo: "container",
type: "spline",
zoomType: 'x'
},
title: {
text: 'Inverter ~ AC Currents'
},
subtitle: {
text: 'Click and drag in the plot area to zoom in'
},
plotOptions: {
spline: {
turboThreshold: 2000,
lineWidth: 2,
states: {
hover: {
enabled: true,
lineWidth: 3
}
},
marker: {
enabled: false,
states: {
hover: {
enabled: true,
radius: 5,
lineWidth: 1
}
}
}
}
},
In the link above, I do not see any line that defines the limit for the number of points.
This is how addPoint in your example works, see docs.
So third param (shift) is responsible for removing first point in series. Just add checking if number of points == 10, and then set it to true to remove point.

Highstock Column Chart - data grouping causes data to scroll independently of axis

I am attempting to make a stacked column chart representing events on a timeline. I need evenly-spaced bars, that scroll left/right with their respective ticks. Currently upon scrolling, the columns remain in place and their data is updated to reflect the new timespan they represent (I assume).
For example: when scrolling one "step" to the right, I note these differences:
The column remains in place with updated data and the axis tick moves to the left. This results in a 'graphic equalizer'-like effect when scrolling. (See fiddle)
What I need is to have the column represent the same data for the life of the chart, and to scroll left/right with its tick mark.
I suspect I'm misunderstanding something in the configuration. Any help/direction would be very much appreciated.
(As a side note: is there any easy way to style/color data from the past (with an xAxis datetime value of < today) differently to normal data?)
chart: {
alignTicks: false,
backgroundColor: '#eeeeee',
events: {
load: function (e) {
this.xAxis[0].setExtremes(1390943153305, 1400015153305);
}
},
ignoreHiddenSeries: true,
renderTo: $('#chart')[0]
},
colors: ['#89f1a4','#68d9f7','#9eb9ef','#c49eef'],
credits: {enabled: false},
legend: {
enabled: true,
shadow: true
},
rangeSelector: {selected: 1},
title: {text: 'Global Events'},
navigator: {
height: 40,
xAxis: {
gridLineWidth: 1
},
series: {type: 'column'}
},
plotOptions: {
series: {
showInLegend: true,
stacking: 'normal',
dataGrouping: {
enabled: true,
forced: true,
units: [
['millisecond', [604800000]], // Attempting to force data into weekly groups, throws error if this is null
['second', [604800]],
['minute', [10080]],
['hour', [168]],
['day', [7]],
['week', [1]], // Expected this to be the only required option if I only want weekly grouping...
['month', null],
['year', null]
]
}
}
},
xAxis: {ordinal: false},
series: data
If you want just weekly grouping, then only that one set, see: http://jsfiddle.net/s6BmC/2/
I think that resolves your issue, right?
plotOptions: {
series: {
showInLegend: true,
stacking: 'normal',
dataGrouping: {
enabled: true,
forced: true,
units: [ [ 'week', [1] ]]
}
}
},
Regarding additional question:
- yes you can set specific color for each point, but you need to determine on your own what color should be set:
data: [{ x: timestamp, y: value, color: color }, { x: timestamp, y: value, color: color }... ]
Another solution is to wrap setting color for column. Something similar I have done for candlestick: http://jsfiddle.net/79WZM/ (this solution requires much more knowledge of Highcharts).

Disable hover on HighCharts

I have building a pie chart using HighCharts library, and here is my chart:
// http://jsfiddle.net/t2MxW/20890/
var chart = new Highcharts.Chart({
colors: ['#0072BC', '#BFDAFF', '#DDDF00', '#24CBE5', '#64E572', '#FF9655', '#FFF263', '#6AF9C4'],
credits: { enabled: false },
chart: {
renderTo: 'container',
backgroundColor: 'rgba(255, 255, 255, 0.1)',
type: 'pie',
margin: [0, 0, 0, 0],
spacingTop: 0,
spacingBottom: 0,
spacingLeft: 0,
spacingRight: 0
},
title: { text: null },
plotOptions: {
pie: {
allowPointSelect: false,
size: '100%',
dataLabels: { enabled: false }
}
},
series: [{
showInLegend: false,
type: 'pie',
name: 'Pie Chart',
data: [
['Mobile', 65], // first half of pie
['Other', 35] // second half of pie
]
}]
});
But the problem is that I don't want appearing tooltip on mouse over...
Is it possible to disable tooltip on hover?
Disabling tooltip just disables the tooltip but the hover effect is still present. To disable the hover effect, add the following to your plotOptions:
plotOptions: {
series: {
states: {
hover: {
enabled: false
}
}
}
},
You need to set the tooltip attribute to false, like so:
tooltip: { enabled: false },
jsFiddle here
Here's the full code for your case:
var chart = new Highcharts.Chart({
colors: ['#0072BC', '#BFDAFF', '#DDDF00', '#24CBE5', '#64E572', '#FF9655', '#FFF263', '#6AF9C4'],
credits: { enabled: false },
tooltip: { enabled: false },
chart: {
renderTo: 'container',
backgroundColor: 'rgba(255, 255, 255, 0.1)',
type: 'pie',
margin: [0, 0, 0, 0],
spacingTop: 0,
spacingBottom: 0,
spacingLeft: 0,
spacingRight: 0
},
title: { text: null },
plotOptions: {
pie: {
allowPointSelect: false,
size: '100%',
dataLabels: { enabled: false }
}
},
series: [{
showInLegend: false,
type: 'pie',
name: 'Pie Chart',
data: [
['Mobile', 65], // first half of pie
['Other', 35] // second half of pie
]
}]
});
You might alternatively want to disable all mouse tracking in general, both tooltip and hover effects:
(copy and paste link) http://api.highcharts.com/highcharts#series.enableMouseTracking
http://jsfiddle.net/gh/get/jquery/1.7.2/highslide-software/highcharts.com/tree/master/samples/highcharts/plotoptions/series-enablemousetracking-false/
plotOptions: {
series: {
enableMouseTracking: false
}
}
The title of the question is about disabling hovering, so in case anyone else finds themselves here for that purpose, I'll elaborate on #SergeyB's answer.
There are a few options that affect how mouse hovering changes a series' styling. They each have different effects depending on the series type. I'll talk about line and pie series here, but generally, you can look under plotOptions.<seriesType>.states.hover for styling applied to the currently hovered series and plotOptions.<seriesType>.states.inactive for styling applied to the non-hovered series (e.g. plotOptions.pie.states.hover). None of these options affect the tooltip styling.
plotOptions.series.states.inactive
plotOptions.series.states.inactive affects the styling applied to all series that aren't currently being hovered over. To prevent them from fading into the background, set plotOptions.series.states.inactive.opacity to 1.
var chartOptions = {
// ...
plotOptions: {
series: {
states: {
inactive: {
opacity: 1,
},
},
},
},
}
jsFiddle for line
jsFiddle for pie
plotOptions.series.states.hover
plotOptions.series.states.hover affects the styling applied to the series that's being hovered over. For example, for a line series, the default is to thicken the line width and apply a halo to the nearest point.
To disable any styling of a currently hovered line series, set plotOptions.series.states.hover.enabled to false.
var chartOptions = {
// ...
chart: {
type: "line",
},
plotOptions: {
series: {
states: {
hover: {
enabled: false,
},
},
},
},
}
jsFiddle
Unfortunately, if we set this on a pie series, this will make the hovered slice fade into the background with the rest of the inactive slices (see this jsFiddle for an example). If we want to remove all hover styling without affecting the inactive styling, we can set plotOptions.series.states.hover.halo.size to 0 (which removes the halo) and plotOptions.pie.states.hover.brightness to 0 (which removes the brightening effect). Note that since brightness is specific to pie series, it's documented under plotOptions.pie instead of plotOptions.series (though it worked for me even when I added it under plotOptions.series).
var chartOptions = {
// ...
chart: {
type: "pie",
},
plotOptions: {
series: {
states: {
hover: {
halo: {
size: 0,
},
// this worked for me even though it's not
// documented under plotOptions.series:
//brightness: 0,
},
},
},
pie: {
states: {
hover: {
brightness: 0,
},
},
},
},
}
jsFiddle
plotOptions.series.stickyTracking
If you're using a line or area series, you may have noticed that as soon as you hover over the chart, even if you're not touching a series, the nearest series will receive hover styling and the rest will receive inactive styling. This is because plotOptions.series.stickyTracking is true by default for line and area series. If you set plotOptions.series.stickyTracking to false, hover and inactive styling will only be applied while you're hovering over a line.
var chartOptions = {
// ...
chart: {
type: "line",
},
plotOptions: {
series: {
stickyTracking: false,
},
},
}
jsFiddle
plotOptions.series.enableMouseTracking
As #ninedozen noted, you can completely disable all responsive interactions based on mouse movement by setting plotOptions.series.enableMouseTracking to false. Note that this will also disable tooltips in addition to hover/inactive styling.
Options scope
To apply these options to all series in the entire chart, place them under plotOptions.series. To apply them only to certain series types (or if the option is specific to a certain series), place them under plotOptions.<seriesType>. To apply them to a specific series, place them inside that series' options.
var chartOptions = {
series: [
{
name: "series1",
type: "line",
data: [...],
// these options will only apply to series1, not series2 or series3
states: {...},
},
{
name: "series2",
type: "line"
data: [...],
},
{
name: "series3",
type: "pie"
data: [...],
}
],
plotOptions: {
// these options will apply to all series in the chart
series: {states: {...}},
// these options will only apply to series of type line
// i.e. series1 and series2
line: {states: {...}}
}
}
You can simply turn them of using the following:
tooltip: {
enabled: false
},
plotOptions: {
series: {
states: {
inactive: {
opacity: 1,
},
},
}
}
I did this to display multiple line charts on hover.
In order to completely turn off tooltip and hover effects on a chart,
it is needed to turn off the tooltip, disable hover state and set inactive data opacity to 100%.
This answer is based on previous answers and shows a complete solution to the problem.
This is the configuration which turns off the hover and tooltip effects:
series: {
states: {
hover: {
enabled: false
},
inactive: {
opacity: 1,
}
}
},
tooltip: {
enabled: false
}
you can simply disable it by setting the option
tooltip:{
enabled: false
}
I usually just disable the style in css so I can still access the hover event in JS if needed...
.highcharts-tooltip {
display: none;
}
As specified in the accepted answer, you need to set
tooltip: { enabled: false }
Note - you must specify this as a property of your Highcharts.Options object (i.e. your chart options object, not a property of your series). So, either specify it in the JSON that you pass into your Highcharts.Chart object, or specify it as a property of a Highcharts.Options object that you explicitly create, before you pass it to you Highcharts.Chart
See https://api.highcharts.com/highcharts/tooltip.enabled

Categories