When `sync` is enabled, hiding/showing dataset is also sync'ed? - javascript

Situation
I have multiple charts in my page that show different datasets.
I want to use chartjs-plugin-crosshair to be able to show vertical lines on hover.
I also want to sync the vertical lines so that I can the vertical on the same date.
Bug
Both of the above work, except I noticed a weird bug where enabling sync: {enabled: true} means hiding/showing a dataset of one chart hides/shows a dataset of another (even though they have different keys)
When I make sync: {enabled: false}, the weird bug stops, but then I lose the feature of syncing the vertical lines.
I looked through the code of the plugin but I don't see anything that changes the hidden property of datasets.
Plugin config
The plugin config is simple:
crosshair: {
...
sync: {
enabled: true, // enable trace line syncing with other charts
group, // chart group
suppressTooltips: false, // suppress tooltips when showing a synced tracer
},
zoom: {
enabled: false,
},
},
For confidentiality reasons I had to hide some info with red boxes. When I toggle a label on the first chart (top left) some of the labels of the others ones also get toggled. I never touch any of the labels of the remaining charts.
What gives?

Related

Looking for default yAxis options for Highmaps to be able to add it from code

I need to remove and then add an yAxis for the highmaps using javascript.
However, I cannot find axis's settings that are responsible for fixing issues with zooming and dragging after zoom.
Here is my code: http://jsfiddle.net/bso80657/
If you comment lines 53 and 54, you will see a normal default behaviour: zoom is working fine.
Issues with my code after removing and adding yAxis:
It is not possible to use a mouse wheel to zoom in.
If you use 'plus' button to zoom in and then drag the map a bit up or down - it resets zoom settings.
I could figure out that the axis should be reversed and hidden.
Here is a piece of code responsible for removing and adding an axis.
var axis = {
reversed: true,
visible: false,
};
//Comment the next two lines to be able to check the default behaviour
chart.yAxis[0].remove(false);
chart.addAxis(axis, false);
What other options I should use to fix this zoom issue?
Thank you.

How to apply data-grouping to indicators in HighCharts highstocks

I am using HighCharts engine to draw some stock-charts. Currently i use candlesticks and managed to change the candles time period by changing plotOptions.dataGrouping settings which are defined in react state:
chageDataGrouping(){
this.setState((prevState)=>({
options:{
...prevState.options,
plotOptions:{
...prevState.options.plotOptions,
series:{
dataGrouping : {
//setting data grouping value to show each candle as a summary of 2 weeks candles
units: [['week', [1] ] ]
},
forced : true,
enabled : true,
}
}
}
}
}))
The above code works fine. The Problem is this : if there is an indicator present in the chart, changing the data-grouping setting in plotOptions, makes the indicators disapear. By the way i am changing data grouping manually as user clicks on a button to select 'week','month',etc view.
Since i am using react and setting up chart options in react.state, it feels like i am some how re-redering the chart which makes the indicators disappear.
Any ideas? tnx.

Highcharts scatter chart legend toggle running slow

I'm working on a scatter chart with highcharts. The chart renders just fine, but when I click on the legend to toggle any one of the series, the whole chart becomes very slow. It works on chrome (takes a good 15 seconds to load), but on safari, it times out. If I switch my 'type' to line, the legend toggle becomes nice and swift again. So, is there something about the highcharts scatter chart that I need to look into? FYI I also tried the booster on the highcharts API, but it doesn't work for me.
This is the code I use in the legend:
legend: {
width: 0,
enabled: true,
itemStyle: {
'cursor': 'pointer'
}
}
Here is my fiddle.
Disabling animations made it toggle quickly for me.
options.chart.animation = false;

Chart.js pie tooltip getting cut

I'm using Chart.js pie chart with tooltips which being cut for some reason.
Screenshot attached, didn't found any attribute/option to take care of it..
Is there anyway to take care of it?
Thanks!
This improper cutoff was raised as issue#622 in the Github repository for ChartJS.
This was determined to be a bug (evidently this bug hasn't yet been fixed)
https://github.com/nnnick/Chart.js/issues/622
In response to that issue, Robert Turrall has a solution which he says is a good workaround. Here is his proposed fix:
I'm sure that this is due to the fact that the tooltips are generated
within the confines of the canvas, making it difficult to fix.
I had the same issue on my doughnut chart and solved it by
implementing custom tooltips as per the example on the samples folder
- worked in conjunction with my existing tooltip fontsize and template settings in the chart initialisation code:
var myDoughnutChart = new Chart(donut).Doughnut(donutdata, {
tooltipFontSize: 10,
tooltipTemplate: "<%if (label){%><%=label%>: <%}%><%= value %>hrs",
percentageInnerCutout : 70
});
Check out samples/pie-customTooltips.html for the custom tooltip code.
Copy/paste and it worked straight away. Very happy!
Tooltip displayed well outside the bounds of the canvas:
PS: there's a line chart example too, which I'm guessing will work
fine with bar charts.
You can add internal padding to the chart. For instance in my case I had a cut of tooltips on the right.
options: {
responsive: true,
maintainAspectRatio: false,
cutoutPercentage: 60,
legend: {
display: false
},
animation: {
animateRotate: false
},
layout: {
padding: {
right: 40
}
}
}
I found a workaround for this. I have blank labels on my x axis, so I just added a label with several spaces in it for the last label entry. That caused ChartJS to leave enough space for the label to fit, which also leaves enough room for the tooltip to fit.
In addition, I have large circles for my data points and the last one on the right was getting clipped before. Adding the extra space to the label also fixed that.
Here is the code where I create my labels. The ratings is my actual data defined earlier:
// Add blank labels and "Today"
for (i=0; i<ratings.length; i++) {
labels.push("");
}
labels[ratings.length-1] = " ";
var data = {
labels: labels,
datasets: [
{
label: "Progress",
strokeColor: "rgba(255,165,0,1.0)",
pointColor: "white",
pointStrokeColor: "rgba(255,165,0,1.0)",
pointHighlightStroke: "#B87700",
data: ratings
}
]
};
Even if you have actual labels on your graph, you could add spaces to your last label to make it bigger. If you are centering your label, you could add the same amount of space before and after.
Obviously there will be limits where this will or won't work for you, but for my case I added 7 spaces and all looks good now.
Also, my case had an issue on the right side, whereas this question has an issue with the left side. The same fix should work, but putting the space on the first label.
It seems like Chart.js can't figure out which direction to show the tooltip because it can't detect the size of the tooltip element when it extends beyond the canvas.
In my scenario I fixed it by squeezing the text inside this particular tooltip closer with these options for the tooltip options object:
tooltips.titleMarginBottom = 1;
tooltips.bodySpacing = 1;
tooltips.yPadding = 2;
Wierdly enough Chart.js then correctly decides to show the tooltip to the left of the mouse and not below.
Would be cool if you could choose which direction the tooltip appears compared to the mouse.
In my case, I was able to work around this issue by reducing the amount of text in the tooltip. I did so using custom tooltip callbacks to specify the label text. My initialization looked like this:
var chart = new Chart(canvas.getContext("2d"), {
type: 'line',
data: chartData,
options: {
responsive: true,
tooltips: {
callbacks: {
title: function(tooltipItems, data) {
return tooltipItems[0].xLabel;
},
label: function(tooltipItems, data) {
return tooltipItems.yLabel;
},
}
},
},
});
There appears to be a fix available that hasn't yet been merged into the project: https://github.com/chartjs/Chart.js/pull/1064
Interestingly, by the setting the tooltipCaretSize option to 0 solves the issue.
{ tooltipCaretSize: 0, ... }

Javascript Highcharts v3.0.5 - How to hide Y Axis Title when using multiple Y Axis

When using Highcharts (v.3.0.5), I have multiple Y Axis displayed in the same chart. Using the legend, a user can choose to hide or show any of the Y Axis as they want. All this is built in feature of the Highcharts javascript library. However, when a Y Axis is hidden, its Title still appears visible in the Chart. I would like to hide it when the rest of the Y Axis is hidden. Surprised this is not the default behaviour already. Does anyone know how to do that?
The behaviour can be seen by looking at the example provided on Highcharts examples page:
http://www.highcharts.com/demo/combo-multi-axes
If you hide the "rainfall" axis for example, the title remains in the chart as "Rainfall".
I found this post (several years old) where the exact same question was asked. However, the solution proposed does not work. The show and hide events, redisplay everything.
http://forum.highcharts.com/highcharts-usage/how-to-hide-y-axis-title-multiple-axis-t6973/#p32842
This actually turns out to be a much sought after question/answer. Since Highcharts V2.2, it is possible to assign "showEmpty: false" to y axis definitions and this will ensure that when hidden, the Y-axis text label is also hidden. Example snippet of config below:
yAxis: [{
min: 0,
showEmpty: false,
labels: {
formatter: function() {
return this.value;
},
style: {
color: '#3366CC'
}
},
title: {
text: 'Clicks',
style: {
color: '#3366CC'
}
},
id: 'Clicks'
},
...
I have read reports where this showEnabled = false breaks if both min and max are also set. In the case above, where only min is set, it worked well for me using Highcharts V3.0.5
you can use yAxis.setTitle() and set/remove the title when needed.
here is the api documentation link
#arcseldon, it is true that showEnabled = false breaks if both min and max are also set. A possible workaround in this case is to set floor and max instead

Categories

Resources