Right now i’m using trial version but i’m looking forward to buy full version as to integrate the charts in my app . I am building an real time chart that update data according to time , which means simply i need Time on the x axis and numeric values on the y axis , but i’m not getting any hint how to get the time values on the x axis .
- Abhishek Sadana asked 9 years ago
- You must login to post comments
Hi Abhishek,
Good question! SciChart’s Android Chart features a DateAxis which can be used to display date and time on the XAxis.
There is an example of use in the Android Mountain Chart example which has the following code to initialise a DateAxis and populate an XyDataSeries with Date data for X-Values.
package com.scichart.examples.fragments;
Â
import ... // See https://www.scichart.com/android-mountain-chart-example for full imports
Â
import java.util.Collections;
import java.util.Date;
Â
public class MountainChartFragment extends ExampleBaseFragment {
    @Bind(R.id.chart)
    SciChartSurface surface;
Â
    @Override
    protected int getLayoutId() {
        return R.layout.example_single_chart_fragment;
    }
Â
    @Override
    protected void initExample() {
        UpdateSuspender.using(surface, new Runnable() {
            @Override
            public void run() {
                final PriceSeries priceData = DataManager.getInstance().getPriceData(getActivity());
Â
// Initialises an XyDataSeries with type TX=Date and TY=Double
                final IXyDataSeries<Date, Double> dataSeries = sciChartBuilder.newXyDataSeries(Date.class, Double.class).build();
Â
// Appends Date Data on X, and Double data on Y
                dataSeries.append(priceData.getDateData(), priceData.getCloseData());
Â
                final IAxis xBottomAxis = sciChartBuilder.newDateAxis()
                        .withGrowBy(new DoubleRange(0.1d, 0.1d))
                        .build();
Â
// Declares the DateAxis
                final IAxis yRightAxis = sciChartBuilder.newNumericAxis()
                        .withGrowBy(new DoubleRange(0.1d, 0.1d))
                        .build();
Â
                final IRenderableSeries rs1 = sciChartBuilder.newMountainSeries()
                        .withDataSeries(dataSeries)
                        .withXAxisId(xBottomAxis.getAxisId())
                        .withYAxisId(yRightAxis.getAxisId())
                        .withStrokeStyle(0xAAFFC9A8)
                        .withAreaFillLinearGradientColors(0xAAFF8D42,0x88090E11)
                        .build();
Â
                Collections.addAll(surface.getXAxes(), xBottomAxis);
                Collections.addAll(surface.getYAxes(), yRightAxis);
                Collections.addAll(surface.getRenderableSeries(), rs1);
                Collections.addAll(surface.getChartModifiers(), sciChartBuilder.newModifierGroupWithDefaultModifiers().build());
            }
        });
    }
Please take a look and let me know if it helps!
Best regards,
Andrew
- Andrew Burnett-Thompson answered 9 years ago
- Actually here we are adding static data in this , but i need to show only current time like as “hh:mm” on x-axis , or is there any way we can add string values on the x-axis as i can parse the current time in string format after that i’ll append in series.
- I would think you can simply set the DateAxis.TextFormatting to allow the string to be formatted as hh:mm. Try calling dateAxis.setTextFormatting(“hh:mm”) with a Java date format string . For advanced string formatting there is a feature called LabelProvider which will allow strings on an axis. AxisBase.setLabelProvider(new CustomLabelProvider()) where CustomLabelProvider inherits LabelProviderBase https://www.scichart.com/documentation/android/v1.x/webframe.html#SciChart.Charting~com.scichart.charting.numerics.labelProviders.LabelProviderBase.html
- Scroll and update time on X axis and value on Y axis
- Xaxis shows 5:30 constant no changes
- You must login to post comments
Please login first to submit.