Pre loader

How can I update xAxis labels?

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums

0
0

Hello.
I am working on a stock chart with socket.
When received a new data, it is added to the chart,
but the labels of xAxis do not update their datetimes.
And I touch the surface of the chart,
then the labels of xAxis are updated.
What is wrong?
I attach some parts of my code.
Please let me know the correct way that I can update automatically the labels of x axis when a new data is added to.

The function for the x Axis creation
void setYAxis() {
yAxis = sciChartBuilder.newNumericAxis().withGrowBy(0d, 0.1d).withAxisAlignment(AxisAlignment.Right).withAutoRangeMode(AutoRange.Always).build();

    PenStyle tickStyle = new SolidPenStyle(_chartSetting.tickStyle, true, 2, null);
    BrushStyle bandStyle = new SolidBrushStyle(_chartSetting.bandStyle);
    PenStyle gridlineStyle2 = new SolidPenStyle(_chartSetting.gridlineStyle2, true, 2, null);
    // PenStyle gridlineStyle = new SolidPenStyle(_chartSetting.gridlineStyle, true, 1, new float[]{10, 10});
    PenStyle gridlineStyle = new SolidPenStyle(_chartSetting.gridlineStyle, true, 1, null);

    yAxis.setAxisBandsStyle(bandStyle);
    yAxis.setDrawMajorBands(true);
    //yAxis.setMinorTickLineStyle(tickStyle);
    yAxis.setMajorTickLineStyle(tickStyle);


    yAxis.setMajorGridLineStyle(gridlineStyle);
    yAxis.setMinorGridLineStyle(gridlineStyle2);
    String yFormat = "%.2f";
    if (chartData != null) {
        SmSymbolManager symbolManager = SmSymbolManager.getInstance();
        SmSymbol symbol = symbolManager.findSymbol(chartData.symbolCode);
        yFormat = "%.";
        if (symbol != null)
            yFormat += Integer.toString(symbol.decimal);
        else
            yFormat += Integer.toString(2);
        yFormat += "f";
    }
    yAxis.setLabelProvider(new NumericLabelProviderEx(yFormat));

    Collections.addAll(surface.getYAxes(), yAxis);

    if (_style == "mock_left" || _style == "mock_right") {
        yAxis.setVisibility(View.GONE);
    }

    if (_style == "mock_main") {
        yAxis.setVisibility(View.VISIBLE);
        yAxis.setAxisAlignment(AxisAlignment.Left);
    }
}

The callback function for the new data arrival.
private synchronized Action1 onNewPrice() {
return new Action1() {
@Override
public void execute(final PriceBar price) {
if (symbolCode.compareTo(price.getSymbolCode()) != 0 ||
lastPrice == null ||
lastPrice.getDate() == price.getDate())
return;

            DateFormat dateFormat = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");
            String strDate = dateFormat.format(price.getDate());

            //Log.d("TAG", "onNewPrice:  -> " + price.getSymbolCode() + "::" + strDate);

            if (getSeriesType() == SmSeriesType.CandleStick || getSeriesType() == SmSeriesType.Ohlc) {
                ((IOhlcDataSeries) dataSeries).append(price.getDate(), price.getOpen(), price.getHigh(), price.getLow(), price.getClose());
            } else {
                ((IXyDataSeries) dataSeries).append(price.getDate(), price.getClose());
            }

            IRange dataRange = xAxis.getDataRange();

            final IRange visibleRange = surface.getXAxes().get(0).getVisibleRange();
            if (visibleRange.getMaxAsDouble() > dataSeries.getCount()) {
                visibleRange.setMinMaxDouble(visibleRange.getMinAsDouble() + 1, visibleRange.getMaxAsDouble() + 1);
                xAxis.updateAxisMeasurements();
            }

            getActivity().runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    ohlcAxisMarker.setBackgroundColor(price.getClose() >= price.getOpen() ? STOKE_UP_COLOR : STROKE_DOWN_COLOR);
                }
            });

            //smaAxisMarker.setY1(smaLastValue);
            ohlcAxisMarker.setY1(price.getClose());

            lastPrice = price;
        }
    };
}
Version
SciChart_Android_v2.5.0.2540_SDK
  • Yura Khariton
    Hi Shiwan. Do you see any exceptions in logcat? I don’t see anything wrong in your code except it’s abit confusing that you have problem with xAxis but code says that it’s yAxis. Code for data series update is similar to the one which we use in our ‘Realtime Ticking Stock Charts’ example and in our demo app labels updated correctly. As I see you use some custom LabelProvider. Maybe you can provide an entire project or modify one of our examples to reproduce this issue so I can debug it? Thanks in advance.
  • You must to post comments
Showing 0 results
Your Answer

Please first to submit.

Try SciChart Today

Start a trial and discover why we are the choice
of demanding developers worldwide

Start TrialCase Studies