问题
I'm trying to display a candlestick series with TeeChart library.
Everyting is fine except I can't control the range of data displayed. The question is when I add new data to my series, I want to scroll my bottom axis to display the last N values. E.g. when I add a new candle, I want to scrol +1 index to display this bar.
I found that Axis class has 2 methods for doing this:
axis.setMinMax(DateTime arg0, DateTime arg1)
axis.setMinMax(double arg0, double arg1)
Which is the right method to use in conjunction with Candles? I guess that this is the 1st overload that takes 2 DateTime params, but I'm adding values to the Candle series without a specific date:
Candle series = ...
...
series.add(bar.getOpen(), bar.getHigh(), bar.getLow(), bar.getClose());
so all of the points have a default date.
Also I tried to use axis.setMinMax(double arg0, double arg1)
specifying startIndex and endIndex I wanted to display, but it doesn't seem to be working...
Is it possible to control range in my case with candles without specifying a DateTime value for each series' value?
回答1:
If you know the startIndex and endIndex, you could do this:
axis.setMinMax(series.getXValues().getValue(startIndex), series.getXValues().getValue(endIndex));
Another alternative, if you know the offset to apply to the axis, would be calling the axis scroll method, ie:
int myOffset = 1;
axis.scroll(myOffset, true);
And another alternative, if you know the number of values to display:
int nValuesToShow = 10;
axis.setMinMax(series.getXValues().getValue(series.getCount()-nValuesToShow-1), series.getXValues().getValue(series.getCount()-1);
Finally note the Add()
override without date (without XValue) is adding your value with getCount() as XValue.
来源:https://stackoverflow.com/questions/25350626/how-do-i-set-min-and-max-for-bottom-axis-for-candlestick-series-in-teechart