2

I'm trying to create a mountain chart using SciChart, but I need to create using Logarithmic, I tried the below code, but dont change chart and missing YAxis label. I change the demo SciChart to it:

public class MountainChartFragment extends ExampleBaseFragment {
@BindView(R.id.chart)
SciChartSurface surface;

private double selectedLogBase = 10d;
@Override
protected int getLayoutId() {
    return R.layout.example_single_chart_fragment;
}

@Override
protected void initExample() {
    //final IAxis xBottomAxis = sciChartBuilder.newDateAxis().withGrowBy(0.1d, 0.1d).build();
    final IAxis xBottomAxis = sciChartBuilder.newDateAxis().withGrowBy(0.1d, 0.1d).build();
    final IAxis yRightAxis = sciChartBuilder.newLogarithmicNumericAxis().withScientificNotation(ScientificNotation.LogarithmicBase).withLogarithmicBase(selectedLogBase).withGrowBy(0.1d, 0.1d).build();
    //final IAxis yRightAxis = sciChartBuilder.newNumericAxis().withGrowBy(0.1d, 0.1d).build();

    final PriceSeries priceData = DataManager.getInstance().getPriceDataIndu(getActivity());
    final IXyDataSeries<Date, Double> dataSeries = sciChartBuilder.newXyDataSeries(Date.class, Double.class).build();
    dataSeries.append(priceData.getDateData(), priceData.getCloseData());

    final FastMountainRenderableSeries rSeries = sciChartBuilder.newMountainSeries()
            .withZeroLine(0.001)
            .withDataSeries(dataSeries)
            .withStrokeStyle(0xAAFFC9A8, 1f, true)
            .withAreaFillLinearGradientColors(0xAAFF8D42, 0x88090E11)
            .build();

    UpdateSuspender.using(surface, new Runnable() {
        @Override
        public void run() {
            Collections.addAll(surface.getXAxes(), xBottomAxis);
            Collections.addAll(surface.getYAxes(), yRightAxis);
            Collections.addAll(surface.getRenderableSeries(), rSeries);
            Collections.addAll(surface.getChartModifiers(), sciChartBuilder.newModifierGroupWithDefaultModifiers().build());

            sciChartBuilder.newAnimator(rSeries).withWaveTransformation().withInterpolator(new DecelerateInterpolator()).withDuration(3000).withStartDelay(350).start();
        }
    });
}

}

But dont worked

2 Answers2

2

There are no labels because default TickProvider implementation for LogarithmicNumericAxis can't generate any ticks for auto calculated VisibleRange which is set for YAxis ( it has next values - Min = 10460.814629837885, Max = 13048.710993563885) The nearest values which which would satisfy LogBase = 10 would be 10000 and then 100000 and data set of example lies between these two values so TickProvider returns zero values to render.

In this case there are two possible workarounds:

  • Try to pick up some other LogBase value;
  • Set some alternative TickProvider implementation for YAxis (e.g. you can try to use TickProvider for NumericAxis or create your own implementation):

    yRightAxis.setTickProvider(new NumericTickProvider());

Yura Khariton
  • 484
  • 2
  • 6
2

I change the code and worked well. This is my code:

xAxis = sciChartBuilder.newNumericAxis().withGrowBy(0.1d, 0.1d).withVisibleRange(1.1, 2.7).build();
    yAxis = generateLogarithmicAxis();
    //yAxis = sciChartBuilder.newNumericAxis().withGrowBy(0.1d, 0.1d).build();

    //yAxis.setTickProvider(new NumericTickProvider());

    final SimpleDateFormat formatDate = new SimpleDateFormat("yyyyMMdd");

    String data1 = "20190401";
    Date date1 = null;

    Calendar c = Calendar.getInstance();

    final IXyDataSeries<Date, Double> dataSeries = sciChartBuilder.newXyDataSeries(Date.class, Double.class).build();

    try {
        date1 = formatDate.parse(data1);
        for(int i = 0 ; i<1000 ; i+=10){

            double random = Math.random() * 100.0 + 5;
            dataSeries.append(date1, random);

            c.setTime(date1);
            c.add(Calendar.DATE, 1);
            date1 = c.getTime();
        }

    } catch (ParseException e) {
        e.printStackTrace();
    }


    final FastLineRenderableSeries rSeries = sciChartBuilder.newLineSeries().withZeroLine(0.01d).withDataSeries(dataSeries).withStrokeStyle(0xFF279B27, 1f, true).build();

    UpdateSuspender.using(surface, new Runnable() {
        @Override
        public void run() {
            Collections.addAll(surface.getXAxes(), xAxis);
            Collections.addAll(surface.getYAxes(), yAxis);
            Collections.addAll(surface.getRenderableSeries(), rSeries);
            Collections.addAll(surface.getChartModifiers(), sciChartBuilder.newModifierGroupWithDefaultModifiers().build());

            sciChartBuilder.newAnimator(rSeries).withSweepTransformation().withInterpolator(new DecelerateInterpolator()).withDuration(3000).withStartDelay(350).start();
        }
    });