// // 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); }
public string WeightYearProgressNet() { var startWeight = pedometerCalcService.GetStartWeight(DateTime.Now.Year); const int goalWeight = 144; var currentWeight = pedometerCalcService.GetRecentWeight(); var goalLoss = startWeight - goalWeight; var actualLoss = Math.Round(startWeight - currentWeight, 1); var expectedPct = (DateTime.Now.DayOfYear / 365.0); var expectedLoss = Math.Round(expectedPct * goalLoss, 1); var highchart = new Highcharts("weightloss"); var chart = new Chart() { Type = ChartTypes.Gauge }; highchart.InitChart(chart); highchart.SetTitle(new Title{Text = "Weight Loss " + Math.Round(currentWeight,1)}); var series = new Series {Data = new Data(new object[] {actualLoss})}; highchart.SetSeries(series); var pane = new Pane { Background = new[] { new BackgroundObject { InnerRadius = new PercentageOrPixel(60, true), OuterRadius = new PercentageOrPixel(100, true) } }, StartAngle = 0, EndAngle = 360 }; highchart.SetPane(pane); var yaxis = new YAxis { Min = 0, Max = goalLoss, PlotBands = new[] { new YAxisPlotBands { From = 0, To = expectedLoss, Color = Color.Red }, new YAxisPlotBands { From = expectedLoss, To = expectedLoss+0.7, Color = Color.Yellow }, new YAxisPlotBands { From = expectedLoss+0.7, To = goalLoss, Color = Color.Green } }, Labels = new YAxisLabels() { Style = "color:'black'"} }; highchart.SetYAxis(yaxis); highchart.SetTooltip(new Tooltip() {Enabled = false}); highchart.SetSubtitle(new Subtitle() { Text = string.Format("Actual: {0} | Expected: {1} | Difference: {2}", actualLoss, expectedLoss, actualLoss-expectedLoss) }); highchart.SetLegend(new Legend() {Enabled = false}); return highchart.ToHtmlString(); }
public string CurrentMonthGoalProgressNet() { var now = DateTime.Now; var daysInMonth = DateTime.DaysInMonth(now.Year, now.Month); var expectedPct = ((decimal)now.Day / daysInMonth); var remainingDays = daysInMonth - now.Day; var stepsPR = pedometerCalcService.StepsPR(); var remainingSteps = (int) (stepsPR-pedometerCalcService.MonthStepsActual())/remainingDays; var highchart = new Highcharts("CurrentMonthGoal"); var chart = new Chart() {Type = ChartTypes.Bar}; var categories = new List<string> {"Steps"}; var yaxis = new YAxis {Max = 1}; var seriesArray = new List<Series>(); var series = new Series {Name = "Expected",Color = Color.Red}; var data = new List<object> {pedometerCalcService.MonthPctExpected(now)}; var plotoptions = new PlotOptionsBar { Grouping = false, Shadow = false, DataLabels = new PlotOptionsBarDataLabels() { Enabled = false, Format = string.Format("Expected: {0}", (int) (stepsPR*expectedPct)), Color = Color.White } }; series.Data = new Data(data.ToArray()); series.PlotOptionsBar = plotoptions; seriesArray.Add(series); series = new Series {Name = "Actual", Color = Color.Green}; data = new List<object> { pedometerCalcService.MonthPct(now.Month, now.Year) }; plotoptions = new PlotOptionsBar { Grouping = false, Shadow = false, DataLabels = new PlotOptionsBarDataLabels() { Enabled = true, Format = string.Format("Remaining: {0}/day", remainingSteps), Color = Color.White, Shadow = false } }; series.Data = new Data(data.ToArray()); series.PlotOptionsBar = plotoptions; seriesArray.Add(series); highchart.InitChart(chart); highchart.SetTitle(new Title() {Text = "Month Progress"}); highchart.SetXAxis(new XAxis() {Categories = categories.ToArray()}); highchart.SetYAxis(yaxis); highchart.SetSeries(seriesArray.ToArray()); highchart.SetTooltip(new Tooltip() {Enabled = false}); return highchart.ToHtmlString(); }
public void BuildChart() { int kpiId = KpiId; string strategyId = ""; string startingPeriod = ""; string endingPeriod = ""; decimal target = 0; int firstDayOfWeek = Artexacta.App.Configuration.Configuration.GetFirstDayOfWeek(); List <KpiChartData> measurements = KpiMeasurementBLL.GetKPIMeasurementForChart(kpiId, CategoryId, CategoryItemId, firstDayOfWeek, ref strategyId, ref target, ref startingPeriod, ref endingPeriod); Dictionary <string, object> standardSerie = new Dictionary <string, object>(); Dictionary <string, object> targetStandardSerie = new Dictionary <string, object>(); Dictionary <string, object> sumSerie = new Dictionary <string, object>(); Dictionary <string, object> targetSumSerie = new Dictionary <string, object>(); KPI objKpi = KPIBLL.GetKPIById(kpiId); bool hasTarget = target != -1; bool isSum = strategyId == "SUM"; bool isTargetUsable = false; //bool isSerieUsable = false; decimal sumMeasurement = 0; decimal sumTarget = 0; foreach (var item in measurements) { //if (!string.IsNullOrEmpty(startingPeriod) && item.Period == startingPeriod) // isSerieUsable = true; //if (isSerieUsable) standardSerie.Add(item.Period, item.Measurement); //else // standardSerie.Add(item.Period, null); if (isSum) { sumMeasurement = sumMeasurement + item.Measurement; //if (isSerieUsable) sumSerie.Add(item.Period, sumMeasurement); //else // sumSerie.Add(item.Period, null); if (hasTarget) { if (!string.IsNullOrEmpty(startingPeriod) && item.Period == startingPeriod) { isTargetUsable = true; } if (!string.IsNullOrEmpty(endingPeriod) && item.Period == endingPeriod) { isTargetUsable = false; } if (isTargetUsable) { sumTarget = sumTarget + target; targetSumSerie.Add(item.Period, sumTarget); } else { targetSumSerie.Add(item.Period, null); } } } if (hasTarget) { if (!string.IsNullOrEmpty(startingPeriod) && item.Period == startingPeriod) { isTargetUsable = true; } if (!string.IsNullOrEmpty(endingPeriod) && item.Period == endingPeriod) { isTargetUsable = false; } if (isTargetUsable) { targetStandardSerie.Add(item.Period, target); } else { targetStandardSerie.Add(item.Period, null); } } } List <Series> series = new List <Series>(); series.Add(new Series { Name = Resources.KpiDetails.ValuesLabel, Data = new Data(standardSerie.Values.ToArray <object>()) }); if (hasTarget) { series.Add(new Series { Name = Resources.KpiDetails.KpiTargetLabel, Color = System.Drawing.Color.Red, Data = new Data(targetStandardSerie.Values.ToArray <object>()) }); } DotNet.Highcharts.Highcharts chart = new DotNet.Highcharts.Highcharts(ClientID) .InitChart(new Chart() { Type = ChartTypes.Line }) .SetTitle(new Title() { Text = "" }) .SetXAxis(new XAxis { Categories = standardSerie.Keys.ToArray <string>() }) .SetSeries(series.ToArray()) .SetLegend(new Legend() { Layout = Layouts.Horizontal, Align = HorizontalAligns.Center, VerticalAlign = VerticalAligns.Bottom, BorderWidth = 0 }); if (objKpi.UnitID != "TIME") { //chart.SetTooltip(new Tooltip() //{ // ValueSuffix = " " + objKpi.uni.ToLower() + "s" //}); } else { chart.SetTooltip(new Tooltip() { Formatter = "function (){" + "return decimalToYYMMDDhhmm(this.y).toString('" + Resources.DataTime.YearsValueSingle + "','" + Resources.DataTime.YearsValue + "'," + "'" + Resources.DataTime.MonthsValueSingle + "'," + "'" + Resources.DataTime.MonthsValue + "'," + "'" + Resources.DataTime.DaysValueSingle + "'," + "'" + Resources.DataTime.DaysValue + "'," + "'" + Resources.DataTime.HoursValueSingle + "'," + "'" + Resources.DataTime.HoursValue + "'," + "'" + Resources.DataTime.MinutesValueSingle + "'," + "'" + Resources.DataTime.MinutesValue + "');" + "}" }); } ChartLiteral.Text = chart.ToHtmlString(); if (isSum) { series = new List <Series>(); series.Add(new Series { Name = Resources.KpiDetails.ValuesLabel, Data = new Data(sumSerie.Values.ToArray <object>()) }); if (hasTarget) { series.Add(new Series { Name = Resources.KpiDetails.KpiTargetLabel, Color = System.Drawing.Color.Red, Data = new Data(targetSumSerie.Values.ToArray <object>()) }); } chart = new DotNet.Highcharts.Highcharts(ClientID + "_sum") .InitChart(new Chart() { Type = ChartTypes.Line }) .SetTitle(new Title() { Text = "" }) .SetXAxis(new XAxis { Categories = standardSerie.Keys.ToArray <string>() }) .SetSeries(series.ToArray()) .SetLegend(new Legend() { Layout = Layouts.Horizontal, Align = HorizontalAligns.Center, VerticalAlign = VerticalAligns.Bottom, BorderWidth = 0 }); if (objKpi.UnitID != "TIME") { //chart.SetTooltip(new Tooltip() //{ // ValueSuffix = " " + objKpi.uni.ToLower() + "s" //}); } else { chart.SetTooltip(new Tooltip() { Formatter = "function (){" + "return decimalToYYMMDDhhmm(this.y).toString('" + Resources.DataTime.YearsValueSingle + "','" + Resources.DataTime.YearsValue + "'," + "'" + Resources.DataTime.MonthsValueSingle + "'," + "'" + Resources.DataTime.MonthsValue + "'," + "'" + Resources.DataTime.DaysValueSingle + "'," + "'" + Resources.DataTime.DaysValue + "'," + "'" + Resources.DataTime.HoursValueSingle + "'," + "'" + Resources.DataTime.HoursValue + "'," + "'" + Resources.DataTime.MinutesValueSingle + "'," + "'" + Resources.DataTime.MinutesValue + "');" + "}" }); } SumChartLiteral.Text = chart.ToHtmlString(); SumChartPanel.Visible = true; } }