Highstock/Highchart scatter points in combined graph - javascript

I am trying to plot a combination chart of a scatter and columnrange.
I am having issues with the scatter plot not showing correctly. The points seem to "stop" at a certain point after zooming in and scrolling.
https://codepen.io/moosejaw/pen/QavGgR?editors=0011
It must be related to the boost module?
I've tried enabling and disabling it.
boost: {
// enabled: false // works
enabled: true // doesn't work
}
I know the boost module can handle the number of points, but I am confused on why their is a scrolling / placement issue.
Thanks for your time.

This issue happens only when the chart is inverted.
It's a bug reported on github: https://github.com/highcharts/highcharts/issues/4608
The workaround here is to create inverted chart manually (which can be done via chart options and preprocessing the data):
Swap x and y values for all points
Set reversed to true for the y axis (when chart is inverted it's set by default: https://api.highcharts.com/highcharts/chart.inverted)
Swap formatting and zoom options for axes
Handle the format of tooltip (tooltip.formatter may be useful)

Related

Chart.js: Don't stretch axes beyond chart

I'm using chart.js 2.9.4 and the ng2-charts wrapper for Angular. I'm trying to display incoming live data, but have trouble configuring the chart so that the ticks/axis don't stretch beyond the data in the chart. In other words, I want the chart data points to fill the entire width of the chart grid.
StackBlitz showing my issue.
If you keep looking at the chart as data is added, you see that most of the time the ticks stretch beyond the last point in the chart:
The only solution I could come up with is overwriting the max value of the ticks on the x-axis each time new data is added to the chart: options.scales.xAxes[0].ticks.max = x;. Uncomment line 68 in the StackBlitz in order to apply this. This solves my problem but introduces another. Sometimes as data gets added, the last two ticks overlap:
I've tried experimenting with various parameters of the scales and ticks options (bounds,distribution,stepSize,source,autoSkip,autoSkipPadding) with no results. Is there any combination of configuration parameters to solve my issue ?
You may want to add delay at streaming plugin, the config will look something like:
scales: {
x: {
type: 'realtime', // x axis will auto-scroll from right to left
realtime: { // per-axis options
delay: 1000, // delay of 1000 ms, so upcoming values are known before plotting a line
pause: false, // chart is not paused
ttl: undefined, // data will be automatically deleted as it disappears off the chart
}
},
I have tested this on your code, and it seems to work as expected, you may want to tune some parameters as needed.

Apache ECharts: "time" Axis labels are overlapping when using DataZoom

I am using Apache ECharts to create a line chart with an Y Axis of type "value" and an X Axis of type "time". I am also implementing dataZoom on the X Axis, which is working correctly. The problem is that when I move the dataZoom a bit, this happens:
My data consist of series with actual Date objects for the X axis, like:
Then, I have the following config for the X Axis. As you can see, I have specified a formatter in the Axis to convert dates to strings, which also works correctly.
Finally, my DataZoom config is just:
{ dataZoom: [{}] }
I am setting the same config as other time charts in ECharts official examples, but I am still getting this error. Any ideas?
xAxis: {
axisLabel: {
hideOverlap: true,
}
}
This should solve the overlapping issue.

Reverse one chart and leave the other unreversed - Synchronized highcharts

In order to reverse a chart you have to add reversed: true. It can be done either on the xAxis or the yAxis. In this example provided by Highcharts: https://jsfiddle.net/omaraziz/zg516ruk/ when I add reversed, it reverses all the charts. How can I reverse only one chart? More generally, what is the proper way to do more customization on one chart and not the other when the two are synchronized?
I chose synchronized because I wanted the values from both to be displayed at the same time when scanning from right to left and vice versa.
For now every time I change the legend position, reverse xAxis or yAxis, play with the tooltip, set a max and min for the yAxis, etc. it does it to both.
Here's my JSON data, in case the way to do it is through the JSON file: https://omaraziz.me/CC-chart/activity.json
You can use index variable i to recognize the chart. For example the IFFE function below return true only for the second chart:
xAxis: {
reversed: (function() {
return i === 1
})(),
...
}
Live demo: https://jsfiddle.net/BlackLabel/7fx6jdnw/

Highcharts Y-Axis Limits

I am having problems controlling the Y-Axis range of a highcharts graph. It seems like highcharts likes nice round numbers. When my data passes or is close to certain thresholds, the Y-Axis range can expand a lot which effectively compresses all the plot points downward.
Here is a jsfiddle that illustrates the problem I am having:
https://jsfiddle.net/shannonwrege/z8h5eork
The relevant code for this post is this:
chart.yAxis[0].setExtremes(0, max, true, false);
Keep in mind that I don't know what the data will look like in advance, so I must dynamically modify the Y-Axis range. Right now I am using the setExtremes because of other suggestions I've read on stackoverflow.
The maximum y-value of the data in the first two charts is 99. You'll notice that the y-axis is set at 150 in the first chart where the range is automatically calculated and 100 in the second chart where I specifically set the extreme values. The look of the 2nd chart is what I want. So it seems like setExtremes(0,99,true,false) should do the trick, but it actually doesn't.
In the 3rd chart I changed the data so that the maximum y-value of the data is 101, and I called setExtremes(0,101,true,false). You'll note that the y-axis is now back to 150.
Ideally I want the scale of the graph to be capped on the maximum value to limit the about of extra white space. I want to see all of the data, but I don't necessarily care about the y-axis displaying a maximum band that is greater than the max data value. In this case, I would be happy with the y-axis displaying 100 on the axis and some points over but still visible.
Does anyone know how to make this work?
I ended up using the endOnTick parameter to solve this problem. Adding the following line to the yAxis configuration parameters did exactly what I wanted:
endOnTick: false,
Here's the updated Fiddle showing the results.
https://jsfiddle.net/shannonwrege/z8h5eork/3/
All of the charts look pretty good in my opinion (even the one where the yAxis range was auto calculated).
You will need to read the data and then round up to set the idealMax
var chart,
idealMax = 0; // init the max value
// Read the data to find the highest value
for (i=0;i < (options.series[0].data).length; i++ ){
if (options.series[0].data[i][1] > idealMax) {
idealMax = options.series[0].data[i][1];
}
}
// Round the max to the nearest 10
idealMax = Math.round(idealMax / 10) * 10;
options.yAxis.tickPixelInterval = idealMax/10;
Highcharts.chart('container1', options);
chart = $('#container1').highcharts();
chart.yAxis[0].setExtremes(0, idealMax, true, false);
Updated Fiddle

D3 parcoords axis scale not updating correctly

I'm using the d3 parcoords library. When I modify data plotted in a parallel coordinates chart, and reload the chart, the scale of the axis isn't refreshed.
I tried calling .autoscale(), but if I call it before .render(), it has no effect, and if I call it after .render(), then no polylines are drawn anymore.
$("#example").html(""); //to make sure "ghost" axes are removed
parcoords = d3.parcoords()("#example")
.data(parsedData)
.createAxes()
.brushMode("1D-axes")
.reorderable()//;
.detectDimensions()
.dimensions(dimensionObj)
.autoscale() //no visible effect if placed here
.render()
.updateAxes();
Not sure if this is related (although the issue started at the same time), I started specifying an order for the dimensions. To do this, instead of using an array containing the axes (dimensionArray), I use a JS object dimensionObj containing numbered "index" keys, as follows:
//dimensionArray = ["axis1", "axis2", "axis3", "axis4"]; //orderless array
//Default axes to display with predefined ordering
dimensionObj = {
"axis1": {index:0},
"axis2": {index:1},
"axis3": {index:2},
"axis4": {index:3}
}
For illustration purposes, the following screenshots show how on the top image, the scales are properly set, but on the second (updated) chart, some new polylines are going to 0 on the 1st and 3rd axis, but the scale isn't updated so lines go out of range.
Is there a simple way to refresh the axis scales when reloading a chart? Is it possible that using the JS object in .dimensions() is creating some conflicts with the underlying scale function?
Found what was causing this behaviour: an if statement in d3.parcoords.js pc.autoscale function which was only resetting scales if the yscale was not previously defined. Essentially I edited the if statement from original:
d3.keys(__.dimensions).forEach(function(k) {
if (!__.dimensions[k].yscale){
__.dimensions[k].yscale = defaultScales[__.dimensions[k].type](k);
}
});
to this (of course the if statement could be dropped altogether, I simply kept it in this form in case I need to revert to original version later for any reason):
d3.keys(__.dimensions).forEach(function(k) {
if (!__.dimensions[k].yscale || __.dimensions[k].yscale){
__.dimensions[k].yscale = defaultScales[__.dimensions[k].type](k);
}
});

Categories

Resources