Legend at least one should be active when user clicks in highchart - highcharts

I am trying to use line chart, where I am using data with line series.
For that purpose I am using the legend. When clicked the legend, the following value will be hidden, and when I click the last one it also gets hidden, in my scenario last value should not get hidden so that at least one should be active.
I have done this in pie chart series but I can't implement this in line chart why?
- [Js Fiddle Pie Chart Demo][1]
- [Js Fiddle Line Chart][2]

var points = this.chart.series
JSFiddle

Related

Google Sheets Pie Chart - Display Actual Value Below Label, not in pie chart?

I know I can get the actual value to show up in the pie chart, i.e. on the slice. However I want the percentage in the pie chart (which I can get to show up) since it is more likely to fit in a slice and the actual value underneath the label. However no matter what I do I can't get anything besides the respective percentage to show up underneath each slice's label. Help!
I understand that you want to change your pie graph hiding the percentage shown inside the pie slice. If that is your goal, then you only have to update one chart setting. Follow these steps:
Double left click on the chart. The chart editor sidebar will open.
Click on the Customise tab.
Open the Pie chart submenu.
Update the Slice label property from Percentage to None.

Highchart Scatter plot with 2 series, tooltip refresh command giving error

I have 1 chart with 2 scatterplot series like so
The series have same data points, basically I am drawing 2-2D plots instead of 1-3D plot..
Series 1 has the legend while on 2 its disabled. When I hover my cursor over the legend I want the tooltip to show up in both the chart, so a user can correlate legend to points on scatter plots.
$('.highcharts-legend text, .highcharts-legend span').each(function (index, element) {
$(element).hover(function () {
chart.tooltip.refresh([chart.series[index].data[0], chart.series[index+data.length].data[0]]);
}, function () {
chart.tooltip.hide();
})
});
I use above code to create desired effect, but tooltip is not appearing at the right place. maybe its a limitation from highchart. It throws the following JS error
Could someone please suggest me a workaround?
If you could make the chart.tooltip.refresh to function properly that would be the best. Other wise I am willing to make a compromise with at-least having the points in both series in hovered state and 1 of them showing the tooltip.
here is a fiddle to see the problem in action https://jsfiddle.net/9eoyg283/1/ , Hover over the legend items and you would get JS error in the console.
I can create the desired effect if I create 2 charts instead of using 2 series, but then that complicates other things which are not desirable. So this solution is off
Thanks in advance

Highcharts colorAxis - Hide or add dynamically

I have a system set up where the user adds a chart and then selects the type they want. If I add the chart with the colorAxis in place, how do I hide it or remove it for those charts where I don't need it?
If I create the chart without the colorAxis, what is the proper way to add the colorAxis? I tried using the addAxis just like you would for any other axis, but there are problems. The remove function removed the colorAxis from the chart object, but not from the chart. It also resulted in an error.
You can destroy colorAxis by remove legend.
chart.legend.destroy();
Example: http://jsfiddle.net/h0rkf05t/

Turn series and plot bands on/off using API

I have a chart that has a custom legend i.e. it isn't part of Highcharts at all, it's completely my own code, the Highcharts legend is disabled for this chart.
Is it possible to turn series data AND plot bands on/off in a Highcharts chart using the API?
I found an example that triggered the click event of a legend item to do this, but this obviously relies on a legend being present, so this is no use to me: http://birdchan.com/home/2013/01/23/trigger-a-click-event-on-a-legend-item-in-highchart/
I also tried to set the series data .visible property to false and then redraw the chart and although it sets the visible property just fine, it doesn't redraw the chart so nothing changes:
var chart = new Highcharts.Chart(myoptions);
$("#custom_legend_link").click(function (e) {
chart.series[0].visible = !chart.series[0].visible;
chart.redraw();
}
Here is a jsFiddle using the basic line demo showing my problem:
http://jsfiddle.net/gfyans/zsaV4/
Thanks,
Greg.
To toggle the series, use Series.setVisible(). When called without parameters, it toggles.
Plot bands are a bit different, since they don't have methods like hide(), show() or setVisible. To toggle a plot band, you need to remove it by Axis.removePlotBand() and add a new one with the same options by Axis.addPlotBand().

Changing the contents of Highcharts legend

When using Highcharts, is it possible to change the contents of the legend to display something other than the series?
For example, I have a scatter chart with just one series but with many elements, so that the element labels obstruct one another and are illegible:
Would it be possible to use the legend to display the element names instead of the series? (each member in the series has a different color so that it is possible to use the legend in this case)
EDIT:
It turns out there isn't any good way to do this, so I wrote my own custom legend. You can find the code here: http://pastie.org/5115536
I hope you find it useful
Highcharts allows to show data points instead of series name in the in the legend. But, Unfortunately its only for Pie charts type:pie.
There is a default option available for the Pie Chart though undocumented in the API.
legendType: 'point',
If you try to set it for other type of chart, Legend does not gets rendered.

Resources