Pre loader

Display a DateAxis data

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

I am using StackedColumnRenderableSeries and I have a problem when a data is displayed as it shows the incomplete graph as the second attached image.
Thank you

var xAxis = new DateAxis(this)
{
GrowBy = new DoubleRange(0.1, 0.1),
AxisTitle = “”,
AutoRange = AutoRange.Always,
TextFormatting = “MMM yyyy”,
DrawMajorGridLines = false,
DrawMinorGridLines = false,
AxisBandsStyle = new SolidBrushStyle(0xfff9f9f9),
};

Version
7.1
Images
  • Yura Khariton
    Hi Benigno. Can you post a project or code which will help us to reproduce the case from the second picture (data set with points from the picture, chart configuration etc)? Thanks in advance.
  • You must to post comments
0
0

The code is:

What is shown are monthly data so I send it 15/08/2917, 09/15/2017, 10/15/2017 so it stays in the middle.


public class HistPrec_G : AppCompatActivity
{
DrawerLayout drawerLayout;
NavigationView navigationView;
string _usuarioInterno, filtro;
Android.App.ProgressDialog progress;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);

        SetContentView(Resource.Layout.graf3);
        var toolbar = FindViewById<V7Toolbar>(Resource.Id.toolbar);
        SetSupportActionBar(toolbar);
        SupportActionBar.SetDisplayHomeAsUpEnabled(true);
        SupportActionBar.SetHomeAsUpIndicator(GetDrawable(Resource.Drawable.backButton));

        TextView ToolOff = FindViewById<TextView>(Resource.Id.modooff);
        //var chart = FindViewById<SciChartSurface>(Resource.Id.Chart);
        var chart = new SciChartSurface(this);
        var linearLayoutC = FindViewById<LinearLayout>(Resource.Id.linearLayout1);
        var linearLayoutL = FindViewById<LinearLayout>(Resource.Id.linearLayout2);
        int themeid = Resource.Style.SciChart_Bright_Spark;
        chart.Theme = themeid;


        _usuarioInterno = Intent.GetStringExtra("_usuarioInterno") ?? "Data not available";
        filtro = Intent.GetStringExtra("filtro") ?? "Data not available";
        string _codCliente = Intent.GetStringExtra("_codCliente") ?? "Data not available";
        string _codPuntoF = Intent.GetStringExtra("_codPuntoF") ?? "Data not available";
        string _moneda = Intent.GetStringExtra("_moneda") ?? "Data not available";
        string _fechaD = Intent.GetStringExtra("_fechaD") ?? "Data not available";
        string _fechaH = Intent.GetStringExtra("_fechaH") ?? "Data not available";
        string _modooff = Intent.GetStringExtra("_modooff") ?? "0";

        ModoOff();
        Inicializar();
        void ModoOff()
        {
            if (_modooff == "0")
            {
                ToolOff.Visibility = ViewStates.Gone;
            }
            else if (_modooff == "1")
            {
                ToolOff.Visibility = ViewStates.Gone;
            }
            else if (_modooff == "2")
            {
                ToolOff.Visibility = ViewStates.Visible;
            }
        }
        void Inicializar()
        {
            progress = ProgressDialog.Show(this, "", "Obteniendo datos...", true, false);
            progress.SetProgressStyle(ProgressDialogStyle.Spinner);
            new Thread(new ThreadStart(delegate
            {
                RunOnUiThread(async () => await CargarGrafico());

            })).Start();
        }

        async Task CargarGrafico()
        {
            List<BEGraficosFacturacion> resultado;
            List<TBLHistoricoPrecio> resultado1;
            DAReporte_Facturacion conexion = new DAReporte_Facturacion();
            BLTBLHistoricoPrecio conexion1 = new BLTBLHistoricoPrecio();
            TBLHistoricoPrecio data = new TBLHistoricoPrecio();
            string mhp;
            string MensajeErrorHP;

            if (_moneda == "USD") { mhp = "$ "; } else if (_moneda == "PEN") { mhp = "S/ "; } else { mhp = ""; }
            if (_modooff == "1")
            {
                resultado = await conexion.Reporte_HistoricoPrecio(_fechaD, _fechaH, _codCliente, _codPuntoF, _moneda);
                MensajeErrorHP = conexion.ResultadoFinalRHP;
                if (resultado == null)
                {
                    progress.Dismiss();
                    Toast.MakeText(this, MensajeErrorHP, ToastLength.Short).Show();
                }
                else if (resultado.Count == 0)
                {
                    progress.Dismiss();
                    Android.App.AlertDialog.Builder alert = new Android.App.AlertDialog.Builder(this);
                    alert.SetMessage("No hay datos");
                    alert.SetCancelable(false);
                    alert.SetPositiveButton("OK", (senderAlert, args) =>
                    {
                        Finish();
                    });
                    alert.Show();
                }
                else
                {
                    var Fecha = resultado.Select(x => x.Fecha).Distinct().ToArray();
                    var Potencia = resultado.Where(x => x.Concepto == "Potencia").Select(x => (Convert.ToDouble(x.Consumo))).ToArray();
                    var EnergiaHoraPunta = resultado.Where(x => x.Concepto == "EnergiaHoraPunta").Select(x => (Convert.ToDouble(x.Consumo))).ToArray();
                    var EnergiaHoraFueraPunta = resultado.Where(x => x.Concepto == "EnergiaHoraFueraPunta").Select(x => (Convert.ToDouble(x.Consumo))).ToArray();
                    var PrecioMedio = resultado.Where(x => x.Concepto == "Monomico").Select(x => (Convert.ToDouble(x.Consumo))).ToArray();
                    var PCSPT = resultado.Where(x => x.Concepto == "PCSPT").Select(x => (Convert.ToDouble(x.Consumo))).ToArray();
                    var SST = resultado.Where(x => x.Concepto == "SST").Select(x => (Convert.ToDouble(x.Consumo))).ToArray();
                    var cont = (Convert.ToDouble(resultado.Count) / Convert.ToDouble(6));
                    GraficarColumn(Fecha, Potencia, EnergiaHoraPunta, EnergiaHoraFueraPunta, PrecioMedio, PCSPT, SST, cont);
                }
            }
            else if(_modooff=="2")
            {
                DateTime desde = DateTime.ParseExact(_fechaD, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                DateTime _desde = new DateTime(desde.Year, desde.Month, 1);
                DateTime hasta = DateTime.ParseExact(_fechaH, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                DateTime _hasta = new DateTime(hasta.Year, hasta.Month, 20);
                data.CodCliente = _codCliente;
                data.CodPuntoFacturacion = _codPuntoF;
                data.Moneda = _moneda;
                resultado1 = await conexion1.Reporte_HistoricoPrecio(data, _desde, _hasta);
                MensajeErrorHP = "Error al momento de leer los datos guardados";
                if (resultado1 == null)
                {
                    progress.Dismiss();
                    Android.App.AlertDialog.Builder alert = new Android.App.AlertDialog.Builder(this);
                    alert.SetMessage("No hay datos sincronizados");
                    alert.SetCancelable(false);
                    alert.SetPositiveButton("OK", (senderAlert, args) =>
                    {
                        Finish();
                    });
                    alert.Show();
                }
                else if (resultado1.Count == 0)
                {
                    progress.Dismiss();
                    Android.App.AlertDialog.Builder alert = new Android.App.AlertDialog.Builder(this);
                    alert.SetMessage("No hay datos");
                    alert.SetCancelable(false);
                    alert.SetPositiveButton("OK", (senderAlert, args) =>
                    {
                        Finish();
                    });
                    alert.Show();
                }
                else
                {
                    var Fecha = resultado1.Select(x => x.Fecha).Distinct().ToArray();
                    var Potencia = resultado1.Where(x => x.Concepto == "Potencia").Select(x => (Convert.ToDouble(x.Consumo))).ToArray();
                    var EnergiaHoraPunta = resultado1.Where(x => x.Concepto == "EnergiaHoraPunta").Select(x => (Convert.ToDouble(x.Consumo))).ToArray();
                    var EnergiaHoraFueraPunta = resultado1.Where(x => x.Concepto == "EnergiaHoraFueraPunta").Select(x => (Convert.ToDouble(x.Consumo))).ToArray();
                    var PrecioMedio = resultado1.Where(x => x.Concepto == "Monomico").Select(x => (Convert.ToDouble(x.Consumo))).ToArray();
                    var PCSPT = resultado1.Where(x => x.Concepto == "PCSPT").Select(x => (Convert.ToDouble(x.Consumo))).ToArray();
                    var SST = resultado1.Where(x => x.Concepto == "SST").Select(x => (Convert.ToDouble(x.Consumo))).ToArray();
                    var cont = (Convert.ToDouble(resultado1.Count) / Convert.ToDouble(6));
                    GraficarColumn(Fecha, Potencia, EnergiaHoraPunta, EnergiaHoraFueraPunta, PrecioMedio, PCSPT, SST, cont);
                }
            }
            void GraficarColumn(DateTime[] Fecha, double[] Potencia, double[] EnergiaHoraPunta, double[] EnergiaHoraFueraPunta, double[] PrecioMedio, double[] PCSPT, double[] SST, double cont)
            {
                try
                {
                    var xAxis = new DateAxis(this);
                    if (Fecha.Count() == 1)
                    {
                        var title = Fecha[0].ToString("MMM yyyy");
                        xAxis = new DateAxis(this)
                        {
                            GrowBy = new DoubleRange(0, 1),
                            AutoRange = AutoRange.Always,
                            //TextFormatting = title,
                            AxisTitle = title,
                            DrawMajorGridLines = false,
                            DrawMinorGridLines = false,
                            //LabelProvider = new MonthYearLabelProvider(),
                            AxisBandsStyle = new SolidBrushStyle(0xfff9f9f9),
                        };
                    }
                    else if (Fecha.Count() > 1)
                    {
                        xAxis = new DateAxis(this)
                        {
                            GrowBy = new DoubleRange(-0.0175, -0.0175),
                            AutoRange = AutoRange.Always,
                            TextFormatting = "MMM yyyy",
                            AxisTitle = "",
                            DrawMajorGridLines = false,
                            DrawMinorGridLines = false,
                            //LabelProvider = new MonthYearLabelProvider(),
                            AxisBandsStyle = new SolidBrushStyle(0xfff9f9f9),
                        };
                    }
                    var yAxis = new NumericAxis(this)
                    {
                        AxisTitle = "Consumo" + " (" + _moneda + ")",
                        GrowBy = new DoubleRange(0, 0.1d),
                        CursorTextFormatting = mhp + "##,##0.00",
                        DrawMajorGridLines = false,
                        DrawMinorGridLines = false,
                        AxisBandsStyle = new SolidBrushStyle(0xfff9f9f9),
                        AxisAlignment = AxisAlignment.Left,

                    };

                    var PotenciaDataSeries = new XyDataSeries<DateTime, double> { SeriesName = "Potencia" };
                    var EnergiaHoraPuntaDataSeries = new XyDataSeries<DateTime, double> { SeriesName = "Energia Hora Punta" };
                    var EnergiaHoraFueraPuntaDataSeries = new XyDataSeries<DateTime, double> { SeriesName = "Energia Hora Fuera Punta" };
                    var PrecioMedioDataSeries = new XyDataSeries<DateTime, double> { SeriesName = "Precio Medio" };
                    var PCSPTDataSeries = new XyDataSeries<DateTime, double> { SeriesName = "PCSPT" };
                    var SSTDataSeries = new XyDataSeries<DateTime, double> { SeriesName = "SST" };
                    var totalDataSeries = new XyDataSeries<DateTime, double> { SeriesName = "Total" };


                    for (var i = 0; i < cont; i++)
                    {
                        PotenciaDataSeries.Append(Fecha[i], Potencia[i]);
                        EnergiaHoraPuntaDataSeries.Append(Fecha[i], EnergiaHoraPunta[i]);
                        EnergiaHoraFueraPuntaDataSeries.Append(Fecha[i], EnergiaHoraFueraPunta[i]);
                        PrecioMedioDataSeries.Append(Fecha[i], PrecioMedio[i]);
                        PCSPTDataSeries.Append(Fecha[i], PCSPT[i]);
                        SSTDataSeries.Append(Fecha[i], SST[i]);
                        totalDataSeries.Append(Fecha[i], Potencia[i] + EnergiaHoraPunta[i] + EnergiaHoraFueraPunta[i] + PrecioMedio[i] + PCSPT[i] + SST[i]);
                    }

                    var columnsCollection = new HorizontallyStackedColumnsCollection();

                    columnsCollection.Add(GetRenderableSeries(PotenciaDataSeries, 0xff7cb5ec, 0xff7cb5ec));
                    columnsCollection.Add(GetRenderableSeries(EnergiaHoraPuntaDataSeries, 0xFF434348, 0xFF434348));
                    columnsCollection.Add(GetRenderableSeries(EnergiaHoraFueraPuntaDataSeries, 0xFF90ed7d, 0xFF90ed7d));
                    columnsCollection.Add(GetRenderableSeries(PrecioMedioDataSeries, 0xFFf7a35c, 0xFFf7a35c));
                    columnsCollection.Add(GetRenderableSeries(PCSPTDataSeries, 0xFF8085e9, 0xFF8085e9));
                    columnsCollection.Add(GetRenderableSeries(SSTDataSeries, 0xfff15c80, 0xfff15c80));

                    var legend = new SciChartLegend(this);

                    var legendModifier = new LegendModifier(legend);
                    legendModifier.SetOrientation(SciChart.Core.Framework.Orientation.Vertical);
                    legendModifier.SetLegendPosition(GravityFlags.Top | GravityFlags.Start, 0);
                    legendModifier.SetSourceMode(SourceMode.AllVisibleSeries);
                    legendModifier.SetShowSeriesMarkers(true);
                    legendModifier.SetShowCheckboxes(true);
                    legendModifier.SetReceiveHandledEvents(true);

                    var modifierGroup = new ModifierGroup(legendModifier);

                    chart.ChartModifiers.Add(modifierGroup);
                    if (legend.Parent != null)
                    {
                        (legend.Parent as ViewGroup).RemoveView(legend);
                    }
                    chart.XAxes.Add(xAxis);
                    chart.YAxes.Add(yAxis);
                    chart.RenderableSeries.Add(columnsCollection);
                    //
                    chart.ChartModifiers.Add(new TooltipModifier());
                    //chart.ChartModifiers.Add(new ZoomExtentsModifier());
                    //chart.ChartModifiers.Add(new PinchZoomModifier());
                    //
                    linearLayoutC.Orientation = Orientation.Vertical;
                    linearLayoutL.Orientation = Orientation.Vertical;
                    linearLayoutC.AddView(chart);
                    linearLayoutL.AddView(legend);
                    progress.Dismiss();
                }
                catch (Exception ex)
                {
                    progress.Dismiss();
                    Toast.MakeText(this, ex.Message, ToastLength.Short).Show();
                }
            }
        }
    }
    private StackedColumnRenderableSeries GetRenderableSeries(IDataSeries dataSeries, uint fillColor, uint strokeColor)
    {
        return new StackedColumnRenderableSeries
        {
            DataSeries = dataSeries,
            StrokeStyle = new SolidPenStyle(this, strokeColor),
            FillBrushStyle = new SolidBrushStyle(fillColor)
        };
    }

    //BackButton
    public override bool OnOptionsItemSelected(IMenuItem item)
    {
        if (item.ItemId == Android.Resource.Id.Home) ;
        {
            Finish();
        }
        return base.OnOptionsItemSelected(item);
    }
}

  • Yura Khariton
    Unfortunately your code contains some missing types so I couldn’t use it to create a project and debug it on my PC. Can you try to simplify it so I could compile it or attach entire project? Maybe you can modify one of our examples and reproduce this issue there? The only thing which I noticed without compilation is that for some reasons you apply negative GrowBy for your xAxis (0.0175, -0.0175) when there are more than 1 point which leads to reducing of VisibleRange and as result columns at the edges could be drawn outside viewport. Please can you recheck this code?
  • You must to post comments
0
0

Te envío el código editado donde replique el error. La idea es que los datos sean mensuales.

In the FOR tests with:
//ERROR
for (var i = 0; i < 1; i++)
{
Fecha= date.AddMonths(i);

            PotenciaDataSeries.Append(Fecha, Potencia[i]);
            EnergiaHoraPuntaDataSeries.Append(Fecha, EnergiaHoraPunta[i]);
            EnergiaHoraFueraPuntaDataSeries.Append(Fecha, EnergiaHoraFueraPunta[i]);
            PrecioMedioDataSeries.Append(Fecha, PrecioMedio[i]);
            PCSPTDataSeries.Append(Fecha, PCSPT[i]);
            SSTDataSeries.Append(Fecha, SST[i]);
        }

//CORRECT
for (var i = 0; i < 4; i++)
{
Fecha= date.AddMonths(i);

            PotenciaDataSeries.Append(Fecha, Potencia[i]);
            EnergiaHoraPuntaDataSeries.Append(Fecha, EnergiaHoraPunta[i]);
            EnergiaHoraFueraPuntaDataSeries.Append(Fecha, EnergiaHoraFueraPunta[i]);
            PrecioMedioDataSeries.Append(Fecha, PrecioMedio[i]);
            PCSPTDataSeries.Append(Fecha, PCSPT[i]);
            SSTDataSeries.Append(Fecha, SST[i]);
        }

using Android.Views;
using Java.Lang;
using SciChart.Charting.Model.DataSeries;
using SciChart.Charting.Modifiers;
using SciChart.Charting.Numerics.LabelProviders;
using SciChart.Charting.Visuals;
using SciChart.Charting.Visuals.Axes;
using SciChart.Charting.Visuals.RenderableSeries;
using SciChart.Core.Utility;
using SciChart.Data.Model;
using SciChart.Drawing.Common;
using SciChart.Examples.Demo.Fragments.Base;
using System;
using Xamarin.Examples.Demo.Droid.Fragments.Base;

namespace Xamarin.Examples.Demo.Droid.Fragments.Examples
{
[ExampleDefinition(“Stacked Column Side By Side Chart”, description: “A Stacked Column chart with columns grouped side by side”, icon: ExampleIcon.StackedColumn)]
public class StackedColumnSideBySideFragment : ExampleBaseFragment
{
public SciChartSurface Surface => View.FindViewById(Resource.Id.chart);

    public override int ExampleLayoutId => Resource.Layout.Example_Single_Chart_Fragment;

    protected override void InitExample()
    {
        var xAxis = new DateAxis(Activity)
        {
        };
        var yAxis = new NumericAxis(Activity)
        {
            AutoRange = AutoRange.Always,
            AxisTitle = "billions of People",
            GrowBy = new DoubleRange(0, 0.1),
            DrawMajorBands = true,
        };

        var EnergiaHoraFueraPunta = new[] { 1.269, 1.330, 1.356, 1.304 };
        var EnergiaHoraPunta = new[] { 1.004, 1.173, 1.236, 1.656 };
        var PrecioMedio = new[] { 0.282, 0.310, 0.319, 0.439 };
        var PCSPT = new[] { 0.214, 0.243, 0.254, 0.313 };
        var Potencia = new[] { 0.176, 0.201, 0.203, 0.261 };
        var SST = new[] { 0.176, 0.201, 0.203, 0.261 };

        var PotenciaDataSeries = new XyDataSeries<DateTime, double> { SeriesName = "Potencia" };
        var EnergiaHoraPuntaDataSeries = new XyDataSeries<DateTime, double> { SeriesName = "Energia Hora Punta" };
        var EnergiaHoraFueraPuntaDataSeries = new XyDataSeries<DateTime, double> { SeriesName = "Energia Hora Fuera Punta" };
        var PrecioMedioDataSeries = new XyDataSeries<DateTime, double> { SeriesName = "Precio Medio" };
        var PCSPTDataSeries = new XyDataSeries<DateTime, double> { SeriesName = "PCSPT" };
        var SSTDataSeries = new XyDataSeries<DateTime, double> { SeriesName = "SST" };

        DateTime date = DateTime.Now;
        DateTime Fecha;

         //Probar
        //for (var i = 0; i < 4; i++)
        for (var i = 0; i < 1; i++)
        {
            Fecha= date.AddMonths(i);

            PotenciaDataSeries.Append(Fecha, Potencia[i]);
            EnergiaHoraPuntaDataSeries.Append(Fecha, EnergiaHoraPunta[i]);
            EnergiaHoraFueraPuntaDataSeries.Append(Fecha, EnergiaHoraFueraPunta[i]);
            PrecioMedioDataSeries.Append(Fecha, PrecioMedio[i]);
            PCSPTDataSeries.Append(Fecha, PCSPT[i]);
            SSTDataSeries.Append(Fecha, SST[i]);
        }
        //
        var columnsCollection = new HorizontallyStackedColumnsCollection();

        columnsCollection.Add(GetRenderableSeries(PotenciaDataSeries, 0xff7cb5ec, 0xff7cb5ec));
        columnsCollection.Add(GetRenderableSeries(EnergiaHoraPuntaDataSeries, 0xFF434348, 0xFF434348));
        columnsCollection.Add(GetRenderableSeries(EnergiaHoraFueraPuntaDataSeries, 0xFF90ed7d, 0xFF90ed7d));
        columnsCollection.Add(GetRenderableSeries(PrecioMedioDataSeries, 0xFFf7a35c, 0xFFf7a35c));
        columnsCollection.Add(GetRenderableSeries(PCSPTDataSeries, 0xFF8085e9, 0xFF8085e9));
        columnsCollection.Add(GetRenderableSeries(SSTDataSeries, 0xfff15c80, 0xfff15c80));

        var legendModifier = new LegendModifier(Activity);
        legendModifier.SetLegendPosition(GravityFlags.Top | GravityFlags.Left, 10);

        using (Surface.SuspendUpdates())
        {
            Surface.XAxes.Add(xAxis);
            Surface.YAxes.Add(yAxis);
            Surface.RenderableSeries.Add(columnsCollection);
            Surface.ChartModifiers.Add(legendModifier);
            Surface.ChartModifiers.Add(new TooltipModifier());
        }
    }

    private StackedColumnRenderableSeries GetRenderableSeries(IDataSeries dataSeries, uint fillColor, uint strokeColor)
    {
        return new StackedColumnRenderableSeries
        {
            DataSeries = dataSeries,
            StrokeStyle = new SolidPenStyle(Activity, strokeColor),
            FillBrushStyle = new SolidBrushStyle(fillColor)
        };
    }
}

}


Thank You.

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.