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 static Highcharts LineChart(string chartTitle, Number width, Number height, string[] categories, Series[] series, string fakeChartName, string yAxisDescriptions) { return new Highcharts(fakeChartName.Replace(" ", "")) .InitChart(new Chart { Width = width, Height = height, DefaultSeriesType = ChartTypes.Line, }) .SetTitle(new Title {Text = chartTitle}) .SetXAxis(new XAxis { Categories = categories, Labels = new XAxisLabels { Style = "background: '#ffffff'", Enabled = true, Align = HorizontalAligns.Center } }) .SetYAxis(new YAxis { Title = new YAxisTitle {Text = yAxisDescriptions, Style = "background: '#ffffff'"} }) .SetPlotOptions(new PlotOptions { Series = new PlotOptionsSeries { DataLabels = new PlotOptionsSeriesDataLabels { Enabled = false, Style = "background: '#ffffff'", Formatter = @"function() { return '<span style=""font-size:10px; font-family:Calibri"">' + this.y + ' zł</span>' ;}" } } }) .SetTooltip(new Tooltip { Formatter = @"function() { return '<span style=""font-size:10px; font-family:Calibri"">' + this.y + ' zł</span>' ;}", Enabled = true, FollowPointer = true, Shared = true, HeaderFormat = "", Crosshairs = new Crosshairs(true) }) .SetLegend(new Legend {BorderWidth = 0}) .SetSeries(series ?? new Series[] {}) .SetCredits(new Credits {Enabled = false}); }
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(); }
private DotNet.Highcharts.Highcharts GetChart(Series[] series, DataEnum data) { Chart chart = null; XAxis xAxis = null; PlotOptions options = null; switch (data) { case DataEnum.random_points: xAxis = new XAxis { Categories = new[] { "50", "100", "500", "1k", "5k", "10k", "50k", "100k", "500k", "1M", "2M", "3M", "4M", "5M" } }; options = new PlotOptions(); chart = new Chart(); break; case DataEnum.countries: xAxis = new XAxis { Categories = series.Select(t => t.Name).ToArray() }; options = new PlotOptions { Column = new PlotOptionsColumn { Stacking = Stackings.Normal } }; chart = new Chart { DefaultSeriesType = ChartTypes.Column }; // ReSharper disable once PossibleNullReferenceException var results = new object[series.Length]; for (int i = 0; i < series.Length; i++) results[i] = series.FirstOrDefault(x => x.Name.Equals(series[i].Name)).Data.ArrayData[0]; series = new[]{ new Series{ Name = data.ToString(), Data = new Data(results)} }; break; } return new DotNet.Highcharts.Highcharts("chart") .InitChart(chart) .SetTitle(new Title{ Text = "Comparison result" }) .SetXAxis(xAxis) .SetYAxis(new YAxis { Title = new YAxisTitle { Text = "Time (ms)" }, }) .SetSeries(series) .SetPlotOptions(options); }
public static DotNet.Highcharts.Highcharts GetPieChart(Series seriesSet, string title) { DotNet.Highcharts.Highcharts chart = new DotNet.Highcharts.Highcharts(title); chart.InitChart(new Chart { Height = 250, Width = 250, DefaultSeriesType = ChartTypes.Pie }); chart.SetSeries(seriesSet); chart.SetTitle(new DotNet.Highcharts.Options.Title { Text = title }); return chart; }
public ActionResult Bar() { var list = new DataForBarChart().ListDatas; Series[] array = new Series[list.Count]; for (int i = 0; i < list.Count; i++) array[i] = new Series { Name = list[i].Name, Data = new Data(list[i].List) }; Highcharts chart = new Highcharts("chart") .InitChart(new Chart { Type = ChartTypes.Bar }) .SetTitle(new Title { Text = "Yearly Sales of Goods" }) .SetXAxis(new XAxis { Categories = _elementsService.ProductsItems.Select(item => item.Name).ToArray(), Title = new XAxisTitle { Text = string.Empty } }) .SetYAxis(new YAxis { Min = 0, Title = new YAxisTitle { Text = "BYR", Align = AxisTitleAligns.High } }) .SetTooltip(new Tooltip { Formatter = @"function() { return ''+ this.series.name +': '+ this.y +' BYR'; }" }) .SetPlotOptions(new PlotOptions { Bar = new PlotOptionsBar { DataLabels = new PlotOptionsBarDataLabels { Enabled = true } } }) .SetLegend(new Legend { Layout = Layouts.Vertical, Align = HorizontalAligns.Right, VerticalAlign = VerticalAligns.Top, X = -100, Y = 100, Floating = true, BorderWidth = 1, BackgroundColor = new BackColorOrGradient(ColorTranslator.FromHtml("#FFFFFF")), Shadow = true }) .SetCredits(new Credits { Enabled = false }) .SetSeries(array); return View(chart); }
public ActionResult CoinsCompare(String coins) { Series[] series = new Series[coins.Split(',').Length]; XAxis[] xAxises = new XAxis[coins.Split(',').Length]; for (int i = 0; i < coins.Split(',').Length; i++ ) { string coinId = coins.Split(',')[i]; var coin = CoinManager.GetCoin(Guid.Parse(coinId)); var coinDealHistories = CoinManager.GetCoinDealHistories(coin); String[] dealDates = new String[coinDealHistories.Count]; String[] dealPrices = new String[coinDealHistories.Count]; for (int j = 0; j < dealDates.Length; j++) { dealDates[j] = coinDealHistories[j].DealDate.ToString("yyyy-MM-dd"); dealPrices[j] = coinDealHistories[j].DealPrice.ToString(); } series[i] = new Series { Name = coin.Name + "," + coin.AppraisalInstitute + "," + coin.AppraisalScore, Data = new Data(dealPrices), XAxis = i }; xAxises[i] = new XAxis { Title = new XAxisTitle { Text = "拍卖日期" }, Categories = dealDates }; } DotNet.Highcharts.Highcharts coinHistoryDealChart = new DotNet.Highcharts.Highcharts("CoinHistoryDealChart") .SetTitle(new Title { Text = "拍卖价格波动表" }) .SetYAxis(new YAxis { Title = new YAxisTitle { Text = "拍卖价格" } }) .SetXAxis(xAxises) .SetSeries(series); CoinViewModel coinView = new CoinViewModel(); coinView.coinHistoryDealChart = coinHistoryDealChart; return View(coinView); }
private Highcharts ColumnLineAndPie(string[] categories, Series[] series) { Highcharts chart = new Highcharts("chart") .SetTitle(new Title { Text = "Combination chart" }) .SetTooltip(new Tooltip { Formatter = "function() { return '<b>'+ this.point.name +'</b>: '+ this.percentage +' %'; }" }) .SetXAxis(new XAxis { Categories = categories }) .SetTooltip(new Tooltip { Formatter = "TooltipFormatter" }) .AddJavascripFunction("TooltipFormatter", @"var s; if (this.point.name) { // the pie chart s = ''+ this.point.name +': '+ this.y +' fruits'; } else { s = ''+ this.x +': '+ this.y; } return s;") .SetLabels(new Labels { Items = new[] { new LabelsItems { Html = "Average Weather Status", Style = "left: '40px', top: '8px', color: 'black'" } } }) .SetPlotOptions(new PlotOptions { Pie = new PlotOptionsPie { Center = new[] { "100", "80" }, Size = "100", ShowInLegend = false, DataLabels = new PlotOptionsPieDataLabels { Enabled = false } } }) .SetSeries(series); return chart; }
public ReportViewModel(ComparisonViewModel viewModel, Series[] series) { Data = viewModel.Data; Query = viewModel.Query; Results = new List<TestResult>(); foreach (var s in series) { var index = (IndexEnum)Enum.Parse(typeof(IndexEnum), s.Name); for(int i = 0; i < s.Data.ArrayData.Length; i++) { var size = DataSizeEnum.None; if (Data != DataEnum.countries) size = (DataSizeEnum)Enum.GetValues(typeof(DataSizeEnum)).GetValue(i+1); Results.Add(new TestResult { Result = (double)s.Data.ArrayData[i], Index = index, DataSize = size }); } } }
private static Highcharts BuildPieChart(string id, Series series, string dataLabelFormat, string tooltipFormat) { return new Highcharts(id) .InitChart(new Chart {Type = ChartTypes.Pie}) .SetTitle(new Title {Text = ""}) //.SetSubtitle(new Subtitle() {Text = "Click the slices to view"}) .SetOptions(new GlobalOptions { Colors = new[] { Color.Yellow, Color.Orange, Color.OrangeRed, Color.Red, Color.Magenta, Color.Purple, Color.Blue } }) .SetPlotOptions(new PlotOptions { Pie = new PlotOptionsPie { AllowPointSelect = true, DataLabels = new PlotOptionsPieDataLabels { Enabled = true, Format = dataLabelFormat } } }) .SetTooltip(new Tooltip { HeaderFormat = @"<span style=""font-size:11px"">{series.Name}</span><br>", PointFormat = tooltipFormat }) .SetSeries(series); }
// Choose of one using series array or data public static Highcharts StackColumnChart3D(string chartTitle, Number width, Number height, string[] categories, string xAxisLTitle, string yAxisTitle, Series[] series, string headerFormat, string fakeTitleName, Color[] colors) { return new Highcharts(fakeTitleName.Replace(" ", "")) .InitChart(new Chart { DefaultSeriesType = ChartTypes.Column, PlotShadow = false, Height = height, Width = width, Options3d = new ChartOptions3d { Enabled = true, Alpha = 0, Beta = 0, Depth = 30 } }) .SetTitle(new Title { Style = "color:'#000000', fontSize: '14px'", Text = chartTitle }) .SetXAxis(new XAxis { Categories = categories, Labels = new XAxisLabels { Style = "background : '#ffffff'", Enabled = true, Align = HorizontalAligns.Right }, Title = new XAxisTitle { Text = xAxisLTitle, Style = "fontWeight: 'normal', color:'#000000' , fontSize: '11px',background : '#ffffff'" }, GridLineWidth = 0 }) .SetYAxis(new YAxis { Title = new YAxisTitle { Text = yAxisTitle, Style = "fontWeight: 'normal', color:'#000000' , fontSize: '11px',background : '#ffffff'" }, StackLabels = new YAxisStackLabels { Enabled = true, Style = "fontWeight: 'normal', color:'#000000' , fontSize: '11px',background : '#ffffff'" } }) .SetTooltip(new Tooltip { Enabled = true, Shared = true, HeaderFormat = headerFormat }) .SetPlotOptions(new PlotOptions { //Column = new PlotOptionsColumn {Stacking = Stackings.Normal, Depth = 30}, Column = new PlotOptionsColumn { Stacking = Stackings.Normal, Depth = 30, PointWidth = 30, ColorByPoint = false }, Series = new PlotOptionsSeries { DataLabels = new PlotOptionsSeriesDataLabels { Enabled = false, Format = "{point.y}" } } }) .SetCredits(new Credits { Enabled = false }) .SetLegend(new Legend { BorderWidth = 0, ItemStyle = "color:'#000000', fontSize: '11px', background : '#ffffff'" }) .SetSeries(series ?? new Series[] { }); }
public static Highcharts PieChart3D(string chartTitle, string fakeChartName, Series[] series, string pieDataLabel = @"{point.percentage:.1f} %") { return new Highcharts(fakeChartName.Replace(" ", "")) .InitChart(new Chart { DefaultSeriesType = ChartTypes.Pie, PlotShadow = false, PlotBackgroundColor = null, PlotBorderWidth = null, Height = 400, Width = 450, Options3d = new ChartOptions3d { Enabled = true, Alpha = 45 } }) .SetTitle(new Title { Style = "color:'#000000', fontSize: '14px'", Text = chartTitle, Align = HorizontalAligns.Center, VerticalAlign = VerticalAligns.Middle, Y = -20 }) .SetPlotOptions(new PlotOptions { Pie = new PlotOptionsPie { InnerSize = new PercentageOrPixel(40, true), Depth = 45, Colors = GreenSetColor, ShowInLegend = true, AllowPointSelect = true, Cursor = Cursors.Pointer, DataLabels = new PlotOptionsPieDataLabels { Enabled = true, Format = pieDataLabel, Distance = 5 } } }) .SetCredits(new Credits { Enabled = false }) .SetSeries(series); }
public static Highcharts StackColumnChart(string chartTitle, Number width, Number height, string[] categories, string yLabel, Series[] seriesData, string fakeChartName, string chartSubtitle, string tooltipFormatter) { var chart = new Highcharts(fakeChartName.Replace(" ", "")) .InitChart(new Chart { DefaultSeriesType = ChartTypes.Column, Width = width, Height = height }) .SetTitle(new Title { Text = chartTitle }) .SetXAxis(new XAxis { Categories = categories }) .SetYAxis(new YAxis { Min = 0, Title = new YAxisTitle { Text = yLabel, Style = "background: '#ffffff',fontSize: '13px',fontFamily: 'Verdana, sans-serif'" }, StackLabels = new YAxisStackLabels { Enabled = true }, }) .SetLegend(new Legend { BorderWidth = 0 }) .SetTooltip(new Tooltip { Enabled = true, FollowPointer = true, Formatter = tooltipFormatter }) .SetPlotOptions(new PlotOptions { Column = new PlotOptionsColumn { Stacking = Stackings.Normal, DataLabels = new PlotOptionsColumnDataLabels { Enabled = false } } }) .SetSeries(seriesData ?? new Series[] { }) .SetCredits(new Credits { Enabled = false }); if (!string.IsNullOrEmpty(chartSubtitle)) { chart .SetSubtitle(new Subtitle { Style = "color: '#ff0000'", Text = chartSubtitle }); } return chart; }
public static Highcharts GaugeChart(string chartTitle, string fakeChartName, Number width, Number height, Number yAxisMaxValue, Number yAxisPlotBandMaxValue, Series[] series) { return new Highcharts(fakeChartName.Replace(" ", "")) .InitChart(new Chart { DefaultSeriesType = ChartTypes.Gauge, PlotShadow = false, PlotBackgroundColor = null, PlotBorderWidth = null, Height = height, Width = width }) .SetYAxis(new YAxis { Min = 0, Max = yAxisMaxValue, LineWidth = 0, Labels = new YAxisLabels { Y = 5 }, PlotBands = new[] { new YAxisPlotBands { Color = Color.Green, From = 0, To = yAxisPlotBandMaxValue } } }) .SetTitle(new Title { Style = "color:'#000000', fontSize: '14px'", Text = chartTitle, Align = HorizontalAligns.Center, VerticalAlign = VerticalAligns.Top, Y = 20 }) .SetPane(new Pane { Size = new PercentageOrPixel(150, true), StartAngle = -90, EndAngle = 90, Center = new[] { new PercentageOrPixel(50, true), new PercentageOrPixel(100, true) }, Background = new[] { new BackgroundObject { InnerRadius = new PercentageOrPixel(60, true), OuterRadius = new PercentageOrPixel(100, true) } } }) .SetPlotOptions(new PlotOptions { Gauge = new PlotOptionsGauge { Pivot = new PlotOptionsGaugePivot { BackgroundColor = new BackColorOrGradient(Color.Green) }, DataLabels = new PlotOptionsGaugeDataLabels { Enabled = true, BorderWidth = 0, Style = "fontSize: '30px'", Y = -30 } } }) .SetCredits(new Credits { Enabled = false }) .SetSeries(series); }
public static Highcharts HalfPieChart3D(string chartTitle, Number width, Number height, Series[] series, string fakeChartName, int? startAngle = -90, int? endAngle = -270, string pieDataLabel = @"<b>{point.name}</b>: {point.percentage:.1f} %") { return new Highcharts(fakeChartName.Replace(" ", "")) .InitChart(new Chart { DefaultSeriesType = ChartTypes.Pie, PlotShadow = false, Height = height, Width = width, Options3d = new ChartOptions3d { Enabled = true, Alpha = 45 } }) .SetTitle(new Title { Style = "color:'#000000', fontSize: '14px'", Text = chartTitle, Align = HorizontalAligns.Center, VerticalAlign = VerticalAligns.Middle, Y = 50 }) .SetPlotOptions(new PlotOptions { Pie = new PlotOptionsPie { StartAngle = startAngle ?? -90, EndAngle = endAngle ?? -270, DataLabels = new PlotOptionsPieDataLabels { Enabled = true, Distance = 5, Format = pieDataLabel }, InnerSize = new PercentageOrPixel(20, true), Depth = 45, Center = new[] { new PercentageOrPixel(50, true), new PercentageOrPixel(50, true) } } }) .SetCredits(new Credits { Enabled = false }) .SetSeries(series); }
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."; }
/// <summary> /// Builds the high chart for Throughput chart /// </summary> /// <param name="tpCurveClean">TP curve clean</param> /// <param name="tpCurveNoClean">TP curve no clean</param> /// <param name="isDashboard">IsDashboard flag</param> /// <returns>Returns the high chart</returns> private Highcharts plotTPData(Dictionary<DateTime, Tuple<int, double, string>> tpCurveClean, Dictionary<DateTime, Tuple<int, double, string>> tpCurveNoClean, bool isDashboard) { try { double cleanAverage = 0; double noCleanAverage = 0; double xaxisMinValue = 0.0; double xaxisMaxValue = Convert.ToDouble(tpCurveClean.Last().Value.Item1); List<Point> replacePts = new List<Point>(); List<Point> cleanedPts = new List<Point>(); List<double> xseries = new List<double>(); double[] chartdata1 = new double[tpCurveClean.Count]; double[] chartdata2 = new double[tpCurveNoClean.Count]; Point[] chartData_Point1 = new Point[tpCurveClean.Count]; Point[] chartData_Point2 = new Point[tpCurveNoClean.Count]; int counter = 0; Number width, height; foreach (DateTime dateTime in tpCurveClean.Keys) { Tuple<int, double, string> tuple = tpCurveClean[dateTime]; chartData_Point1[counter] = new Point(); chartData_Point1[counter].X = tuple.Item1; chartData_Point1[counter].Y = !double.IsInfinity(tuple.Item2) ? tuple.Item2 : 0; chartdata1[counter] = !double.IsInfinity(tuple.Item2) ? tuple.Item2 : 0; xseries.Add(tuple.Item1); counter++; if (tuple.Item3 == "Clean") { cleanedPts.Add(new Point() { X = tuple.Item1, Y = tuple.Item2 }); } } Number? MaximumWeek = chartData_Point1 != null && chartData_Point1.Length > 0 ? chartData_Point1[chartdata1.Count() - 1].X : 0; cleanAverage = chartdata1.Length > 0 ? chartdata1.Average() : 0; counter = 0; if (isDashboard == true) { width = 500; height = 290; } else { width = 650; height = 300; } foreach (DateTime dateTime in tpCurveNoClean.Keys) { Tuple<int, double, string> tuple = tpCurveNoClean[dateTime]; chartData_Point2[counter] = new Point(); chartData_Point2[counter].X = tuple.Item1; chartData_Point2[counter].Y = !double.IsInfinity(tuple.Item2) ? tuple.Item2 : 0; chartdata2[counter] = !double.IsInfinity(tuple.Item2) ? tuple.Item2 : 0; counter++; if (tuple.Item3 == "Replace") { replacePts.Add(new Point() { X = tuple.Item1, Y = tuple.Item2 }); } } noCleanAverage = chartdata2.Length > 0 ? chartdata2.Average() : 0; xaxisMinValue = xseries.Count > 0 ? xseries[0] : 0; // Set up area color fill gradient parameters Gradient gradLine = new Gradient(); int[] LinearGradient = new int[] { 0, 0, 0, 300 }; gradLine.LinearGradient = LinearGradient; object[,] stops2 = new object[,] { { 0, "#F7EF9B" }, { 1, "#FFFFFF" } }; gradLine.Stops = stops2; Series withCleaning = new Series { Name = "With Cleaning", Data = new Data(chartData_Point1), PlotOptionsArea = new PlotOptionsArea { FillColor = new BackColorOrGradient(Color.FromArgb(30, 0, 128, 0)), Color = Color.FromArgb(80, 153, 80) } }; Series withoutCleaning = new Series { Name = "Without Cleaning", Data = new Data(chartData_Point2), PlotOptionsArea = new PlotOptionsArea { FillColor = new BackColorOrGradient(gradLine), Color = System.Drawing.Color.Goldenrod } }; Highcharts chart1 = new Highcharts("chart") .SetOptions(new GlobalOptions { Lang = new DotNet.Highcharts.Helpers.Lang { ThousandsSep = ",", DecimalPoint = "." } }) .InitChart(new Chart { Width = width, Height = height, DefaultSeriesType = ChartTypes.Area, ZoomType = ZoomTypes.Xy, SpacingRight = 20 }) .SetTitle(new Title { Text = "Throughput Forecast" }) .SetTooltip(new Tooltip { HeaderFormat = "<b>Week: {point.x:.0f}</b><br>", PointFormat = "<b>{series.name}: {point.y:,.2f}</b><br>", Enabled = true, Shared = true }) .SetXAxis(new XAxis { Title = new XAxisTitle { Text = "Number of Weeks" }, Type = AxisTypes.Linear, MinRange = xaxisMinValue, Min = xaxisMinValue, Max = xaxisMaxValue, TickInterval = 20, Labels = new XAxisLabels { Formatter = "function() { return this.value; }" } }) .SetCredits(new Credits { Enabled = false }) .SetLegend(new Legend { BorderWidth = 1, }) .SetYAxis(new YAxis { Title = new YAxisTitle { Text = "Throughput" }, Labels = new YAxisLabels { Formatter = "function() { return this.value; }" } }) .SetPlotOptions(new PlotOptions { Area = new PlotOptionsArea { Marker = new PlotOptionsAreaMarker { Enabled = false, Symbol = "circle", Radius = 2, States = new PlotOptionsAreaMarkerStates { Hover = new PlotOptionsAreaMarkerStatesHover { Enabled = true } } }, PointInterval = 1, PointStart = new PointStart(xaxisMinValue), } }) .SetSeries(new[] { withoutCleaning, withCleaning, new Series { Name = "Replace", Type = ChartTypes.Scatter, Data = new Data(replacePts.ToArray()), Color = Color.Blue, }, new Series { Name = "Clean", Type = ChartTypes.Scatter, Data = new Data(cleanedPts.ToArray()), Color = Color.Red }, new Series { Name = "Without Cleaning Average", Type = ChartTypes.Spline, Data = new Data(new[] { new Point { X = xaxisMinValue, Y = noCleanAverage, }, new Point { X = MaximumWeek, Y = noCleanAverage, } }), Color = Color.Goldenrod , PlotOptionsSpline=new PlotOptionsSpline { DashStyle=DashStyles.ShortDash, LineWidth=1, Marker = new PlotOptionsSplineMarker{Enabled = false}, } }, new Series { Name = "With Cleaning Average", Type = ChartTypes.Spline, Data = new Data(new[] { new Point { X = xaxisMinValue, Y = cleanAverage, }, new Point { X = MaximumWeek, Y = cleanAverage, } }), Color = Color.ForestGreen, PlotOptionsSpline=new PlotOptionsSpline { DashStyle=DashStyles.ShortDash, LineWidth=1, Marker = new PlotOptionsSplineMarker{Enabled = false} } } } ); return chart1; } catch (Exception) { throw; } }
/// <summary> /// Builds the high chart for Throughput chart /// </summary> /// <param name="tpCurveClean">TP curve clean</param> /// <param name="tpCurveNoClean">TP curve no clean</param> /// <param name="isDashboard">IsDashboard flag</param> /// <returns>Returns the high chart</returns> private Highcharts plotTPData(Dictionary<DateTime, Tuple<int, double, string>> tpCurveClean, Dictionary<DateTime, Tuple<int, double, string>> tpCurveNoClean, bool isDashboard) { try { double cleanAverage = 0; double noCleanAverage = 0; double xaxisMinValue = 0.0; double xaxisMaxValue = Convert.ToDouble(tpCurveClean.Last().Value.Item1); List<Point> replacePts = new List<Point>(); List<Point> cleanedPts = new List<Point>(); List<double> xseries = new List<double>(); double[] chartdata1 = new double[tpCurveClean.Count]; double[] chartdata2 = new double[tpCurveNoClean.Count]; Point[] chartData_Point1 = new Point[tpCurveClean.Count]; Point[] chartData_Point2 = new Point[tpCurveNoClean.Count]; int counter = 0; Number width, height; foreach (DateTime dateTime in tpCurveClean.Keys) { Tuple<int, double, string> tuple = tpCurveClean[dateTime]; chartData_Point1[counter] = new Point(); chartData_Point1[counter].X = tuple.Item1; chartData_Point1[counter].Y = !double.IsInfinity(tuple.Item2) ? tuple.Item2 : 0; chartdata1[counter] = !double.IsInfinity(tuple.Item2) ? tuple.Item2 : 0; xseries.Add(tuple.Item1); counter++; if (tuple.Item3 == "Clean") { cleanedPts.Add(new Point() { X = tuple.Item1, Y = tuple.Item2 }); } } Number? MaximumWeek = chartData_Point1 != null && chartData_Point1.Length > 0 ? chartData_Point1[chartdata1.Count() - 1].X : 0; cleanAverage = chartdata1.Length > 0 ? chartdata1.Average() : 0; counter = 0; if (isDashboard == true) { width = 500; height = 290; } else { width = 650; height = 300; } foreach (DateTime dateTime in tpCurveNoClean.Keys) { Tuple<int, double, string> tuple = tpCurveNoClean[dateTime]; chartData_Point2[counter] = new Point(); chartData_Point2[counter].X = tuple.Item1; chartData_Point2[counter].Y = !double.IsInfinity(tuple.Item2) ? tuple.Item2 : 0; chartdata2[counter] = !double.IsInfinity(tuple.Item2) ? tuple.Item2 : 0; counter++; if (tuple.Item3 == "Replace") { replacePts.Add(new Point() { X = tuple.Item1, Y = tuple.Item2 }); } } noCleanAverage = chartdata2.Length > 0 ? chartdata2.Average() : 0; xaxisMinValue = xseries.Count > 0 ? xseries[0] : 0; // Set up area color fill gradient parameters Gradient gradLine = new Gradient(); int[] LinearGradient = new int[] { 0, 0, 0, 300 }; gradLine.LinearGradient = LinearGradient; object[,] stops2 = new object[,] { { 0, "#F7EF9B" }, { 1, "#FFFFFF" } }; gradLine.Stops = stops2; Series withCleaning = new Series { Name = "With Cleaning", Data = new Data(chartData_Point1), PlotOptionsArea = new PlotOptionsArea { FillColor = new BackColorOrGradient(Color.FromArgb(30, 0, 128, 0)), Color = Color.FromArgb(80, 153, 80) } }; Series withoutCleaning = new Series { Name = "Without Cleaning", Data = new Data(chartData_Point2), PlotOptionsArea = new PlotOptionsArea { FillColor = new BackColorOrGradient(gradLine), Color = System.Drawing.Color.Goldenrod } }; Highcharts chart1 = new Highcharts("chart") .SetOptions(new GlobalOptions { Lang = new DotNet.Highcharts.Helpers.Lang { ThousandsSep = ",", DecimalPoint = "." } }) .InitChart(new Chart { Width = width, Height = height, DefaultSeriesType = ChartTypes.Area, ZoomType = ZoomTypes.X, SpacingRight = 20 }) .SetTitle(new Title { Text = "Throughput Forecast" }) .SetTooltip(new Tooltip { HeaderFormat = "<b>Week: {point.x:.0f}</b><br>", //PointFormat = "<b><span style=\"color:this.data.marker.fillcolor\">{series.name}: {point.y:,.2f}</b></span><br>", // Use javascript function to control the tool tip coloring, to add a week number display, and to add thousands place seperartors Formatter = @"function() {var s = [];var X = '';$.each(this.points, function(index,point){if((index%2)==0){s.push('<span style=""color:#E6B800;font-weight:bold;"">'+ point.series.name + ' : <span>' + '<b style=""font-weight:bold;"">' + point.y.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, "","") + '</b>');}else{s.push('<span style=""color:#509950;font-weight:bold;"">'+ point.series.name + ' : <span>' + '<b style=""font-weight:bold;"">' + point.y.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, "","") + '</b>');}X = point.x;});var header = '<span style=""font-weight:bold;"">Week: ' + X.toString() + '<span>'; s.splice(0, 0, header); var temp1 = s[1];var temp2 = s[2];s[1] = temp2;s[2] = temp1;if(s.length >= 5){temp1 = s[4];temp2 = s[3];s[4] = temp2;s[3] = temp1;}return s.join('<br>');}", Enabled = true, Shared = true }) .SetXAxis(new XAxis { Title = new XAxisTitle { Text = "Number of Weeks" }, Type = AxisTypes.Linear, MinRange = 0, Min = xaxisMinValue, Max = xaxisMaxValue, TickInterval = 20, Labels = new XAxisLabels { Formatter = "function() { return this.value; }" } }) .SetCredits(new Credits { Enabled = false }) .SetLegend(new Legend { BorderWidth = 1, }) .SetYAxis(new YAxis { Title = new YAxisTitle { Text = "Throughput" }, Labels = new YAxisLabels { Formatter = "function() { return this.value; }" } }) .SetPlotOptions(new PlotOptions { Area = new PlotOptionsArea { Marker = new PlotOptionsAreaMarker { Enabled = false, Symbol = "circle", Radius = 2, States = new PlotOptionsAreaMarkerStates { Hover = new PlotOptionsAreaMarkerStatesHover { Enabled = true } } }, PointInterval = 1, PointStart = new PointStart(xaxisMinValue), } }) .SetSeries(new[] { withoutCleaning, withCleaning, new Series { Name = "Replace", Type = ChartTypes.Scatter, Data = new Data(replacePts.ToArray()), Color = Color.Blue, }, new Series { Name = "Clean", Type = ChartTypes.Scatter, Data = new Data(cleanedPts.ToArray()), Color = Color.Red }, new Series { Name = "Without Cleaning Average", Type = ChartTypes.Spline, Data = new Data(new[] { new Point { X = xaxisMinValue, Y = noCleanAverage, }, new Point { X = MaximumWeek, Y = noCleanAverage, } }), Color = Color.Goldenrod , PlotOptionsSpline=new PlotOptionsSpline { DashStyle=DashStyles.ShortDash, LineWidth=1, Marker = new PlotOptionsSplineMarker{Enabled = false}, } }, new Series { Name = "With Cleaning Average", Type = ChartTypes.Spline, Data = new Data(new[] { new Point { X = xaxisMinValue, Y = cleanAverage, }, new Point { X = MaximumWeek, Y = cleanAverage, } }), Color = Color.ForestGreen, PlotOptionsSpline=new PlotOptionsSpline { DashStyle=DashStyles.ShortDash, LineWidth=1, Marker = new PlotOptionsSplineMarker{Enabled = false} } } } ); return chart1; } catch (Exception) { throw; } }
public ActionResult _SingleLine() { Series series = new Series { Data = new Data(new object[] { 29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4 }) }; XAxis xaxis = new XAxis { Categories = new[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" } }; Highcharts chart = new Highcharts("chart_single_line"); chart.SetXAxis(xaxis); chart.SetSeries(series); return PartialView(new SmartCity.Models.Global.HighchartModel { highChart=chart }); }
public void DriversIncome() { //var DriversInc = orderManager.GetDriversIncome(); Highcharts driversIncomeChart = new Highcharts("driversChartId"); driversIncomeChart.SetTitle(new Title() { Text = Resources.Resource.DriversIncome }); driversIncomeChart.SetXAxis(new XAxis() { Title = new XAxisTitle() { Text = @Resources.Resource.Drivers }, Categories = new string[] {Resources.Resource.Info} }); driversIncomeChart.SetYAxis(new YAxis() { Title = new YAxisTitle() { Text = @Resources.Resource.IncomeUAH }}); List<Series> series = new List<Series>(); List<object> serieData = new List<object>(); Series serie = new Series(); /*foreach (ChartsColumnDTO item in DriversInc) { serie = new Series(); serie.Name = item.ColumnName; serie.Type = ChartTypes.Column; serieData.Clear(); serieData.Add(new object[] { item.Value }); serie.Data = new Data(serieData.ToArray()); series.Add(serie); };*/ driversIncomeChart.SetSeries(series.ToArray()); driversIncomeChart.SetLegend(new Legend() { Align = HorizontalAligns.Right, Layout = Layouts.Vertical, VerticalAlign = VerticalAligns.Top }); driversIncomeChart.SetPlotOptions(new PlotOptions() { Area = new PlotOptionsArea() { Stacking = Stackings.Normal } }); driversIncomeChart.SetCredits(new Credits() { Enabled = false }); ViewBag.DriversIncomeChart = driversIncomeChart; }
private void DorinTewst() { Queue<string> categoriesQueue = new Queue<string>(new string[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }); for (int i = 0; i < DateTime.Now.Month; i++) { categoriesQueue.Enqueue(categoriesQueue.Dequeue()); } var categories = categoriesQueue.ToArray(); Highcharts chart = new Highcharts("FuelConsumptionID"); chart.SetTitle(new Title() { Text = Resources.Resource.FuelConsumDorin }); ///var list = orderManager.AnnualFuelConsumption(); List<object> obList = new List<object>(); /*foreach (var item in list) { var iut = (int)item; obList.Add((object)iut); }*/ chart.SetYAxis(new YAxis { Title = new YAxisTitle() { Text = Resources.Resource.FuleLDorin }, }); chart.SetXAxis(new XAxis { Title = new XAxisTitle() { Text = Resources.Resource.FuleMonthDorin }, Categories = categories }); List<Series> series = new List<Series>(); Series serie = new Series(); serie.Name = Resources.Resource.LetresDorin; serie.Type = ChartTypes.Column; //serie.Data = new Data(serieData.ToArray()); serie.Data = new Data(obList.ToArray()); series.Add(serie); chart.SetSeries(series.ToArray()); chart.SetLegend(new Legend() { Align = HorizontalAligns.Right, Layout = Layouts.Vertical, VerticalAlign = VerticalAligns.Top }); chart.SetPlotOptions(new PlotOptions() { Area = new PlotOptionsArea() { Stacking = Stackings.Normal } }); chart.SetCredits(new Credits() { Enabled = false }); ViewBag.Chart = chart; }
// // 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 Line() { var list = new DataForLineChart().ListDatas; Series[] array = new Series[list.Count]; for (int i = 0; i < list.Count; i++) array[i] = new Series { Name = list[i].Name, Data = new Data(list[i].List) }; string[] cat = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; Highcharts chart = new Highcharts("chart") .InitChart(new Chart { Type = ChartTypes.Line, MarginRight = 130, MarginBottom = 25, ClassName = "chart" }) .SetTitle(new Title { Text = "Monthly Sales of Goods", X = -20 }) .SetXAxis(new XAxis { Categories = cat }) .SetYAxis(new YAxis { Title = new YAxisTitle { Text = "BYR" }, PlotLines = new[] { new YAxisPlotLines { Value = 0, Width = 1, Color = ColorTranslator.FromHtml("#808080") } } }) .SetTooltip(new Tooltip { Formatter = @"function() { return '<b>'+ this.series.name +'</b><br/>'+ this.x +': '+ this.y +'BYR'; }" }) .SetLegend(new Legend { Layout = Layouts.Vertical, Align = HorizontalAligns.Right, VerticalAlign = VerticalAligns.Top, X = -10, Y = 100, BorderWidth = 0 }) .SetSeries(array); 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(); }
/// <summary> /// The actual series to append to the chart. In addition to the members listed below, any member of the plotOptions /// for that specific type of plot can be added to a series individually. For example, even though a general lineWidth /// is specified in plotOptions.series, an individual lineWidth can be specified for each series. /// </summary> /// <param name="series"></param> /// <returns></returns> public Highcharts SetSeries(Series series) { _Series = series; return this; }
/// <summary> /// Builds the high chart for Throughput chart /// </summary> /// <param name="tpCurveClean">TP curve clean</param> /// <param name="tpCurveNoClean">TP curve no clean</param> /// <param name="isDashboard">IsDashboard flag</param> /// <returns>Returns the high chart</returns> private Highcharts plotTPData(Dictionary<DateTime, Tuple<int, double, string>> tpCurveClean, Dictionary<DateTime, Tuple<int, double, string>> tpCurveNoClean, bool isDashboard) { try { double cleanAverage = 0; double noCleanAverage = 0; double xaxisMinValue = 0.0; List<Point> lstPoints = new List<Point>(); List<double> xseries = new List<double>(); List<double> yseries = new List<double>(); object[] chartdata1 = new object[tpCurveClean.Count]; object[] chartdata2 = new object[tpCurveNoClean.Count]; object[] chartdataAverageClean = new object[tpCurveClean.Count]; object[] chartdataAveragenoClean = new object[tpCurveNoClean.Count]; Point[] chartData_Point1 = new Point[tpCurveClean.Count]; Point[] chartData_Point2 = new Point[tpCurveNoClean.Count]; Point[] withrticleanaverage = new Point[tpCurveClean.Count + 1]; int counter = 0; Number width, height; foreach (DateTime dateTime in tpCurveClean.Keys) { Tuple<int, double, string> tuple = tpCurveClean[dateTime]; chartData_Point1[counter] = new Point(); chartData_Point1[counter].X = tuple.Item1; chartData_Point1[counter].Y = tuple.Item2; chartdata1[counter] = tuple.Item2; xseries.Add(tuple.Item1); counter++; } Number? MaximumWeek = chartData_Point1 != null && chartData_Point1.Length > 0 ? chartData_Point1[chartdata1.Count() - 1].X : 0; cleanAverage = chartdata1.Length > 0 ? (chartdata1.Cast<double>()).ToArray().Average() : 0; counter = 0; if (isDashboard == true) { width = 500; height = 290; } else { width = 650; height = 300; } foreach (DateTime dateTime in tpCurveNoClean.Keys) { Tuple<int, double, string> tuple = tpCurveNoClean[dateTime]; chartData_Point2[counter] = new Point(); chartData_Point2[counter].X = tuple.Item1; chartData_Point2[counter].Y = tuple.Item2; chartdata2[counter] = tuple.Item2; counter++; if (tuple.Item3 == "Replace") { lstPoints.Add(new Point() { X = tuple.Item1, Y = tuple.Item2 }); } } noCleanAverage = chartdata2.Length > 0 ? chartdata2.Cast<double>().ToArray().Average() : 0; xaxisMinValue = xseries.Count > 0 ? xseries[0] - 1 : 0; Series withCleaning = new Series { Name = "WithCleaning", Data = new Data(chartData_Point1), }; Series withoutCleaning = new Series { Name = "WithoutCleaning", Data = new Data(chartData_Point2), }; Highcharts chart1 = new Highcharts("chart") .InitChart(new Chart { Width = width, Height = height, DefaultSeriesType = ChartTypes.Area, ZoomType = ZoomTypes.Xy, SpacingRight = 20 }) .SetTitle(new Title { Text = "Throughput Forecast" }) .SetTooltip(new Tooltip { HeaderFormat = "<b>Week :{point.x:.0f}</b><br>", PointFormat = "<b>{series.name}: {point.y:.2f}</b>", Enabled = true }) .SetXAxis(new XAxis { Title = new XAxisTitle { Text = "Number of Weeks" }, Type = AxisTypes.Linear, MinRange = xaxisMinValue, Min = xaxisMinValue, TickInterval = 50, Labels = new XAxisLabels { Formatter = "function() { return this.value; }" } }) .SetCredits(new Credits { Enabled = false }) .SetLegend(new Legend { BorderWidth = 1, }) .SetYAxis(new YAxis { Title = new YAxisTitle { Text = "Throughput" }, Labels = new YAxisLabels { Formatter = "function() { return this.value; }" } }) .SetPlotOptions(new PlotOptions { Area = new PlotOptionsArea { Marker = new PlotOptionsAreaMarker { Enabled = false, Symbol = "circle", Radius = 2, States = new PlotOptionsAreaMarkerStates { Hover = new PlotOptionsAreaMarkerStatesHover { Enabled = true } } }, PointInterval = 1, PointStart = new PointStart(xaxisMinValue) } }) .SetSeries(new[] { withoutCleaning, withCleaning, new Series { Name = "Replace", Type = ChartTypes.Scatter, Data = new Data(lstPoints.ToArray()), Color = Color.Blue }, new Series { Name = "Without RTI Average Clean", Type = ChartTypes.Spline, Data = new Data(new[] { new Point { X = xaxisMinValue, Y = noCleanAverage, }, new Point { X = MaximumWeek, Y = noCleanAverage, } }), Color = Color.Red, PlotOptionsSpline=new PlotOptionsSpline{DashStyle=DashStyles.ShortDash} }, new Series { Name = "With RTI Average Clean", Type = ChartTypes.Spline, Data = new Data(new[] { new Point { X = xaxisMinValue, Y = cleanAverage, }, new Point { X = MaximumWeek, Y = cleanAverage, } }), Color = Color.Green, PlotOptionsSpline=new PlotOptionsSpline{DashStyle=DashStyles.ShortDash} } } ); return chart1; } catch (Exception) { throw; } }
public Highcharts SetSeries(Series[] seriesArray) { _SeriesArray = seriesArray; return this; }
public JsonResult TransactionsHighcharts(Guid dashboardId, Guid panelId) { var series = new List<Series>(); var seriesDrilldown = new List<Series>(); var panel = this.GetPanel(dashboardId, panelId); var transactions = transactionServiceOnlyTransaction.GetTransactionsFiltrated(panel.Filter); var hasOnlyOutputs = true; var type = panel.GetDataType(); switch (type) { case Panel.PanelDataType.NonGroup: case Panel.PanelDataType.NonGroupAndSortDate: { var group = new TransactionGroupDefinition { OrderBy = null, OrderByClassification = null, OrderByExpression = null, OrderByName = null, GroupBy = null, //GroupByExpression = panel.GetGroupByExpression(panel.GroupBy, out groupByName), GroupByExpression = f => f.Date.Date, GroupByName = null, OrderByGroup = null, OrderByGroupClassification = null, OrderByGroupExpression = null, OrderByGroupName = null, }; transactions = transactions.OrderBy(f => f.Date).ToList(); var transactionGroup = transactionServiceOnlyTransaction.GetTransactionGroupRoot(transactions, group); //var transactionsDayGrouped = transactions.OrderBy(f => f.Date).GroupBy(f=>f.Date.Date).ToList(); //var total = transactions.Sum(f => f.Value); //var count = transactions.Count(); var serieData = new SeriesData[transactionGroup.SubGroups.Count]; var serie = new Series { Name = " ", Data = new DotNet.Highcharts.Helpers.Data(serieData), }; series.Add(serie); var index = 0; foreach (var transactionDayGroup in transactionGroup.SubGroups) { var y = 0d; switch(panel.DisplayY) { case TransactionDisplayY.Value: y = (double)transactionDayGroup.Total; break; case TransactionDisplayY.ValuePercentage: y = (double)transactionDayGroup.TotalPercentage.Last(); break; case TransactionDisplayY.Count: y = transactionDayGroup.Count; break; case TransactionDisplayY.CountPercentage: y = (double)transactionDayGroup.CountPercentage.Last(); break; } var day = (DateTime)transactionDayGroup.Key; serieData[index] = new SeriesData(); serieData[index].X = Helper.UnixTicks(day); serieData[index].Y = (Number)y; serieData[index].Name = day.ToString("d"); if (y > 0) hasOnlyOutputs = false; index++; } break; } case SpentBook.Domain.Panel.PanelDataType.OneGroup: case SpentBook.Domain.Panel.PanelDataType.TwoGroup: case SpentBook.Domain.Panel.PanelDataType.ThreeOrMoreGroup: { var transactionGroup = transactionService.GetTransactionGroupRoot(transactions, panel.GetGroupDefinitions().ToArray()); var tryCategorize = true; // Como só existe 1 nível, fica impossível criar categorização if (type == Panel.PanelDataType.OneGroup) tryCategorize = false; var chartDataCategorizeds = transactionService.GetChartDataCategorized(transactionGroup, tryCategorize); foreach (var item in chartDataCategorizeds) { var serieData = new SeriesData[item.Items.Length]; var serie = new Series { Id = item.ParentPath, Name = string.IsNullOrWhiteSpace(item.ItemGroupName) ? "Todos" : item.ItemGroupName, Data = new DotNet.Highcharts.Helpers.Data(serieData), }; if (item.ParentPath == null) { series.Add(serie); } else { seriesDrilldown.Add(serie); serie.PlotOptionsBar = new PlotOptionsBar { ColorByPoint = false }; } var index = 0; foreach (var data in item.Items) { if (data == null) { serieData[index++] = null; } else { var y = 0d; switch (panel.DisplayY) { case TransactionDisplayY.Value: y = (double)data.Total; break; case TransactionDisplayY.ValuePercentage: if (tryCategorize && item.ParentPath == null) y = (double)data.TotalPercentageGrandParentRelation; else y = (double)data.TotalPercentage; break; case TransactionDisplayY.Count: y = (double)data.Count; break; case TransactionDisplayY.CountPercentage: if (tryCategorize && item.ParentPath == null) y = (double)data.CountPercentageGrandParentRelation; else y = (double)data.CountPercentage; break; } serieData[index++] = new SeriesData { Y = (Number)y, Name = data.Category, Id = data.Category, Drilldown = data.ItemPath }; if (data.Category == "Despesa") serieData[index - 1].Color = System.Drawing.Color.Red; if (data.Total > 0) hasOnlyOutputs = false; } } } break; } } return Json(new { Series = series, Drilldown = seriesDrilldown, Reversed = hasOnlyOutputs, DisplatY = panel.DisplayY }, JsonRequestBehavior.AllowGet); }
public static Series[] GetSeriesArray(string stationName, DateTime fromDate, DateTime toDate) { SmartCityEntities db = new SmartCityEntities(); var rawData = db.sp_GetDataForColLineAndPie(stationName, fromDate, toDate).Select(x => x).ToArray(); string[] measureParam=new string[] {"AirPollution","MinTemp","MaxTemp","RainFall"}; Series[] seriesArray = new Series[rawData.Count()]; for (int i = 0; i < rawData.Count(); i++) { sp_GetDataForColLineAndPie_Result tempObj = ((sp_GetDataForColLineAndPie_Result)rawData.GetValue(i)); seriesArray[i] = new Series { Type = i<rawData.Count()-1?ChartTypes.Column:ChartTypes.Spline, Name = tempObj.Station, Data = new Data(new object[] { tempObj.AvgAirPollutionLevel, tempObj.AvgMinTemp, tempObj.AvgMaxTemp, tempObj.AvgRainFall } ) }; } Series[] series = new[] { new Series { Type = ChartTypes.Column, Name = "Kathmandu", Data = new Data(new object[] { 3, 2, 1, 3 }) }, new Series { Type = ChartTypes.Column, Name = "Pokhara", Data = new Data(new object[] { 2, 3, 5, 7 }) }, new Series { Type = ChartTypes.Column, Name = "Butwal", Data = new Data(new object[] { 4, 3, 3, 9 }) }, new Series { Type = ChartTypes.Column, Name = "Bhairahawa", Data = new Data(new object[] { 3, 2.67, 3, 6.33}) }//, // new Series //{ // Type = ChartTypes.Spline, // Name = "Average", // Data = new Data(new object[] { 3, 2.67, 3, 6.33, 3.33 }) //}//, //new Series //{ // Type = ChartTypes.Pie, // Name = "Total consumption", // Data = new Data(new[] // { // new DotNet.Highcharts.Options.Point // { // Name = "Jane", // Y = 13, // Color = Color.FromName("Highcharts.getOptions().colors[0]") // }, // new DotNet.Highcharts.Options.Point // { // Name = "John", // Y = 23, // Color = Color.FromName("Highcharts.getOptions().colors[1]") // }, // new DotNet.Highcharts.Options.Point // { // Name = "Joe", // Y = 19, // Color = Color.FromName("Highcharts.getOptions().colors[2]") // } // } // ) //} }; return seriesArray; }
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; }