stxx.chart.dataSet contains all of the data that could potentially be displayed on the screen if the user scrolled all the way to each end of the chart. stxx.chart.dataSegment contains only the data that is currently displayed on the screen. dataSegment is a "splice" of the dataSet.
Sometimes developers need to know where that splice has occurred (beginning of the dataSegement). Here is how:
stxx.chart.scroll always indicates how far away from the end of the dataSet the leftmost bar of the chart is. For instance, if the leftmost tick on the screen is today's bar (only one bar shown on the screen) then
stxx.chart.scroll==0. If the chart is scrolled all the way to the beginning of the dataSet then
It's worth noting that the chart allows the user to scroll past the end of the dataSet so stxx.chart.scroll can actually be greater than the dataSetlength.
So, to find the leftmost bar on the chart (beginning of the dataSegment):
leftTick=stxx.chart.dataSet.length-stxx.chart.scroll; if(leftTick<0) leftTick=0;
Similarly to the left tick,the chart allows the user to scroll past the beginning of the chart, leaving whitespace on the right and causing the right most tick (although empty) to be past the edge of the dataSet.
So the correct formula for finding the rightmost bar on the screen is:
rightTick=stxx.chart.dataSet.length-stxx.chart.scroll+stxx.chart.maxTicks; if(rightTick>stxx.chart.dataSet.length) rightTick=stxx.chart.dataSet.length; rightTick--; // to adjust to the correct index given that arrays begin at 0, not 1
The actual data for either can then be queried with:
As mentioned above, dataSegment is a "splice" of the dataSet. The dataSegment represents the data that is displayed on the screen. It can change rapidly as a user navigates whereas dataSet remains static unless the user loads a new chart or a new periodicity.
There is some nuance to be aware of with dataSegment. If the user scrolls all of the way to the left, past the beginning of the chart data, then the first entries of dataSegment will be null. Always check for null when examining the dataSegment.
On the other hand, if the user has scrolled all the way to the right, past today's bar leaving whitespace, then the dataSegment will end at the last actual bar on the screen.
If you wish to examine the actual axis of the screen, regardless of whether there is whitespace on the left or right, then use
stxx.chart.xaxis. Like dataSegment, the xaxis will contain nulls on the left if the user has scrolled past the begining. But it will contain entries for future dates if the user scrolls to the right leaving whitespace. i.e.
Visual Image: Chart Scrolled to Right With Whitespace
Visual Image: Chart Scrolled to Left: beyond beginning of data