Sliding the data of the line highchart - highcharts

I have a line Highcharts which is receiving real data, and the amount of points is infinite across the time. I need to split this and delete the oldest points after an determinate amount of points. For example, when it arrives to 50 points, the Highcharts deletes the first point drawn and draws the new one, the number 51.
Is there any option to get this? Revising the Highcharts documentation I couldn't find it.

When adding new points you can use the shift parameter to drop off old points when adding the new point. API description:
addPoint (Object options, [Boolean redraw], [Boolean shift], [Mixed animation])
shift: Boolean
Defaults to false. When shift is true, one point is shifted off the start of the series as one is appended to the end. Use this option for live charts monitoring a value over time.
For example:
// attributes: point options, redraw, shift
series.addPoint([value], true, series.data.length >= 10);
Or see this JSFiddle demonstration of it.

Related

TChart axis labels overlapping when using a lot (more than 100) of TLineSeries

I'm dealing with an application that abuses TChart with potentially hundreds of TLineSeries. I get unreadable X axis labels, because they overlap. According to this, that shouldn't happen, but it does.
I'm now looking for a way to completely disable X axis labels derived from the TLineSeries elements and only show calculated labels at regular intervals, e.g. no labels for individual data points. How would I do that?
The misbehaving application:
My failed attempt to replicate the problem:
If the Bottom Axis for the chart has a scale set with Automatic turned off (default is on) you can get overlap like that depending on your data, the desired increment and if Show all labels is checked.
However your example seems to show non-regular extra labels which might just be manually added using the Items (show in far right tab) or something else to add more axis labels.
I was finally able to reproduce the problem with a small test case. Turns out that the problem was, that the application used function TChartSeries.AddXY(Const AXValue, AYValue: TChartValue; Const ALabel: String; AColor: TColor): Integer; and provided a value for ALabel. Using only X and Y values fixed the problem.

amCharts 4: How to get series tooltip to show between samples

We've recently upgraded our amCharts library from version 2 to version 4. In version 2, when the user hovered over the chart, the tooltips on the step line series showed up between the samples; whereas, in version 4, they only show up when the cursor is hovering exactly over one of the value points. (See screen shot.) We haven't changed our code in any appreciable way (other than what we had to do to get it to work with version 4), and we'd really like to get that old behaviour back, as it's difficult to get the cursor exactly over a data point in order to see what the value is. (Note: It's often the case in our charts that some series may have more data points than others in a given time/date range, as is the case in the screen shot, where the line series has more data points than the other two series.)
What can we do to get the tooltips on the various series in the chart to show up when the cursor is between data points? (It doesn't necessarily need to follow the cursor exactly as long as it shows up somewhere (e.g., on one or the other data point to either side of the cursor).)

Highcharts :: Need to split y-axis from primary body of chart. Can I display this axis separately from the Highchart?

I have a situation where I need to remove all margins from a highchart and remove the x/y axis so it fills a series of columns in a table completely.
I did that, no problem. Chart goes to the extremes as needed.
What I need now is that pesky yaxis I already removed...but displayed in a table cell outside of the existing highcharts object.
It would seem easy, as though I could just set the overflow property of yaxis to 'visible' and play with the offset...which would work however this would only work if I wanted to re-position the axis within the boundaries of the highchart object. I want him in a different cell entirely.
Is there anyone who has had experience in this situation? Is it going to require me to have a secondary highchart with only a y-axis?
Best answer gets a green check.
EDIT :: I now have dispersed each 'day' into their own column (more bars coming per day [scheduled,actual,etc...]). In order to keep the scales lined up, I manipulate the yAxis:max property and set them all to a derived value.
In the open column (currently w/ text Hourly Trends) is where I would put an additional highchart module with no series data but with the same min/max/tickInterval.
The next big leap will be to see the data is alive and changes w/ schedule. May have to start another thread for that one, no?
Create a new HC object with no data but only the yAxis (making sure it is the right scale, etc). Perhaps add the same series of data to it but hide the series? Add it to the location you want. This seems kludge and not very good practice. Each business use is different but why would you want this?
EDIT based on comment of business rules:
Why not come at this from a different direction and have the individual chart elements (the bars/points/etc) be a single point chart. This way you have one chart per column. You can then set up the yAxis to be text and not worry about the position. If we could see an example of the page layout and the desired result that would help.

Shifting Chart without losing points

I want to shift a chart in another way than addPoint does. You can see what I mean in my JSFIDDLE: http://jsfiddle.net/Charissima/TEEdw/3/
When the chart has filled the container and the next point is added, it shifts to the left without losing the first point.
It works fine, but sometimes I can see the chart swapping a little bit. And even worth: when running over a longer time the chart gets lost. It still works, you can see it shifting and updating y in the upper right corner, but the chart is not visible any more. Even the navigator is empty.
So my question is: Is there a better and smarter way to shift the chart this way?
data.push([ xTime, prevY ]);
data.push([ xTime, y ]);
series.setData(data, true);
var faktor = ( (chart.xAxis[0].max - chart.xAxis[0].min) / 60 / 1000 ) * 200;
chart.xAxis[0].setExtremes( chart.xAxis[0].min + faktor, chart.xAxis[0].max + faktor);
I've been working on a chart with very similar attributes and have run into similar problems. One of the undesired effects of the addPoint() shift flag is that it tries to keep the data set the same size it was initialized with. I'm guessing that is your reason for not using it. It doesn't allow you to grow your data set to a certain size and then start shifting. I had this issue with the shift so I resorted to doing exactly what you are doing. I think this is the generally accepted alternative to addPoint().
But... couple that with the idea that Highchart (or maybe just Highstock) appears to have a max number of data points it will handle. I don't know if it is the same for all charts (or even for all users/browsers) but for me yours seems to disappear when the data count is 1000. See this fiddle: > jsfiddle.net/TEEdw/4/ you can watch the data length grow to 1000 and then the chart disappears. I was running into the same issue on my chart. My solution was more complicated due to other factors in my chart. But a simple solution is to monitor the data count and when it approaches 1000, switch to the addPoint() with shift method. See this fiddle: > jsfiddle.net/TEEdw/5/ There is probably other ways to allow the data set to grow and then shift at a certain point. But this one just used your existing code. You could probably dynamically set the shift flag based on data length and only set it true once the data reaches a certain length.
EDIT: Ok... there is also a plotOptions setting called turboThreshold (http://api.highcharts.com/highcharts#plotOptions.series.turboThreshold) that can be disabled. It defaults to 1000 (so that makes sense). Setting it to zero allowed your chart to keep going after 1000. See this fiddle: jsfiddle.net/TEEdw/6/

TChart - Dont plot values that are less than 0?

Introduction
I am using the TChart component and am finding the options rather confusing and hard to find what I need.
The Left Axis of the chart has a minimum of 0 and a maximum of 5000, the Bottom Axis has a minimum of 0 and a maximum of 52 (weeks in a year).
In my chart I have 2 series that are populated based on values from a record I have created which can be edited at runtime, everything is working good so far.
Problem
Take a look at the below image of part of the chart filled with some random values:
I am not sure if such an option exists or not, but notice from week 4 onwards where no values have been added there is a solid red line.
I don't want the chart to plot values that are less than 0, so in this example from week 4 onwards there should be no more lines (I can confirm that from week 4 onwards I have the values set at -1)
Week 1 to 4 does not show this bottom red line, obviously because the values are greater than 0 and are therefore plotted above the line, but this should make my problem a bit more clearer.
So, how do I prevent the chart from plotting / drawing values that are less than 0, importantly for the Bottom Axis of the chart?
I am sure there must be a simple option somewhere, I just cannot find it if there is one as I am not too familiar with the TChart Component.
You have the possibility when adding values to a series to add them as null.
This will prevent them from showing.
Ken is correct saying that a tricky situation is to handle a single value surrounded by null values.
Picking another series type than FastLine and show dots as well as lines might work better.
For a FastLine series to show gaps, set:
Series1.IgnoreNulls := False;
And to discriminate values below zero:
if (y < 0) then
Series1.AddNullXY(x, y, '')
else
Series1.AddXY(x, y, '');
if y < 0 then
LineSeries1.AddXY(x, y, '', clNone)
else
LineSeries1.AddXY(x, y, '', clRed);

Resources