Example #1
0
        protected async Task HandleRedraw()
        {
            await CargaDatos();

            await lineChartTemperature.Clear();

            await lineChartTemperature.Update();

            StateHasChanged();
            await lineChartTemperature.AddLabel(Labels);

            await lineChartTemperature.AddDataSet(GetLineChartTemperatureDataset());

            await lineChartTemperature.Update();

            StateHasChanged();

            await lineChartHumity.Clear();

            await lineChartHumity.Update();

            StateHasChanged();
            await lineChartHumity.AddLabel(Labels);

            await lineChartHumity.AddDataSet(GetLineChartHumityDataset());

            await lineChartHumity.Update();

            StateHasChanged();
            //await JSRuntime.InvokeVoidAsync("resizeEvent", new object[] { });
        }
Example #2
0
        private async Task CargarGrafica()
        {
            await graficaTemperatura.Clear();

            await graficaTemperatura.AddLabel(Labels);

            int indiceColor = 0;                                              // -- indice utilizado en el array de colores para que cada sensor (dataset) tenga un color

            foreach (var datosSensor in listaDatosTemp.OrderBy(_ => _.Item1)) // -- datasets ordenados por nombre de sensor
            {
                await graficaTemperatura.AddDataSet(ObtenerDataSet(datosSensor.Item1, datosSensor.Item2, indiceColor));

                indiceColor = (indiceColor + 1) % coloresGraficas.Count();
            }
            await graficaTemperatura.Update();

            StateHasChanged();

            await graficaHumedad.Clear();

            await graficaHumedad.AddLabel(Labels);

            indiceColor = 0;
            foreach (var datosSensor in listaDatosHum.OrderBy(_ => _.Item1)) // -- datasets ordenados por nombre de sensor
            {
                await graficaHumedad.AddDataSet(ObtenerDataSet(datosSensor.Item1, datosSensor.Item2, indiceColor));

                indiceColor = (indiceColor + 1) % coloresGraficas.Count();
            }
            await graficaHumedad.Update();

            StateHasChanged();
        }
Example #3
0
        private void FillChart(LineChart volume, string property, double correctionFactor, string color1, string color2)
        {
            // create values, we want to end up with nine years of data, where the first year starts with the current date nine years back

            // we determine 52 datapoints per year (every seventh day), find out how many there are in the first and current year
            // thats the number of datapoints we'll use for the first year
            var thisYearPoints  = (DateTime.Now.DayOfYear / 4) + 1;
            var firstYearPoints = 91 - thisYearPoints;

            int closingValue = 0;

            // create datasets for last 8 years (including the current year)
            for (int i = DateTime.Now.Year - 10; i <= DateTime.Now.Year; i++)
            {
                List <int> values = new List <int>
                {
                    closingValue
                };

                // get values
                for (int j = 1; j < 92; j++)
                {
                    var    pointDate = new DateTime(i, 1, 1).AddDays(j * 4);
                    double total     = 0;

                    total = property switch
                    {
                        "Distance" => Activities.Where(a => a.Date > pointDate.AddDays(-28) && a.Date <= pointDate).Sum(a => a.Distance),
                        "Climb" => Activities.Where(a => a.Date > pointDate.AddDays(-28) && a.Date <= pointDate).Sum(a => a.Climb),
                        _ => 0,
                    };
                    values.Add((int)Math.Round(total / 28 / correctionFactor));  // 28 for average
                }

                // if this is the first year, slice that year up to the current date
                if (i == DateTime.Now.Year - 10)
                {
                    values = values.TakeLast(firstYearPoints).ToList();
                }

                //if this is the current year, slice of the remainder of the year
                if (i == DateTime.Now.Year)
                {
                    values = values.Take(thisYearPoints + 2).ToList();
                }

                // create dataset
                var dataSet = new LineChart.DataSet
                {
                    Name   = i.ToString(),
                    Color  = AlternatingColor(i, color1, color2),
                    Values = values
                };

                volume.AddDataSet(dataSet);

                closingValue = values.Last();
            }
        }
Example #4
0
        //protected override async Task OnAfterRenderAsync()
        //{
        //    await HandleRedraw();
        //}

        async Task HandleRedraw()
        {
            lineChart.Clear();

            lineChart.AddLabel(Labels);

            lineChart.AddDataSet(GetLineChartDataset());

            await lineChart.Update();
        }
Example #5
0
        async Task AddNewVerticalLineDataSet()
        {
            var colorIndex = verticalLineChart.Data.Datasets.Count % backgroundColors.Count;

            await verticalLineChart.AddDataSet(new LineChartDataset <LiveDataPoint>
            {
                Data            = new List <LiveDataPoint>(),
                Label           = $"Dataset {verticalLineChart.Data.Datasets.Count + 1}",
                BackgroundColor = backgroundColors[colorIndex],
                BorderColor     = borderColors[colorIndex],
                Fill            = false,
                LineTension     = 0,
            });

            await verticalLineChart.Update();
        }
Example #6
0
        public async Task RefreshChartData()
        {
            IEnumerable <DashboardChartData> newDatas = await GenerateChartDatas.Invoke();

            await Chart.Clear();

            await Chart.AddLabels(newDatas.Select(x => x.Label).ToArray());

            List <string> colors = new List <string>();

            for (int i = 0; i < newDatas.Count(); i++)
            {
                string lineColor = PointColorGenerator?.Invoke(i);
                if (!string.IsNullOrWhiteSpace(lineColor))
                {
                    colors.Add(lineColor);
                }
                else
                {
                    colors.Add(DEFAULT_POINT_COLOR);
                }
            }

            LineChartDataset <DashboardChartDatasetYValue> newChartDataset = new LineChartDataset <DashboardChartDatasetYValue>()
            {
                Data = newDatas.Select(x => new DashboardChartDatasetYValue()
                {
                    Y = x.Value, DataId = x.DataId
                }).ToList(),
                Fill                 = true,
                BackgroundColor      = DEFAULT_FILL_COLOR,
                PointBackgroundColor = colors,
                PointBorderColor     = colors,
                PointRadius          = 3.5f
            };

            CurrentDataset = newChartDataset;
            await Chart.AddDataSet(newChartDataset);

            await Chart.Update();
        }