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 string AllGoalsByMonthNet() { var now = DateTime.Now; var currentMonth = new DateTime(now.Year, now.Month, 1); var startDate = currentMonth.AddYears(-1); var highchart = new Highcharts("AllGoalsMonth"); var chart = new Chart() { Type = ChartTypes.Column }; highchart.InitChart(chart); highchart.SetTitle(new Title() {Text = "Goals by Month"}); var yaxis = new YAxis {Max = 2}; highchart.SetYAxis(yaxis); var series = new Series {Name = "Steps"}; var xaxis = new XAxis(); var categories = new List<string>(); var data = new List<object>(); for (var i = startDate; i <= currentMonth; i = i.AddMonths(1)) { categories.Add(i.Month.ToString() + "-" + i.Year.ToString()); data.Add(pedometerCalcService.MonthPct(i.Month, i.Year)); } xaxis.Categories = categories.ToArray(); series.Data = new Data(data.ToArray()); highchart.SetXAxis(xaxis); highchart.SetSeries(series); return highchart.ToHtmlString(); }
// // 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 Highcharts SetYAxis(YAxis[] yAxisArray) { _YAxisArray = yAxisArray; return this; }
/// <summary> /// The Y axis or value axis. Normally this is the vertical axis, though if the chart is inverted this is the horiontal axis. /// In case of multiple axes, the yAxis node is an array of configuration objects. /// </summary> /// <param name="yAxis"></param> /// <returns></returns> public Highcharts SetYAxis(YAxis yAxis) { _YAxis = yAxis; return this; }
private void GetAreaChart() { DashboardViewModel dashboard = new DashboardViewModel(); dashboard.ViewModelEvent += dashboard_ViewModelEvent; // Get statistics List<Dictionary<string, object>> values = dashboard.GetAreaChart(); if (values != null) { Highcharts areaChart = new Highcharts("areaChart"); areaChart.InitChart(new Chart() { DefaultSeriesType = ChartTypes.Area, BackgroundColor = new DotNet.Highcharts.Helpers.BackColorOrGradient(Color.Transparent), Height = 300 }); areaChart.SetPlotOptions(new PlotOptions() { Series = new PlotOptionsSeries() { ConnectNulls = true, ConnectEnds = true } }); areaChart.SetLegend(new DotNet.Highcharts.Options.Legend() { Align = DotNet.Highcharts.Enums.HorizontalAligns.Center, Layout = DotNet.Highcharts.Enums.Layouts.Horizontal, VerticalAlign = DotNet.Highcharts.Enums.VerticalAligns.Bottom, BorderWidth = 0 }); areaChart.SetCredits(new DotNet.Highcharts.Options.Credits() { Enabled = false }); areaChart.SetTitle(new DotNet.Highcharts.Options.Title() { Text = "" }); YAxis yAxis = new YAxis(); yAxis.Title = new DotNet.Highcharts.Options.YAxisTitle() { Text = "" }; yAxis.Min = 0; XAxis xAxis = new XAxis(); xAxis.Categories = values[0].Keys.ToArray(); List<Series> seriesCollection = new List<Series>(); Series seriesUsers = new Series(); seriesUsers.Data = new DotNet.Highcharts.Helpers.Data(values[0].Values.ToArray()); seriesUsers.Name = "Users"; seriesCollection.Add(seriesUsers); Series seriesMailbox = new Series(); seriesMailbox.Data = new DotNet.Highcharts.Helpers.Data(values[1].Values.ToArray()); seriesMailbox.Name = "Mailbox"; seriesCollection.Add(seriesMailbox); if (StaticSettings.CitrixEnabled) { Series seriesCitrix = new Series(); seriesCitrix.Data = new DotNet.Highcharts.Helpers.Data(values[2].Values.ToArray()); seriesCitrix.Name = "Citrix"; seriesCollection.Add(seriesCitrix); } areaChart.SetXAxis(xAxis); areaChart.SetYAxis(yAxis); areaChart.SetSeries(seriesCollection.ToArray()); litAreaChart.Text = areaChart.ToHtmlString(); } else litAreaChart.Text = "Error populating 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(); }