// // GET: /HighChartsSampleModel/ public ActionResult Index() { var highchartSample = new List<HighChartsSampleModel> { new HighChartsSampleModel() {Parameters = "Event", GoodScore = 23.45D, AverageScore = 15.32D,BadScore = 9.4D,ActualScore=78.33D}, new HighChartsSampleModel() {Parameters = "Weather",GoodScore=45.67D,AverageScore = 33.24D,BadScore = 12.23D,ActualScore = 56.22D}, new HighChartsSampleModel() {Parameters = "User Review",GoodScore=67.23D,AverageScore = 31.23D,BadScore = 10.11D,ActualScore = 29.44D}, new HighChartsSampleModel() {Parameters = "Tweets",GoodScore = 89.67D,AverageScore = 12.33D,BadScore = 3.43D,ActualScore = 88.11D}, new HighChartsSampleModel() {Parameters = "Persona",GoodScore=38.34D,AverageScore = 25.34D,BadScore = 16.43D,ActualScore = 35.08D}, new HighChartsSampleModel() {Parameters = "Crime",GoodScore=38.34D,AverageScore = 25.34D,BadScore = 16.43D,ActualScore = 24.87D} }; var xDataParameters = highchartSample.Select(i => i.Parameters).ToArray(); var actualScore = highchartSample.Select(i => i.ActualScore); var chart = new Highcharts("chart"); chart.InitChart(new Chart { DefaultSeriesType = ChartTypes.Bar }); chart.SetTitle(new Title { Text = "Risk Score Profiling" }); chart.SetSubtitle(new Subtitle { Text = "Risk predicting using social media" }); chart.SetXAxis(new XAxis { Categories = xDataParameters }); chart.SetYAxis(new YAxis { Title = new YAxisTitle { Text = "Scores" }, Max = 100 }); chart.SetLegend(new Legend { Enabled = false, }); chart.SetTooltip(new Tooltip { Enabled = true, Formatter = @"function(){return '<b>' + this.series.name +'</b><br/>' + this.x+':' + this.y;}" }); chart.SetPlotOptions(new PlotOptions { //Series = new PlotOptionsSeries() { Stacking = Stackings.Normal }, Bar = new PlotOptionsBar { DataLabels = new PlotOptionsBarDataLabels { Enabled = true,Color = Color.Maroon,Shadow = true}, //PointWidth = 10, //GroupPadding = 1, //PointPadding = 0, Shadow = true, BorderWidth = 1, BorderColor = Color.FloralWhite, } }); Data data = new Data( actualScore.Select(y => new Point { Color = GetBarColor(y), Y = y}).ToArray() ); chart.SetSeries(new Series { Name = "Actual Score", Data = data }); return View(chart); }
/// <summary> /// Conductivity Plot /// </summary> /// <param name="USGSSource1ID">USGS Source1 ID</param> /// <returns>Returns the view</returns> public JsonResult ConductivityPlot(long USGSID) { try { List<water_data> wd = new List<water_data>(); wd = this.modifiedCondRepository.GetWaterSourceData(USGSID); Dictionary<DateTime, int?> ChartData = new Dictionary<DateTime, int?>(); Data data1 = new Data(new object[] { }); int[] d = new int[wd.Count]; DateTime pointstart; object[,] chartData = new object[wd.Count, 2]; int i = 0; foreach (var item in wd) { if (!string.IsNullOrWhiteSpace(item.measurment_date)) { ChartData.Add(Convert.ToDateTime(item.measurment_date, new CultureInfo("en-US", true)), item.cond); } d[i] = Convert.ToInt32(item.cond); if (!string.IsNullOrWhiteSpace(wd[0].measurment_date) && DateTime.TryParse(wd[0].measurment_date, new CultureInfo("en-US", true), DateTimeStyles.AdjustToUniversal, out pointstart)) { pointstart = Convert.ToDateTime(wd[0].measurment_date, new CultureInfo("en-US", true)); } chartData.SetValue(item.measurment_date, i, 0); chartData.SetValue(item.cond, i, 1); i++; } return Json(ChartData.ToList(), JsonRequestBehavior.AllowGet); } catch { throw; } }
public ActionResult _Chart(DateTime paramFromDate, DateTime paramToDate, string station, string displayOption, string chartOption, string tempParam) { var a = new Data(BaseLineRepo.GetDataForBaseLineChart(station, paramFromDate, paramToDate, displayOption, "AirPolutionLevel")); if (chartOption == "Single Station") { return PartialView(new SmartCity.Models.BaseLineModel { highChart = BasicLineSingleStation( displayOption+ " Average AirPollution, MinTemp, MaxTemp, and RainFall", new Data(BaseLineRepo.GetDataForBaseLineChart(station, paramFromDate, paramToDate, displayOption, "AirPolutionLevel")), new Data(BaseLineRepo.GetDataForBaseLineChart(station, paramFromDate, paramToDate, displayOption, "MinTemp")), new Data(BaseLineRepo.GetDataForBaseLineChart(station, paramFromDate, paramToDate, displayOption, "MaxTemp")), new Data(BaseLineRepo.GetDataForBaseLineChart(station, paramFromDate, paramToDate, displayOption, "RainFall")), displayOption == "Yearly" ? CustomChartsData.CategoryYear : displayOption == "Weekly" ? CustomChartsData.CategoryWeek : CustomChartsData.CategoryMonth ) }); } else { string[] stationList = station.Split(','); return PartialView(new SmartCity.Models.BaseLineModel { highChart = BasicLineMultipleStation( displayOption+ " " + tempParam, new PairModel { Key = stationList[0], Value = new Data(BaseLineRepo.GetDataForBaseLineChart(stationList[0], paramFromDate, paramToDate, displayOption, tempParam)) }, new PairModel { Key = stationList[1], Value = new Data(BaseLineRepo.GetDataForBaseLineChart(stationList[1], paramFromDate, paramToDate, displayOption, tempParam)) }, new PairModel { Key = stationList[2], Value = new Data(BaseLineRepo.GetDataForBaseLineChart(stationList[2], paramFromDate, paramToDate, displayOption, tempParam)) }, new PairModel { Key = stationList[3], Value = new Data(BaseLineRepo.GetDataForBaseLineChart(stationList[3], paramFromDate, paramToDate, displayOption, tempParam)) }, displayOption == "Yearly" ? CustomChartsData.CategoryYear : displayOption == "Weekly" ? CustomChartsData.CategoryWeek : CustomChartsData.CategoryMonth ) }); } }
// // GET: /Home/ public ActionResult Index() { DbDataContext dt = new DbDataContext(); //Fetching data from db: var voltageValues = dt.Values.Where(v => v.FieldName == "Voltage").OrderBy(v => v.Datetime).ToList<Value>(); var currentValues = dt.Values.Where(v => v.FieldName == "Current").OrderBy(v => v.Datetime).ToList<Value>(); Highcharts Chart = new Highcharts("Chart"); // Initiizing chart // Making month and days persian, however it is not accurate at all! Chart.SetOptions(new GlobalOptions { Lang = new DotNet.Highcharts.Helpers.Lang { Loading = "در حال بارگذاری", Months = new string[] { "فروردین", "اردیبهشت", "خرداد", "تیر", "مرداد", "شهریور", "مهر", "آبان", "آذر", "دی", "بهمن", "اسفند" }, Weekdays = new string[] { "شنبه", "یک شنبه", "دوشنبه", "سه شنبه", "چهارشنبه", "پنج شنبه", "جمعه" }, ShortMonths = new string[] { "فرور", "اردی", "خرداد", "تیر", "مرداد", "شهریور", "مهر", "آبان", "آذر", "دی", "بهمن", "اسفند" } } }); Chart.InitChart(new Chart { DefaultSeriesType = ChartTypes.Line, MarginRight = 130, MarginBottom = 55, ClassName = "chart", ZoomType = ZoomTypes.X }) .SetTitle(new Title { Text = "نمودار تغییرات داده ها " }) .SetSubtitle(new Subtitle { Text = "نمونه استفاده نمودار", X = -20 }) .SetXAxis(new XAxis { Type = AxisTypes.Datetime, Title = new XAxisTitle { Text = "بازه زمانی از ... تا..." }, MinorTickInterval = 3600 * 1000, TickLength = 1, MinRange = 3600 * 1000, MinTickInterval = 3600 * 1000, GridLineWidth = 1, Labels = new XAxisLabels { Align = HorizontalAligns.Right, Rotation = -30, }, DateTimeLabelFormats = new DateTimeLabel { Second = "%H:%M:%S", Minute = "%H:%M", Hour = "%H:%M", Day = "%e %b", Week = "%e %b", Month = "%b", Year = "%Y", }, ShowEmpty = false, }) .SetLegend(new Legend { Layout = Layouts.Vertical, Align = HorizontalAligns.Left, X = 20, VerticalAlign = VerticalAligns.Top, Y = 80, BackgroundColor = new BackColorOrGradient(System.Drawing.ColorTranslator.FromHtml("#FFFFFF")) }); YAxis[] yAxis = new YAxis[2]; yAxis[0] = (new YAxis { Title = new YAxisTitle { Text = string.Format("{0} ({1})", "Voltage", "V"), }, Labels = new YAxisLabels { //Align = HorizontalAligns.Right, Formatter = "function() { return this.value; }", }, Opposite = true, GridLineWidth = 0 }); yAxis[1] = (new YAxis { Title = new YAxisTitle { Text = string.Format("{0} ({1})", "Current", "A"), }, Labels = new YAxisLabels { //Align = HorizontalAligns.Left, Formatter = "function() { return this.value; }", }, Opposite = false, GridLineWidth = 1 }); Chart.SetYAxis(yAxis); Series[] seriesOfData = new Series[2]; object[,] x1 = new object[voltageValues.Count(), 2]; for (int i = 0; i < voltageValues.Count(); i++) { x1[i, 0] = PersianDateTime.ParseFromDateTime(voltageValues[i].Datetime).ToString("Date.parse('MM/dd/yyyy HH:mm:ss')"); x1[i, 1] = voltageValues[i].Value1; } DotNet.Highcharts.Helpers.Data data1 = new DotNet.Highcharts.Helpers.Data(x1); Series series1 = new Series { Name = "Voltage", Data = data1, Type = ChartTypes.Line, }; series1.YAxis = "0"; seriesOfData[0] = series1; object[,] x2 = new object[currentValues.Count(), 2]; for (int i = 0; i < voltageValues.Count(); i++) { x2[i, 0] = PersianDateTime.ParseFromDateTime(voltageValues[i].Datetime).ToString("Date.parse('MM/dd/yyyy HH:mm:ss')"); x2[i, 1] = currentValues[i].Value1; } DotNet.Highcharts.Helpers.Data data2 = new DotNet.Highcharts.Helpers.Data(x2); Series series2 = new Series { Name = "Current", Data = data2, Type = ChartTypes.Spline, }; series1.YAxis = "1"; seriesOfData[1] = series2; Chart.SetSeries(seriesOfData); ViewBag.Chart = Chart; return View(); }
// // GET: /Home/ public ActionResult Index() { DbDataContext dt = new DbDataContext(); //Fetching data from db: var voltageValues = dt.Values.Where(v => v.FieldName == "Voltage").OrderBy(v => v.Datetime).ToList <Value>(); var currentValues = dt.Values.Where(v => v.FieldName == "Current").OrderBy(v => v.Datetime).ToList <Value>(); Highcharts Chart = new Highcharts("Chart"); // Initiizing chart // Making month and days persian, however it is not accurate at all! Chart.SetOptions(new GlobalOptions { Lang = new DotNet.Highcharts.Helpers.Lang { Loading = "در حال بارگذاری", Months = new string[] { "فروردین", "اردیبهشت", "خرداد", "تیر", "مرداد", "شهریور", "مهر", "آبان", "آذر", "دی", "بهمن", "اسفند" }, Weekdays = new string[] { "شنبه", "یک شنبه", "دوشنبه", "سه شنبه", "چهارشنبه", "پنج شنبه", "جمعه" }, ShortMonths = new string[] { "فرور", "اردی", "خرداد", "تیر", "مرداد", "شهریور", "مهر", "آبان", "آذر", "دی", "بهمن", "اسفند" } } }); Chart.InitChart(new Chart { DefaultSeriesType = ChartTypes.Line, MarginRight = 130, MarginBottom = 55, ClassName = "chart", ZoomType = ZoomTypes.X }) .SetTitle(new Title { Text = "نمودار تغییرات داده ها " }) .SetSubtitle(new Subtitle { Text = "نمونه استفاده نمودار", X = -20 }) .SetXAxis(new XAxis { Type = AxisTypes.Datetime, Title = new XAxisTitle { Text = "بازه زمانی از ... تا..." }, MinorTickInterval = 3600 * 1000, TickLength = 1, MinRange = 3600 * 1000, MinTickInterval = 3600 * 1000, GridLineWidth = 1, Labels = new XAxisLabels { Align = HorizontalAligns.Right, Rotation = -30, }, DateTimeLabelFormats = new DateTimeLabel { Second = "%H:%M:%S", Minute = "%H:%M", Hour = "%H:%M", Day = "%e %b", Week = "%e %b", Month = "%b", Year = "%Y", }, ShowEmpty = false, }) .SetLegend(new Legend { Layout = Layouts.Vertical, Align = HorizontalAligns.Left, X = 20, VerticalAlign = VerticalAligns.Top, Y = 80, BackgroundColor = new BackColorOrGradient(System.Drawing.ColorTranslator.FromHtml("#FFFFFF")) }); YAxis[] yAxis = new YAxis[2]; yAxis[0] = (new YAxis { Title = new YAxisTitle { Text = string.Format("{0} ({1})", "Voltage", "V"), }, Labels = new YAxisLabels { //Align = HorizontalAligns.Right, Formatter = "function() { return this.value; }", }, Opposite = true, GridLineWidth = 0 }); yAxis[1] = (new YAxis { Title = new YAxisTitle { Text = string.Format("{0} ({1})", "Current", "A"), }, Labels = new YAxisLabels { //Align = HorizontalAligns.Left, Formatter = "function() { return this.value; }", }, Opposite = false, GridLineWidth = 1 }); Chart.SetYAxis(yAxis); Series[] seriesOfData = new Series[2]; object[,] x1 = new object[voltageValues.Count(), 2]; for (int i = 0; i < voltageValues.Count(); i++) { x1[i, 0] = PersianDateTime.ParseFromDateTime(voltageValues[i].Datetime).ToString("Date.parse('MM/dd/yyyy HH:mm:ss')"); x1[i, 1] = voltageValues[i].Value1; } DotNet.Highcharts.Helpers.Data data1 = new DotNet.Highcharts.Helpers.Data(x1); Series series1 = new Series { Name = "Voltage", Data = data1, Type = ChartTypes.Line, }; series1.YAxis = "0"; seriesOfData[0] = series1; object[,] x2 = new object[currentValues.Count(), 2]; for (int i = 0; i < voltageValues.Count(); i++) { x2[i, 0] = PersianDateTime.ParseFromDateTime(voltageValues[i].Datetime).ToString("Date.parse('MM/dd/yyyy HH:mm:ss')"); x2[i, 1] = currentValues[i].Value1; } DotNet.Highcharts.Helpers.Data data2 = new DotNet.Highcharts.Helpers.Data(x2); Series series2 = new Series { Name = "Current", Data = data2, Type = ChartTypes.Spline, }; series1.YAxis = "1"; seriesOfData[1] = series2; Chart.SetSeries(seriesOfData); ViewBag.Chart = Chart; return(View()); }
public ActionResult ColumnWithDrilldown() { string[] categories = new[] { "MSIE", "Firefox", "Chrome", "Safari", "Opera" }; const string NAME = "Browser brands"; Data data = new Data(new[] { new Point { Y = 55.11, Color = Color.FromName("colors[0]"), Drilldown = new Drilldown { Name = "MSIE versions", Categories = new[] { "MSIE 6.0", "MSIE 7.0", "MSIE 8.0", "MSIE 9.0" }, Data = new Data(new object[] { 10.85, 7.35, 33.06, 2.81 }), Color = Color.FromName("colors[0]") } }, new Point { Y = 21.63, Color = Color.FromName("colors[1]"), Drilldown = new Drilldown { Name = "Firefox versions", Categories = new[] { "Firefox 2.0", "Firefox 3.0", "Firefox 3.5", "Firefox 3.6", "Firefox 4.0" }, Data = new Data(new object[] { 0.20, 0.83, 1.58, 13.12, 5.43 }), Color = Color.FromName("colors[1]") } }, new Point { Y = 11.94, Color = Color.FromName("colors[2]"), Drilldown = new Drilldown { Name = "Chrome versions", Categories = new[] { "Chrome 5.0", "Chrome 6.0", "Chrome 7.0", "Chrome 8.0", "Chrome 9.0", "Chrome 10.0", "Chrome 11.0", "Chrome 12.0" }, Data = new Data(new object[] { 0.12, 0.19, 0.12, 0.36, 0.32, 9.91, 0.50, 0.22 }), Color = Color.FromName("colors[2]") } }, new Point { Y = 7.15, Color = Color.FromName("colors[3]"), Drilldown = new Drilldown { Name = "Safari versions", Categories = new[] { "Safari 5.0", "Safari 4.0", "Safari Win 5.0", "Safari 4.1", "Safari/Maxthon", "Safari 3.1", "Safari 4.1" }, Data = new Data(new object[] { 4.55, 1.42, 0.23, 0.21, 0.20, 0.19, 0.14 }), Color = Color.FromName("colors[3]") } }, new Point { Y = 2.14, Color = Color.FromName("colors[4]"), Drilldown = new Drilldown { Name = "Opera versions", Categories = new[] { "Opera 9.x", "Opera 10.x", "Opera 11.x" }, Data = new Data(new object[] { 0.12, 0.37, 1.65 }), Color = Color.FromName("colors[4]") } } }); Highcharts chart = new Highcharts("chart") .InitChart(new Chart { DefaultSeriesType = ChartTypes.Column }) .SetTitle(new Title { Text = "Browser market share, April, 2011" }) .SetSubtitle(new Subtitle { Text = "Click the columns to view versions. Click again to view brands." }) .SetXAxis(new XAxis { Categories = categories }) .SetYAxis(new YAxis { Title = new YAxisTitle { Text = "Total percent market share" } }) .SetLegend(new Legend { Enabled = false }) .SetTooltip(new Tooltip { Formatter = "TooltipFormatter" }) .SetPlotOptions(new PlotOptions { Column = new PlotOptionsColumn { Cursor = Cursors.Pointer, Point = new PlotOptionsColumnPoint { Events = new PlotOptionsColumnPointEvents { Click = "ColumnPointClick" } }, DataLabels = new PlotOptionsColumnDataLabels { Enabled = true, Color = Color.FromName("colors[0]"), Formatter = "function() { return this.y +'%'; }", Style = "fontWeight: 'bold'" } } }) .SetSeries(new Series { Name = "Browser brands", Data = data, Color = Color.White }) .SetExporting(new Exporting { Enabled = false }) .AddJavascripFunction( "TooltipFormatter", @"var point = this.point, s = this.x +':<b>'+ this.y +'% market share</b><br/>'; if (point.drilldown) { s += 'Click to view '+ point.category +' versions'; } else { s += 'Click to return to browser brands'; } return s;" ) .AddJavascripFunction( "ColumnPointClick", @"var drilldown = this.drilldown; if (drilldown) { // drill down setChart(drilldown.name, drilldown.categories, drilldown.data.data, drilldown.color); } else { // restore setChart(name, categories, data.data); }" ) .AddJavascripFunction( "setChart", @"chart.xAxis[0].setCategories(categories); chart.series[0].remove(); chart.addSeries({ name: name, data: data, color: color || 'white' });", "name", "categories", "data", "color" ) .AddJavascripVariable("colors", "Highcharts.getOptions().colors") .AddJavascripVariable("name", "'{0}'".FormatWith(NAME)) .AddJavascripVariable("categories", JsonSerializer.Serialize(categories)) .AddJavascripVariable("data", JsonSerializer.Serialize(data)); return View(chart); }
public ActionResult DonutChart() { string[] categories = new[] { "MSIE", "Firefox", "Chrome", "Safari", "Opera" }; Data data = new Data(new[] { new Point { Y = 55.11, Color = Color.FromName("colors[0]"), Drilldown = new Drilldown { Name = "MSIE versions", Categories = new[] { "MSIE 6.0", "MSIE 7.0", "MSIE 8.0", "MSIE 9.0" }, Data = new Data(new object[] { 10.85, 7.35, 33.06, 2.81 }), Color = Color.FromName("colors[0]") } }, new Point { Y = 21.63, Color = Color.FromName("colors[1]"), Drilldown = new Drilldown { Name = "Firefox versions", Categories = new[] { "Firefox 2.0", "Firefox 3.0", "Firefox 3.5", "Firefox 3.6", "Firefox 4.0" }, Data = new Data(new object[] { 0.20, 0.83, 1.58, 13.12, 5.43 }), Color = Color.FromName("colors[1]") } }, new Point { Y = 11.94, Color = Color.FromName("colors[2]"), Drilldown = new Drilldown { Name = "Chrome versions", Categories = new[] { "Chrome 5.0", "Chrome 6.0", "Chrome 7.0", "Chrome 8.0", "Chrome 9.0", "Chrome 10.0", "Chrome 11.0", "Chrome 12.0" }, Data = new Data(new object[] { 0.12, 0.19, 0.12, 0.36, 0.32, 9.91, 0.50, 0.22 }), Color = Color.FromName("colors[2]") } }, new Point { Y = 7.15, Color = Color.FromName("colors[3]"), Drilldown = new Drilldown { Name = "Safari versions", Categories = new[] { "Safari 5.0", "Safari 4.0", "Safari Win 5.0", "Safari 4.1", "Safari/Maxthon", "Safari 3.1", "Safari 4.1" }, Data = new Data(new object[] { 4.55, 1.42, 0.23, 0.21, 0.20, 0.19, 0.14 }), Color = Color.FromName("colors[3]") } }, new Point { Y = 2.14, Color = Color.FromName("colors[4]"), Drilldown = new Drilldown { Name = "Opera versions", Categories = new[] { "Opera 9.x", "Opera 10.x", "Opera 11.x" }, Data = new Data(new object[] { 0.12, 0.37, 1.65 }), Color = Color.FromName("colors[4]") } } }); List<Point> browserData = new List<Point>(categories.Length); List<Point> versionsData = new List<Point>(); for (int i = 0; i < categories.Length; i++) { browserData.Add(new Point { Name = categories[i], Y = data.SeriesData[i].Y, Color = data.SeriesData[i].Color }); for (int j = 0; j < data.SeriesData[i].Drilldown.Categories.Length; j++) { Drilldown drilldown = data.SeriesData[i].Drilldown; versionsData.Add(new Point { Name = drilldown.Categories[j], Y = Number.GetNumber(drilldown.Data.ArrayData[j]), Color = drilldown.Color }); } } Highcharts chart = new Highcharts("chart") .InitChart(new Chart { DefaultSeriesType = ChartTypes.Pie }) .SetTitle(new Title { Text = "Browser market share, April, 2011" }) .SetSubtitle(new Subtitle { Text = "Total percent market share" }) .SetPlotOptions(new PlotOptions { Pie = new PlotOptionsPie { Shadow = false } }) .SetTooltip(new Tooltip { Formatter = @"function() { return '<b>'+ this.point.name +'</b>: '+ this.y +' %';}" }) .AddJavascripVariable("colors", "Highcharts.getOptions().colors") .SetSeries(new[] { new Series { Name = "Browsers", Data = new Data(browserData.ToArray()), PlotOptionsPie = new PlotOptionsPie { Size = new PercentageOrPixel(60, true), DataLabels = new PlotOptionsPieDataLabels { Formatter = "function() { return this.y > 5 ? this.point.name : null; }", Color = Color.White, Distance = -30 } } }, new Series { Name = "Versions", Data = new Data(versionsData.ToArray()), PlotOptionsPie = new PlotOptionsPie { InnerSize = new PercentageOrPixel(60, true), DataLabels = new PlotOptionsPieDataLabels { Formatter = "function() { return this.y > 1 ? '<b>'+ this.point.name +':</b> '+ this.y +'%' : null; }" } } } }); return View(chart); }
public ActionResult Forecast(int? id) { BudgetUser u = new BudgetUser(); // return list of budgets specific to one user u = db.BudgetUsers.Where(user => user.BudgetUserId == id).SingleOrDefault(); var total = from e in db.Budgets where e.BudgetUserId == id select e; int size = total.Count(); // ------------------- CHART AND FORECAST CALCULATIONS FOR BUDGET ANALYSIS CHARTS ------------------- // ******************* COLUMN BAR CHART - TOTAL EXPENDITURE (Month on Month) ******************* // Budget Names String[] budgetNames = new string[size]; int c1 = 0; foreach (var item in total) { budgetNames[c1] = item.BudgetName; c1++; } // Income object[] income = new object[size]; int c2 = 0; foreach (var item in total) { income[c2] = item.TotalIncome; c2++; } object[] expenditure1 = new object[size]; int c3 = 0; foreach (var item in total) { expenditure1[c3] = item.TotalExpenses; c3++; } // CAR var carExpenseTotal = 0.0; object[] car = new object[size]; int c5 = 0; foreach (var item in total) { car[c5] = item.TotalCarExpenses; carExpenseTotal += (double)item.TotalCarExpenses; c5++; } // calculate average of car expenses for all user budgets ViewBag.carAverage = carExpenseTotal / size; ViewBag.size = size; // HOUSEHOLD var householdExpenseTotal = 0.0; object[] household = new object[size]; int c6 = 0; foreach (var item in total) { household[c6] = item.TotalHouseholdExpenses; householdExpenseTotal += (double)item.TotalHouseholdExpenses; c6++; } // calculate average of the household expenses for all user budgets ViewBag.householdAverage = householdExpenseTotal / size; ViewBag.size = size; // PERSONAL var personalExpenseTotal = 0.0; object[] personal = new object[size]; int c7 = 0; foreach (var item in total) { personal[c7] = item.TotalPersonalExpenses; personalExpenseTotal += (double)item.TotalPersonalExpenses; c7++; } // calculate average of the personal expenses for all user budgets ViewBag.personalAverage = personalExpenseTotal / size; ViewBag.size = size; // TRAVEL var travelExpenseTotal = 0.0; object[] travel = new object[size]; int c8 = 0; foreach (var item in total) { travel[c8] = item.TotalTravelExpenses; travelExpenseTotal += (double)item.TotalTravelExpenses; c8++; } // calculate average of the travel expenses for all user budgets ViewBag.travelAverage = travelExpenseTotal / size; ViewBag.size = size; // UTILITY BILLS var utilityBillExpenseTotal = 0.0; object[] utilityBill = new object[size]; int c9 = 0; foreach (var item in total) { utilityBill[c9] = item.TotalUtilityBillExpenses; utilityBillExpenseTotal += (double)item.TotalUtilityBillExpenses; c9++; } // calculate average of the utility bill expenses for all user budgets ViewBag.utilityBillAverage = utilityBillExpenseTotal / size; ViewBag.size = size; Highcharts chart3 = new Highcharts("chart3") .InitChart(new Chart { DefaultSeriesType = ChartTypes.Column, MarginRight = 130, MarginBottom = 50, ClassName = "chart3" }) .SetTitle(new Title { Text = " Expenditure Totals (Month-On-Month) " }) .SetSubtitle(new Subtitle { Text = " Monthly Budget Analysis Chart " }) .SetXAxis(new XAxis { Categories = budgetNames }) .SetYAxis(new YAxis { Min = 0, Title = new YAxisTitle { Text = " Expenditure Total in € " } }) .SetLegend(new Legend { Y = 10, }) .SetPlotOptions(new PlotOptions { Column = new PlotOptionsColumn { PointPadding = 0.2, BorderWidth = 0 } }) .SetSeries(new[] { new Series { Name = "Monthly Income", Data = new Data(income)}, new Series { Name = "Monthly Expenditure", Data = new Data(expenditure1)} }) .SetCredits(new Credits { Enabled = false }); // ---------------------------- END OF COLUMN CHART ---------------------------- // DRILLDOWN string[] categories = { "Income", "Expenditure" }; const string NAME = "Forecast"; Data data = new Data(new[] { new Point { Y = 55.11, Color = Color.FromName("colors[0]"), Drilldown = new Drilldown { Name = "Monthly Income", Categories = new[] { "Car", "Household", "Personal", "Travel", "Utility Bill" }, Data = new Data(new object[] { 10.85, 7.35, 33.06, 2.81 }), Color = Color.FromName("colors[0]") } }, new Point { Y = 21.63, Color = Color.FromName("colors[1]"), Drilldown = new Drilldown { Name = "Monthly Expenditure", Categories = new[] { "Car", "Household", "Personal", "Travel", "Utility Bill" }, Data = new Data(new object[] { car, household, personal, travel, utilityBill }), Color = Color.FromName("colors[1]") } }, }); Highcharts chart = new Highcharts("chart") .InitChart(new Chart { DefaultSeriesType = ChartTypes.Column }) .SetTitle(new Title { Text = "Browser market share, April, 2011" }) .SetSubtitle(new Subtitle { Text = "Click the columns to view versions. Click again to view brands." }) .SetXAxis(new XAxis { Categories = categories }) .SetYAxis(new YAxis { Title = new YAxisTitle { Text = "Total percent market share" } }) .SetLegend(new Legend { Enabled = false }) .SetTooltip(new Tooltip { Formatter = "TooltipFormatter" }) .SetPlotOptions(new PlotOptions { Column = new PlotOptionsColumn { Cursor = Cursors.Pointer, Point = new PlotOptionsColumnPoint { Events = new PlotOptionsColumnPointEvents { Click = "ColumnPointClick" } }, DataLabels = new PlotOptionsColumnDataLabels { Enabled = true, Color = Color.FromName("colors[0]"), Formatter = "function() { return this.y +'%'; }", Style = "fontWeight: 'bold'" } } }) .SetSeries(new Series { Name = "Browser brands", Data = data, Color = Color.White }) .SetExporting(new Exporting { Enabled = false }) .AddJavascripFunction( "TooltipFormatter", @"var point = this.point, s = this.x +':<b>'+ this.y +'% market share</b><br/>'; if (point.drilldown) { s += 'Click to view '+ point.category +' versions'; } else { s += 'Click to return to browser brands'; } return s;" ) .AddJavascripFunction( "ColumnPointClick", @"var drilldown = this.drilldown; if (drilldown) { // drill down setChart(drilldown.name, drilldown.categories, drilldown.data.data, drilldown.color); } else { // restore setChart(name, categories, data.data); }" ) .AddJavascripFunction( "setChart", @"chart.xAxis[0].setCategories(categories); chart.series[0].remove(); chart.addSeries({ name: name, data: data, color: color || 'white' });", "name", "categories", "data", "color" ) .AddJavascripVariable("colors", "Highcharts.getOptions().colors") .AddJavascripVariable("name", "'{0}'".FormatWith(NAME)) .AddJavascripVariable("categories", JsonSerializer.Serialize(categories)) .AddJavascripVariable("data", JsonSerializer.Serialize(data)); return View(chart3); }
/// <summary> /// Fetches the salt split chart data. /// </summary> /// <param name="numWeeks">The number weeks.</param> /// <param name="avgResinage">The average resin age.</param> /// <param name="startingSS">The starting system.</param> /// <param name="maxDegSS">The maximum deg system.</param> /// <param name="selectedTrain">The selected train.</param> /// <param name="CleaningEffectiveness">The cleaning effectiveness.</param> /// <param name="isDashboard">if set to <c>true</c> [is dashboard].</param> /// <returns></returns> private Highcharts FetchSaltSplitChartData(double numWeeks, double avgResinage, double startingSS, double maxDegSS, string selectedTrain, double CleaningEffectiveness, bool isDashboard) { try { Dictionary<double, double> currentSS = new Dictionary<double, double>(); List<double> minimumSS = this.predictiveModelService.CalculateMinSaltSplit(Convert.ToInt64(this.Session["CustomerId"]), selectedTrain); double minimumSaltSplit = minimumSS[0]; double dblResinAge; if (avgResinage == 0) { dblResinAge = minimumSS[1]; } else { dblResinAge = avgResinage; } Number width, height; Dictionary<double, double> chartPoints = new Dictionary<double, double>(); if (isDashboard == true) { width = 500; height = 290; } else { width = 650; height = 265; } chartPoints = this.predictiveModelService.ComputeDataPoints(numWeeks, startingSS, maxDegSS); Data data1 = new Data(new object[] { }); int[] d = new int[chartPoints.Count]; double pointstart; Point[] afterCleaningSS = new Point[1]; Point[] currentSaltSplitPoints = new Point[1]; Point[] chartdataPoints = new Point[chartPoints.Count]; object[] minThresholdSeries = new object[chartPoints.Count]; int i = 0; foreach (var item in chartPoints) { chartdataPoints[i] = new Point(); chartdataPoints[i].X = item.Key; chartdataPoints[i].Y = item.Value; pointstart = Convert.ToDouble(chartPoints.Keys != null ? chartPoints.Keys.FirstOrDefault() : 0); minThresholdSeries.SetValue(minimumSaltSplit, i); i++; } Point point1 = new Point(); Point point2 = new Point(); currentSS = this.predictiveModelService.CurrentSSConditions(dblResinAge, CleaningEffectiveness, startingSS); this.currentSaltSplit = (currentSS != null && currentSS.Count > 0) ? currentSS.ElementAt(0).Value : 0; point1.X = (currentSS != null && currentSS.Count > 0) ? currentSS.ElementAt(0).Key : 0; point1.Y = (currentSS != null && currentSS.Count > 0) ? currentSS.ElementAt(0).Value : 0; afterCleaningSS[0] = point1; if (currentSS != null && currentSS.Count > 1) { point2.X = currentSS.ElementAt(1).Key; point2.Y = currentSS.ElementAt(1).Value; } currentSaltSplitPoints[0] = point2; Highcharts chart = new Highcharts("chart1") .InitChart(new Chart { Width = width, Height = height, DefaultSeriesType = ChartTypes.Spline, ZoomType = ZoomTypes.Xy, SpacingRight = 30 }) .SetTitle(new Title { Text = "Salt Split Degradation" }) .SetCredits(new Credits { Enabled = false }) .SetTooltip(new Tooltip { HeaderFormat = "<b>{series.name}</b><br>", PointFormat = "<b>Week :{point.x:.0f}<br> <b>Salt Split: {point.y:.2f}</b>" , Enabled = true }) .SetLegend(new Legend { BorderWidth = 1, }) .SetXAxis(new XAxis { Type = AxisTypes.Linear, MinRange = 0, Max = numWeeks, Title = new XAxisTitle { Text = "Number of Weeks" }, TickInterval = 50 }) .SetYAxis(new YAxis { Title = new YAxisTitle { Text = "Salt Split" }, Min = 0, Max = 30, StartOnTick = false, EndOnTick = false, TickInterval = 10, PlotLines = new YAxisPlotLines[1] { new YAxisPlotLines { Value = minimumSaltSplit, Color = Color.Red, Width = 2, DashStyle = DashStyles.ShortDash, Label = new YAxisPlotLinesLabel { Text = "MinimumSS For Demand=" + Math.Round(minimumSaltSplit, 2) + string.Empty } } } }) .SetPlotOptions(new PlotOptions { Spline = new PlotOptionsSpline { LineWidth = 2, Marker = new PlotOptionsSplineMarker { Enabled = false, States = new PlotOptionsSplineMarkerStates { Hover = new PlotOptionsSplineMarkerStatesHover { Enabled = true, Radius = 2 } } }, Shadow = false, States = new PlotOptionsSplineStates { Hover = new PlotOptionsSplineStatesHover { LineWidth = 1 } }, Point = new PlotOptionsSplinePoint() } }) .SetSeries(new[] { new Series{ Name = "Salt Split degradation", Type = ChartTypes.Spline, Data = new Data(chartdataPoints), Color = Color.Green, }, new Series { Name = "Current SaltSplit", Type = ChartTypes.Scatter, Data = new Data(afterCleaningSS), Color = Color.Blue }, new Series { Name = "After Cleaning SaltSplit", Type = ChartTypes.Scatter, Data = new Data(currentSaltSplitPoints), Color = Color.DarkRed } }); return chart; } catch (Exception) { throw; } }
public ActionResult PieWithDrilldown() { Data data = new Data(new[] { new SeriesData { Y = 55.11, Name = "MSIE versions", Drilldown = "MSIE" }, new SeriesData { Y = 21.63, Name = "Firefox versions", Drilldown = "Firefox" }, new SeriesData { Y = 11.94, Name = "Chrome versions", Drilldown = "Chrome" }, new SeriesData { Y = 7.15, Name = "Safari versions", Drilldown = "Safari" }, new SeriesData { Y = 2.14, Name = "Opera versions", Drilldown = "Opera" } }); Drilldown drilldown = new Drilldown { Series = new[] { new Series { Id = "MSIE", Data = new Data(new object[,] {{"MSIE 6.0", 10.85}, {"MSIE 7.0", 7.35}, {"MSIE 6.0", 10.85}, {"MSIE 8.0", 33.06}, {"MSIE 9.0", 2.81}}) }, new Series { Id = "Firefox", Data = new Data(new object[,] {{"Firefox 2.0", 0.20}, {"Firefox 3.0", 0.83}, {"Firefox 3.5", 1.58}, {"Firefox 3.6", 13.12}, {"Firefox 4.0", 5.43}}) }, new Series { Id = "Chrome", Data = new Data(new object[,] {{"Chrome 5.0", 0.12}, {"Chrome 6.0", 0.19}, {"Chrome 7.0", 0.12}, {"Chrome 8.0", 0.36}, {"Chrome 9.0", 0.32}, {"Chrome 10.0", 9.91}, {"Chrome 11.0", 0.50}, {"Chrome 12.0", 0.22}}) }, new Series { Id = "Safari", Data = new Data(new object[,] {{"Safari 5.0", 4.55}, {"Safari 4.0", 1.42}, {"Safari Win 5.0", 0.23}, {"Safari 4.1", 0.21}, {"Safari/Maxthon", 0.20}, {"Safari 3.1", 0.19}, {"Safari 4.1", 0.14}}) }, new Series { Id = "Opera", Data = new Data(new object[,] {{"Opera 9.x", 0.12}, {"Opera 10.x", 0.37}, {"Opera 11.x", 1.65}}) } } }; Highcharts chart = new Highcharts("chart") .InitChart(new Chart { Type = ChartTypes.Pie }) .SetTitle(new Title { Text = "Browser market share, April, 2011" }) .SetSubtitle(new Subtitle { Text = "Click the columns to view versions. " }) .SetXAxis(new XAxis { Type = AxisTypes.Category }) .SetYAxis(new YAxis { Title = new YAxisTitle { Text = "Total percent market share" } }) .SetLegend(new Legend { Enabled = false }) .SetTooltip(new Tooltip { HeaderFormat = "<span style=\"font-size:11px\">{series.name}</span><br>", PointFormat = "<span style=\"color:{point.color}\">{point.name}</span>: <b>{point.y:.2f}%</b> of total<br/>" }) .SetPlotOptions(new PlotOptions { Column = new PlotOptionsColumn { BorderWidth = 0, DataLabels = new PlotOptionsColumnDataLabels { Enabled = true, Format = "{point.y:.1f}%", } } }) .SetSeries(new Series { Name = "Browser brands", Data = data, PlotOptionsBar = new PlotOptionsBar { ColorByPoint = true } }) .SetDrilldown(drilldown); return View(chart); }
public Highcharts ColumnWithDrilldownSector() { var months = new MonthSales[] { new MonthSales { Name = "January", Scale = 1 }, new MonthSales { Name = "February", Scale = 2 }, new MonthSales { Name = "March", Scale = 3 }, new MonthSales { Name = "April", Scale = 4 }, new MonthSales { Name = "May", Scale = 5 }, new MonthSales { Name = "June", Scale = 6 }, new MonthSales { Name = "July", Scale = 7 }, new MonthSales { Name = "August", Scale = 8 }, new MonthSales { Name = "September", Scale = 9 }, new MonthSales { Name = "October", Scale = 10 }, new MonthSales { Name = "November", Scale = 11 }, new MonthSales { Name = "December", Scale = 12 } }; var coursesNames = months.Select(x => x.Name).ToArray(); List <MonthSales> firststTermCourseList = new List <MonthSales>(); List <MonthSales> secondTermCourseList = new List <MonthSales>(); List <MonthSales> thirdTermCourseList = new List <MonthSales>(); List <MonthSales> fourthTermCourseList = new List <MonthSales>(); string[] firstTermSubjects = coursesNames; string[] secondTermSubjects = coursesNames; string[] thirdTermSubjects = coursesNames; string[] fourthTermSubjects = coursesNames; var firstTermData = GetRandom(months, 1, ref firststTermCourseList); var secondTermData = GetRandom(months, 2, ref secondTermCourseList); var thirdTermData = GetRandom(months, 3, ref thirdTermCourseList); var fourthTermData = GetRandom(months, 4, ref fourthTermCourseList); firstTermSubjects = firststTermCourseList.Select(x => x.Name).ToArray(); secondTermSubjects = secondTermCourseList.Select(x => x.Name).ToArray(); thirdTermSubjects = thirdTermCourseList.Select(x => x.Name).ToArray(); fourthTermSubjects = fourthTermCourseList.Select(x => x.Name).ToArray(); var p1 = (Number)GetActualData(1); var p2 = (Number)GetActualData(2); var p3 = (Number)GetActualData(3); var p4 = (Number)GetActualData(4); string[] categories = new[] { "1st Quarter", "2nd Quarter", "3rd Quarter", "4th Quarter" }; string strName = " Year Sales"; DotNet.Highcharts.Helpers.Data data = new DotNet.Highcharts.Helpers.Data(new[] { new Point { Y = p1, Color = System.Drawing.Color.FromName("colors[0]"), Drilldown = new Drilldown { Name = "1st Quarter", Categories = firstTermSubjects, Data = firstTermData, Color = System.Drawing.Color.FromName("colors[0]") } }, new Point { Y = p2, Color = System.Drawing.Color.FromName("colors[1]"), Drilldown = new Drilldown { Name = "2nd Quarter", Categories = secondTermSubjects, Data = secondTermData, Color = System.Drawing.Color.FromName("colors[1]") } }, new Point { Y = p3, Color = System.Drawing.Color.FromName("colors[2]"), Drilldown = new Drilldown { Name = "3rd Quarter", Categories = thirdTermSubjects, Data = thirdTermData, Color = System.Drawing.Color.FromName("colors[2]") } }, new Point { Y = p4, Color = System.Drawing.Color.FromName("colors[3]"), Drilldown = new Drilldown { Name = "4th Quarter", Categories = fourthTermSubjects, Data = fourthTermData, Color = System.Drawing.Color.FromName("colors[3]") } } }); Highcharts chart = new Highcharts("chart") .InitChart(new Chart { DefaultSeriesType = ChartTypes.Column }) .SetTitle(new Title { Text = strName }) .SetSubtitle(new Subtitle { Text = "Click the columns for Quarter View. Click again for Month View." }) .SetXAxis(new XAxis { Categories = categories }) .SetYAxis(new YAxis { Title = new YAxisTitle { Text = "Sales (NGN)" } }) .SetLegend(new Legend { Enabled = false }) .SetTooltip(new Tooltip { Formatter = "TooltipFormatter" }) .SetPlotOptions(new PlotOptions { Column = new PlotOptionsColumn { Cursor = Cursors.Pointer, Point = new PlotOptionsColumnPoint { Events = new PlotOptionsColumnPointEvents { Click = "ColumnPointClick" } }, DataLabels = new PlotOptionsColumnDataLabels { Enabled = true, Color = System.Drawing.Color.FromName("colors[0]"), Formatter = "function() { return this.y +' '; }", Style = "fontWeight: 'bold'" } } }) .SetSeries(new Series { Name = "Sales", Data = data, Color = System.Drawing.Color.White }) .SetExporting(new Exporting { Enabled = false }) .AddJavascripFunction( "TooltipFormatter", @"var point = this.point, s = this.x +':<b>'+ this.y +' </b><br/>'; if (point.drilldown) { s += 'Click to view by '+ point.category +' results'; } else { s += 'Click to return to Quarter View'; } return s;" ) .AddJavascripFunction( "ColumnPointClick", @"var drilldown = this.drilldown; if (drilldown) { // drill down setChart(drilldown.name, drilldown.categories, drilldown.data.data, drilldown.color); } else { // restore setChart(name, categories, data.data); }" ) .AddJavascripFunction( "setChart", @"chart.xAxis[0].setCategories(categories); chart.series[0].remove(); chart.addSeries({ name: name, data: data, color: color || 'white' });", "name", "categories", "data", "color" ) .AddJavascripVariable("colors", "Highcharts.getOptions().colors") .AddJavascripVariable("name", "'{0}'".FormatWith(strName)) .AddJavascripVariable("categories", JsonSerializer.Serialize(categories)) .AddJavascripVariable("data", JsonSerializer.Serialize(data)); return(chart); }
public Highcharts GerarGraficoDeAreas(GraficoDeAreaDTO pGrafico) { Highcharts columnChart = new Highcharts("areasplinechart"); columnChart.InitChart(new Chart() { Type = pGrafico.TipoDeGrafico, BackgroundColor = new BackColorOrGradient(pGrafico.Cor), Style = "fontWeight: 'bold', fontSize: '17px'", BorderColor = pGrafico.CorBorda, BorderRadius = 0, BorderWidth = 2 }); columnChart.SetTitle(new Title() { Text = pGrafico.Titulo }); columnChart.SetXAxis(new XAxis() { Type = AxisTypes.Category, Title = new XAxisTitle() { Style = "fontWeight: 'bold', fontSize: '14px'" }, Categories = pGrafico.EixoY.ToArray() }); columnChart.SetYAxis(new YAxis() { Title = new YAxisTitle() { Style = "fontWeight: 'bold', fontSize: '12px'" }, ShowFirstLabel = true, ShowLastLabel = true, Min = 0 }); columnChart.SetCredits(new Credits() { Enabled = false }); columnChart.SetLegend(new Legend { Enabled = true, BorderColor = System.Drawing.Color.CornflowerBlue, BorderRadius = 6, BackgroundColor = new BackColorOrGradient(ColorTranslator.FromHtml("#FFADD8E6")) }); List <Series> listaValoresX = new List <Series>(); foreach (var item in pGrafico.EixoX) { foreach (var valoresX in item) { var valores = new DotNet.Highcharts.Helpers.Data(valoresX.Valores.ToArray()); var serie = new Series() { Name = valoresX.Nome, Data = valores, Color = valoresX.Cor }; listaValoresX.Add(serie); } } columnChart.SetSeries(listaValoresX.ToArray()); return(columnChart); }
private Highcharts BasicLineSingleStation(string chartHeading, Data airPollutionLevel, Data minTemp, Data maxTemp, Data rainFall, string[] categories) { Highcharts chart = new Highcharts("chart") .InitChart(new Chart { DefaultSeriesType = ChartTypes.Line, MarginRight = 130, MarginBottom = 25, ClassName = "chart" }) .SetTitle(new Title { Text = chartHeading, X = -20 }) .SetSubtitle(new Subtitle { Text = "Source: Dummy Data", X = -20 }) .SetXAxis(new XAxis { Categories = categories }) .SetYAxis(new YAxis { Title = new XAxisTitle { Text = "Temperature (°C)" }, PlotLines = new[] { new XAxisPlotLines { Value = 0, Width = 1, Color = ColorTranslator.FromHtml("#808080") } } }) .SetTooltip(new Tooltip { Formatter = @"function() { return '<b>'+ this.series.name +'</b><br/>'+ this.x +': '+ this.y +'°C'; }" }) .SetLegend(new Legend { Layout = Layouts.Vertical, Align = HorizontalAligns.Right, VerticalAlign = VerticalAligns.Top, X = -10, Y = 100, BorderWidth = 0 }) .SetSeries(new[] { new Series {Name = "AirPolutionlevel", Data= airPollutionLevel}, new Series {Name = "MaxTemp", Data= minTemp}, new Series {Name = "MinTemp", Data= maxTemp}, new Series {Name = "RainFall", Data= rainFall}, } ); return chart; }
private Highcharts DualAxesLineAndColumnSingleStation(string stationName, string[] categories, Data rainFall, Data temperature) { Highcharts chart = new Highcharts("chart") .InitChart(new Chart { ZoomType = ZoomTypes.Xy }) .SetTitle(new Title { Text = "Average Monthly Temperature and Rainfall in " + stationName }) .SetSubtitle(new Subtitle { Text = "Source: Dummy" }) .SetXAxis(new XAxis { Categories = categories }) .SetYAxis(new[] { new YAxis { Labels = new YAxisLabels { Formatter = "function() { return this.value +'°C'; }", Style = "color: '#89A54E'" }, Title = new XAxisTitle { Text = "Temperature", Style = "color: '#89A54E'" } }, new YAxis { Labels = new YAxisLabels { Formatter = "function() { return this.value +' mm'; }", Style = "color: '#4572A7'" }, Title = new XAxisTitle { Text = "Rainfall", Style = "color: '#4572A7'" }, Opposite = true } }) .SetTooltip(new Tooltip { Formatter = "function() { return ''+ this.x +': '+ this.y + (this.series.name == 'Rainfall' ? ' mm' : '°C'); }" }) .SetLegend(new Legend { Layout = Layouts.Vertical, Align = HorizontalAligns.Left, X = 120, VerticalAlign = VerticalAligns.Top, Y = 100, Floating = true, BackgroundColor = ColorTranslator.FromHtml("#FFFFFF") }) .SetSeries(new[] { new Series { Name = "Rainfall", Color = ColorTranslator.FromHtml("#4572A7"), Type = ChartTypes.Column, YAxis = 1, Data = rainFall }, new Series { Name = "Temperature", Color = ColorTranslator.FromHtml("#89A54E"), Type = ChartTypes.Spline, Data = temperature } }); return chart; }
public Highcharts GraphBudget(DateTime fechaAsked) { var mes = (int)Math.Floor(fechaAsked.Subtract(DateTime.Now).TotalDays / (365.25 / 12)); var startDate = DateTime.Now; var actualBalance = (from q in db.Cuentas where q.User == User.Identity.Name select (double?)q.Monto).Sum() ?? 0; var income = (from q in db.TransaccionProyectadas where q.Cuenta.User == User.Identity.Name && q.Monto > 0 select (double?)q.Monto).Sum() ?? 0; var outcome = (from q in db.TransaccionProyectadas where q.Cuenta.User == User.Identity.Name && q.Monto <= 0 select (double?)q.Monto).Sum() ?? 0; //var fechas = new List<string>(); //var fechas2 = new List<string>(); //fechas.Add(startDate.ToShortDateString()); //var lastDate = startDate; //for (int i = 0; i < mes; i++) //{ // lastDate = lastDate.AddMonths(1); // var fecIng = new DateTime(lastDate.Year, lastDate.Month, 1); // fechas.Add(fecIng.ToShortDateString()); // var fecSal = new DateTime(lastDate.Year, lastDate.Month, 15); // fechas.Add(fecSal.ToShortDateString()); //} //var Categories = fechas.ToArray(); // var valores = new List<object>(); // valores.Add(actualBalance); //var balance = actualBalance; //var fecha = startDate; //lastDate = startDate; //for (int i = 0; i < mes; i++) //{ // balance += income; // valores.Add(balance); // balance += outcome; // valores.Add(balance); //} //var Data = new DData(valores.ToArray()); object[,] Balance1 = new object[2 * mes + 2, 2]; //if (fechaAsked.Day >= 15) //{ // Balance1 = new object[2 * mes + 2, 2]; //} //else //{ // Balance1 = new object[2 * mes + 1, 2]; //} Balance1[0, 0] = startDate; Balance1[0, 1] = actualBalance; var lastDate = startDate; var balance = actualBalance; var counter = 1; for (int i = 1; i <= mes; i++) { lastDate = lastDate.AddMonths(1); balance += income; Balance1[counter, 0] = new DateTime(lastDate.Year, lastDate.Month, 1); Balance1[counter, 1] = balance; counter++; balance += outcome; Balance1[counter, 0] = new DateTime(lastDate.Year, lastDate.Month, 15); Balance1[counter, 1] = balance; counter++; } Balance1[counter, 0] = fechaAsked; Balance1[counter, 1] = balance; var Gastos = new DData(Balance1); Series Flujo = new Series { Name = "Flujo Efectivo", Data = Gastos }; Highcharts chart = new Highcharts("chart") .InitChart(new Chart { DefaultSeriesType = ChartTypes.Spline }) .SetOptions(new GlobalOptions { Global = new Global { UseUTC = false } }) .SetTitle(new Title { Text = "Proyección a: " + fechaAsked.ToShortDateString() }) .SetSubtitle(new Subtitle { Text = "En base a los ingresos y el presupuesto." }) .SetXAxis(new XAxis { Type = AxisTypes.Datetime, DateTimeLabelFormats = new DateTimeLabel { Month = "%e. %b", Year = "%b" } }) .SetYAxis(new YAxis { Title = new XAxisTitle { Text = "Monto ($)" }, Min = 0 }) .SetTooltip(new Tooltip { Formatter = "function() { return '<b>'+ this.series.name +'</b><br/>'+ Highcharts.dateFormat('%e %b', this.x) +': $'+ Highcharts.numberFormat(this.y, 0) +' '; }" }) .SetSeries(new[] { Flujo }); //DotNet.Highcharts.Highcharts chart = new DotNet.Highcharts.Highcharts("chart") // .SetOptions(new GlobalOptions { Global = new Global { UseUTC = false } }) // .InitChart(new Chart { ZoomType = ZoomTypes.X, SpacingRight = 20 }) // .SetTitle(new Title { Text = "Flujo de Efectivo" }) // .SetSubtitle(new Subtitle { Text = "Proyección" }) // .SetXAxis(new XAxis // { // Type = AxisTypes.Linear, // //MinRange = 24 * 3600 * 1000, // Categories = Categories, // Title = new XAxisTitle { Text = "Fecha" } // }) // //.SetXAxis(new XAxis // //{ // // Title = new XAxisTitle { Text = "RD$" }, // // Categories = Categories // //}) // //.SetPlotOptions(new PlotOptions // //{ // // Series = new PlotOptionsSeries // // { // // Marker = new PlotOptionsSeriesMarker // // { // // Enabled = true, // // States = new PlotOptionsSeriesMarkerStates // // { // // Hover = new PlotOptionsSeriesMarkerStatesHover // // { // // Enabled = true, // // Radius = 5 // // } // // } // // }, // // //Shadow = false, // // //States = new PlotOptionsAreaStates { Hover = new PlotOptionsAreaStatesHover { LineWidth = 1 } }, // // PointInterval = 24 * 3600 * 1000, // // PointStart = new PointStart(startDate) // // } // //}) // //.SetSeries(new Series // //{ // // Type = ChartTypes.Line, // // Name = "USD to EUR", // // Data = Data // //}) // .SetSeries(new Series // { // Type = ChartTypes.Line, // Name = "USD to EUR", // Data = Data // }) // ; return chart; }
public Highcharts Graph() { var startDate = DateTime.Now; var datos = (from q in db.Cuentas where q.User == User.Identity.Name select new { fecha = startDate, monto = q.Monto }) .Union (from q in db.Transacciones where q.Cuenta.User == User.Identity.Name select new { fecha = q.Fecha, monto = q.Monto }) .Union (from q in db.TransaccionTemps where q.Cuenta.User == User.Identity.Name select new { fecha = q.Fecha, monto = q.Monto }) .OrderBy(q => q.fecha); //var fechas = new List<string>(); //foreach (var dato in datos) //{ // fechas.Add(dato.fecha.ToShortDateString()); //} //var Categories = fechas.ToArray(); //new[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; var valores = new List<object>(); var balance = 0.0; var fecha = startDate; foreach (var dato in datos) { if (fecha == dato.fecha) { balance += (double)dato.monto; } else { valores.Add(balance); fecha = dato.fecha; balance += (double)dato.monto; } } var Data = new DData(valores.ToArray()); DotNet.Highcharts.Highcharts chart = new DotNet.Highcharts.Highcharts("chart") .SetOptions(new GlobalOptions { Global = new Global { UseUTC = false } }) .InitChart(new Chart { ZoomType = ZoomTypes.X, SpacingRight = 20 }) .SetTitle(new Title { Text = "Flujo de Efectivo" }) .SetSubtitle(new Subtitle { Text = "Proyección" }) .SetXAxis(new XAxis { Type = AxisTypes.Datetime, MinRange = 24 * 3600 * 1000, Title = new XAxisTitle { Text = "RD$" } }) //.SetXAxis(new XAxis //{ // Title = new XAxisTitle { Text = "RD$" }, // Categories = Categories //}) .SetPlotOptions(new PlotOptions { Series = new PlotOptionsSeries { Marker = new PlotOptionsSeriesMarker { Enabled = false, States = new PlotOptionsSeriesMarkerStates { Hover = new PlotOptionsSeriesMarkerStatesHover { Enabled = true, Radius = 5 } } }, //Shadow = false, //States = new PlotOptionsAreaStates { Hover = new PlotOptionsAreaStatesHover { LineWidth = 1 } }, PointInterval = 24 * 3600 * 1000, PointStart = new PointStart(datos.First().fecha) } }) .SetSeries(new Series { Type = ChartTypes.Line, Name = "USD to EUR", Data = Data }) //.SetSeries(new Series //{ // Data = Data //}) ; return chart; }