protected override string GetText(float oldVal, float newVal) { string ret = ""; TimeSpan timeSpan = TimeSpan.FromSeconds(var.Value); bool usedAny = false; timeComponents.Clear(); for (int i = 0; i < timeTupleAux.Length; i++) { TimeTuple currentComponent = timeTupleAux[i]; if (!currentComponent.Item1.check) { continue; } double timeValue = currentComponent.Item2(timeSpan); string actualFormat = simplifyHighestValue && !usedAny && timeValue < 10? "{0:0}" : currentComponent.Item1.value; timeComponents.Add(string.Format(actualFormat, timeValue)); usedAny = true; } for (int i = 0; i < timeComponents.Count; i++) { ret += timeComponents[i]; if (i < timeComponents.Count - 1) { ret += format; } } return(ret); }
protected override void OnInitialized() { if (Day == MyChartType.Hourly) { _config = new LineConfig { Options = new LineOptions { Title = new OptionsTitle { Display = true, Text = Title + " Last Day" }, Responsive = true, Animation = new ArcAnimation { AnimateRotate = true, AnimateScale = true }, Scales = new Scales { xAxes = new List <CartesianAxis> { new TimeAxis { Distribution = TimeDistribution.Linear, Ticks = new TimeTicks { Source = TickSource.Auto, Reverse = true }, Time = new TimeOptions { Unit = TimeMeasurement.Hour, Round = TimeMeasurement.Second, TooltipFormat = "DD.MM.YYYY HH:mm:ss", DisplayFormats = TimeDisplayFormats.DE_CH }, ScaleLabel = new ScaleLabel { LabelString = "Time" } } } } } }; } else if (Day == MyChartType.Daily) { _config = new LineConfig { Options = new LineOptions { Title = new OptionsTitle { Display = true, Text = Title + " Last 2 Weeks" }, Responsive = true, Animation = new ArcAnimation { AnimateRotate = true, AnimateScale = true }, Scales = new Scales { xAxes = new List <CartesianAxis> { new TimeAxis { Distribution = TimeDistribution.Linear, Ticks = new TimeTicks { Source = TickSource.Auto, Reverse = true }, Time = new TimeOptions { Unit = TimeMeasurement.Day, Round = TimeMeasurement.Hour, TooltipFormat = "DD.MM.YYYY", DisplayFormats = TimeDisplayFormats.DE_CH }, ScaleLabel = new ScaleLabel { LabelString = "Date" } } } } } }; } else { _config = new LineConfig { Options = new LineOptions { Title = new OptionsTitle { Display = true, Text = Title + " Monthly" }, Responsive = true, Animation = new ArcAnimation { AnimateRotate = true, AnimateScale = true }, Scales = new Scales { xAxes = new List <CartesianAxis> { new TimeAxis { Distribution = TimeDistribution.Linear, Ticks = new TimeTicks { Source = TickSource.Auto, Reverse = true }, Time = new TimeOptions { Unit = TimeMeasurement.Month, Round = TimeMeasurement.Day, TooltipFormat = "DD.MM.YYYY", DisplayFormats = TimeDisplayFormats.DE_CH }, ScaleLabel = new ScaleLabel { LabelString = "Date" } } } } } }; } var Set = new LineDataset <TimeTuple <decimal> > { BackgroundColor = ColorUtil.FromDrawingColor(Color.Blue), BorderColor = ColorUtil.FromDrawingColor(Color.Blue), Fill = false, BorderWidth = 1, PointRadius = 5, PointBorderWidth = 1, SteppedLine = SteppedLine.False, ShowLine = true, Label = "Current" }; var PrevSet = new LineDataset <TimeTuple <decimal> > { BackgroundColor = ColorUtil.FromDrawingColor(Color.LightBlue), BorderDash = new int[] { 10, 5 }, BorderColor = ColorUtil.FromDrawingColor(Color.LightBlue), Fill = false, BorderWidth = 1, PointRadius = 3, PointBorderWidth = 1, SteppedLine = SteppedLine.False, ShowLine = true, Label = "Previous" }; for (int i = 0; i < Data.Count; i++) { var s = Labels[i]; var points = new TimeTuple <decimal>(new Moment(s), Convert.ToDecimal(Data[i])); Set.Add(points); } for (int i = 0; i < (Data.Count < PrevData.Count ? Data.Count : PrevData.Count); i++) { var s = Labels[i]; var points = new TimeTuple <decimal>(new Moment(s), Convert.ToDecimal(PrevData[i])); PrevSet.Add(points); } if (Labels.Count > 0) { DateTime dt = Labels.OrderByDescending(s => s.Date).FirstOrDefault(); Set.Label = dt.ToString("yyyy-MM-dd"); if (Day == MyChartType.Hourly) { PrevSet.Label = dt.AddDays(-1).ToString("yyyy-MM-dd"); } else if (Day == MyChartType.Daily) { PrevSet.Label = dt.AddDays(-14).ToString("yyyy-MM-dd"); } else { PrevSet.Label = "N/A"; PrevSet.Hidden = true; } } _config.Data.Datasets.Add(Set); _config.Data.Datasets.Add(PrevSet); }