コード例 #1
0
        public DashboardGraphString GetGraphsString()
        {
            var graphs = new DashboardGraphString();

            if (_context.Dashboards.Count() > 0)
            {
                // Přepověď teploty a srážek
                if (_context.WeatherForecast != null)
                {
                    var weatherForecastId = _context.WeatherForecast.LastOrDefault().Id;

                    var hourlyForecast = _context.WeatherForecastHourlyState.Where(t => t.WeatherForecastId == weatherForecastId)
                                         .OrderBy(m => m.DateTime);

                    // Graf venkovní teploty a srážek
                    var cmlChart = new CMLChart();

                    //cmlChart.Label = "Předpověď počasí";

                    cmlChart.AsixXPaint = new SKPaint {
                        TextSize = 10, Color = SKColors.White
                    };
                    cmlChart.AsixYPaint = new SKPaint {
                        TextSize = 12, Color = SKColors.White
                    };
                    cmlChart.BarPaint = new SKPaint {
                        TextSize = 10, Color = SKColors.White
                    };
                    cmlChart.LinePaint = new SKPaint {
                        TextSize = 10, Color = SKColors.White
                    };
                    cmlChart.TitlePaint = new SKPaint {
                        TextSize = 14, Color = SKColors.White
                    };
                    cmlChart.BorderPaint = new SKPaint {
                        TextSize = 10, Color = SKColors.Black
                    };

                    var horly = hourlyForecast.Select(t => t.DateTime.Hour.ToString()).ToArray();
                    cmlChart.XAsix = new CMLChartXAsix(horly, CMLValuesType.Hourly);

                    var temperatureForecastValues   = hourlyForecast.Select(t => t.Temperature).ToArray();
                    var precipitationForecastValues = hourlyForecast.Select(t => t.Rain + t.Snow).ToArray();

                    cmlChart.YAsixs = new List <CMLChartYAsix>();
                    cmlChart.YAsixs.Add(new CMLChartYAsix("Teplota (°C)", true, Color.Black, Color.Black, temperatureForecastValues, 1, PresentationType.Line, Location.Left, true));
                    cmlChart.YAsixs.Add(new CMLChartYAsix("Srážky (mm)", true, Color.Black, Color.Black, precipitationForecastValues, 2, PresentationType.Bar, Location.Right, false));

                    // Nastavení maximalní hodnoty na ose Y pro výše srážek. Ostaní min/max jsou defaultně min/max hodnoty
                    cmlChart.YAsixs.Where(t => t.Id == 1).FirstOrDefault().MinValue = Math.Min(0, temperatureForecastValues.Min());;
                    cmlChart.YAsixs.Where(t => t.Id == 2).FirstOrDefault().MaxValue = 4;

                    // :TODO: nastavit hodnoty velikosti obrázku grafu
                    int width            = 400;
                    int height           = 200;
                    var chartImageBitmap = cmlChart.GetBitmap(width, height);

                    var bitmapConvert = new BitmapConvert(chartImageBitmap);
                    graphs.OutdoorTemperatureGraphString = bitmapConvert.GetBitmapByString();
                }
            }
            return(graphs);
        }