Try to add candlestickseries to shinobiCharts in Xamarin.Android

313 Views Asked by At

I'm novice at Xamarin and I'm trying to use ShinobiCharts in Xamarin.Android to show candlestick data on it. Code from .axml:

<fragment
            class="com.shinobicontrols.charts.ChartFragment"
            android:id="@+id/chart"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

This is fragment where should be shown chart.

var chartFragment = (ChartFragment)FragmentManager.FindFragmentById(Resource.Id.chart);
var chart = chartFragment.ShinobiChart;
chart.SetLicenseKey("license_key");

chart.AddXAxis(new DateTimeAxis
            {
                GesturePanningEnabled = true,
                GestureZoomingEnabled = true
            });

chart.AddYAxis(new NumberAxis
            {
                GesturePanningEnabled = true,
                GestureZoomingEnabled = true
            });

var dataPoints =
                quotes.Select(
                    quoteCandle =>
                        new MultiValueDataPoint(DateUtils.ConvertToJavaDate(TimeStamp.UnixToDate(quoteCandle.Timestamp)),
                            (double) quoteCandle.Low, (double) quoteCandle.High,
                            (double) quoteCandle.Open, (double) quoteCandle.Close)).ToList();

var series = new OHLCSeries { DataAdapter = new SimpleDataAdapter() };
series.DataAdapter.AddAll(dataPoints);
chart.AddSeries(series);
chart.XAxis.Style.GridlineStyle.GridlinesShown = true;
chart.YAxis.Style.GridlineStyle.GridlinesShown = true;
chart.RedrawChart();

This is code of creating ShinobiCharts. The problem is that added series are not shown in chart. Style changed, but there are no series. What do I do wrong? I hope anyone can help.

2

There are 2 best solutions below

1
On

Sorry for question, Candlestickes are not available for trial version of ShinobiControls, only for premium version.

5
On

As sammyd said, CandlestickSeries are available in the trial version of ShinobiCharts for Android (as are all the other premium features). Have you managed to get the CandlestickChart sample running? The sample is included in the download bundle.

On the face of it your code looks fine (without seeing the rest of it) but there are a couple of things I'd recommend checking:

  1. Have you replaced the string license_key with the trial license key we would have emailed you when you downloaded the bundle? The trial license key is a a really long string of characters and digits.
  2. Is your data coming in as expected and does it make sense (e.g. are your low values less than your open values etc.)?
  3. I'm not sure it'll make much difference, as they're pretty much interchangeable, but you're actually creating an OHLCSeries in code but mention a CandlestickSeries
  4. Have you set the series' style object in a way that would stop it from showing i.e. have you set it to be transparent in colour?
  5. Are you getting an actual error, and if so what message is being logged?

Hopefully the above will help you get your candlestick chart up and running!

Edit:

If you're using the Android Emulator, your AVD needs to have GPU emulation turned on (as we use OpenGL ES 2.0 for rendering the charts). There's more information on using the emulator with OpenGL on the Android developer site.

Disclaimer: I work for ShinobiControls