public void LoadInfoFromDB() { String request = "select [Дата оформления], sum(Стоимость) as 'Сумма' " + "from (select [Дата оформления], [Номер], [ISBN книги] " + "from Заказы left join [Заказы на книги] on " + "Заказы.Номер = [Заказы на книги].[Номер заказа]) " + "as temp left join Книги on " + "temp.[ISBN книги] = Книги.ISBN group by [Дата оформления]"; SqlCommand command = new SqlCommand(request, connector.SqlConnection); SqlDataAdapter sda = new SqlDataAdapter(command); DataTable dataTable = new DataTable("Продавцы"); sda.Fill(dataTable); Prices = new ChartValues <Int32>(); Dates = new List <String>(); foreach (DataRow EachRaw in dataTable.Rows) { Dates.Add(EachRaw[0].ToString().Remove(11)); Prices.Add(Int32.Parse(EachRaw[1].ToString())); } FromDate = Dates[0]; ToDate = Dates[Dates.Count - 1]; }
public static TSeriesView AsSeriesView <TSeriesView>(this IChartValues values) where TSeriesView : ISeriesView, new() { return(new TSeriesView { Values = values }); }
/* Send serial port data string and add to graph line series */ public void addValues(string values) { //Check to make sure data lines up, discards broken lines if (values.Split(',').Length == serialValues.Length) { int index = 0; foreach (string value in values.Split(',')) { IChartValues chartValues = serialValues[index].Values; chartValues.Add(double.Parse(value)); //Modifys chart to only graph x values at a time (simulate real time graphing) if (chartValues.Count > 20) { chartValues.RemoveAt(0); } index++; } //Update chart every cycle to reflect new changes Dispatcher.Invoke(new Action(() => { chart.Series = chartSeries; })); } }
public void UpdateSeries(string path, DateTime timestamp, float value) { long id = GetCounterId(path); UpdateDatabase(id, timestamp, value); MeasureModel newValue = new MeasureModel(timestamp, Math.Round(value, 2)); List <Series> listeners; if (CounterListeners.TryGetValue(path, out listeners)) { foreach (Series series in listeners) { IChartValues values = series.Values; values.Add(newValue); // Update axis limits if chart is visible if (series.DataContext != BindingOperations.DisconnectedSource) { var chartItem = (ChartItem)series.DataContext; chartItem?.SetAxisLimits(timestamp); } if (values.Count > maxPointsPerChart) { values.RemoveAt(0); } } } }
public MainViewModel() { SetInitial(RequiredSize / 2, RequiredSize / 2); const double FPS60 = 1000d / 60d; var interval = TimeSpan.FromMilliseconds(FPS60); //var interval = TimeSpan.FromMilliseconds(200); timer = new DispatcherTimer { Interval = interval, IsEnabled = false, }; timer.Tick += (o, e) => Next(); phi1Series = new ChartValues <double>(); phi2Series = new ChartValues <double>(); ISeriesView CreateView(IChartValues v) => new LineSeries { Values = v, Fill = Brushes.Transparent, StrokeThickness = 0.5d, PointGeometry = null, }; Series = new SeriesCollection { CreateView(phi1Series), CreateView(phi2Series), }; }
public MainWindow() { InitializeComponent(); values = new ChartValues <double>(); SeriesCollection = new SeriesCollection { new LineSeries { Title = "Ошибка", Values = values } }; Labels = new string[count]; for (int i = 0; i < count / even; ++i) { Labels[i] = ((i + 1) * even).ToString(); } YFormatter = value => (value).ToString("p"); DataContext = this; }
/// <summary> /// Создать линейный график. /// </summary> /// <param name="values">Значения узлов.</param> /// <param name="title">Название.</param> /// <param name="pointDiameter">Диаметр узла.</param> /// <param name="stroke">Цвет линии.</param> /// <returns>LineSeries.</returns> private static LineSeries NewLineSeries(IChartValues values, string title, double pointDiameter, Brush stroke) => new LineSeries { Values = values, PointDiameter = pointDiameter, StrokeThickness = 2, Fill = Brushes.Transparent, LabelPoint = TooltipLabelPoint, Title = title, Stroke = stroke };
/// <summary> /// Maps chart values to a series view. /// </summary> /// <param name="values">The values to map to a series view.</param> /// <typeparam name="TSeriesView">The type of the series view.</typeparam> /// <returns>The series view mapped from the values.</returns> /// <exception cref="ArgumentNullException">Thrown when values is null.</exception> public static TSeriesView AsSeriesView <TSeriesView>(this IChartValues values) where TSeriesView : ISeriesView, new() { if (values == null) { throw new ArgumentNullException(nameof(values)); } return(new TSeriesView { Values = values }); }
private void DrawSet(string title, IChartValues values) { this.SeriesCollection.Add(new LineSeries { Title = title, StrokeThickness = 1, LineSmoothness = 0, Fill = System.Windows.Media.Brushes.Transparent, PointGeometry = null, DataLabels = false, Values = values }); }
public static void AddAPie(SeriesCollection seriesCollection, string title, IChartValues values, Func <ChartPoint, string> piePointLabel = null) { PieSeries pie = new PieSeries { Title = title, Values = values, DataLabels = true, PushOut = 2, LabelPoint = piePointLabel }; seriesCollection.Add(pie); }
private double GetAverage(IChartValues values) { double avg = 0f; double sum = 0f; foreach (ObservablePoint v in values) { sum += v.Y; } avg = sum / values.Count; return(avg); }
private void RenderWave() { //TODO: handle different types of waves and proper number of samples and all the hard stuff... WavePointSeriesCollection = new SeriesCollection(); if (waveValues == null) { waveValues = new ChartValues <float>(); } else { waveValues.Clear(); } Random rand = new Random(DateTime.Now.Millisecond); int samples = 360; for (float sampleIndex = 0; sampleIndex <= samples; sampleIndex++) { float x_rad = (float)(sampleIndex * Math.PI / 180.0); //Sine //float y = (float)(Amplitude * Math.Sin(Frequency * x_rad)); //Triangle //float x = (float)( (Math.Abs( ((Frequency * sampleIndex) % 4) - 2) - 1) * Amplitude); //Sawtooth //float x = (float)(-1 * ((Amplitude * 2) / Math.PI) * Math.Atan(1 / Math.Tan((x_rad * Math.PI / Frequency)))); //float x = (float)(Amplitude * (Frequency * x_rad) % 1); //Square //float x = (float)(Amplitude * Math.Sign(Math.Sin((2 * Math.PI * Frequency) * x_rad))); //Noize! //float x = (float)rand.NextDouble() * Amplitude; //waveValues.Add(y); } WavePointSeriesCollection.Add(new LineSeries { Values = waveValues, LineSmoothness = 0.0, //0: straight lines, 1: really smooth lines PointGeometry = DefaultGeometries.None, PointForeground = Brushes.LightBlue }); }
public Window_ChartData(Chart _Chart, ChartType.Chart_Type type) { InitializeComponent(); chart = _Chart; Ctype = type; dt.Columns.Add("C1", typeof(double)); dt.Rows.Add("0"); datagrid.DataContext = dt.DefaultView; int s = 0; foreach (Series ser in chart.Series) { IChartValues values = ser.Values; for (int i = 0; i < values.Count; i++) { if (s >= dt.Rows.Count) { dt.Rows.Add("0"); } if (i >= dt.Columns.Count) { dt.Columns.Add("C" + col, typeof(double)); col++; } dt.Rows[s][i] = ConvertType <Double>(values[i]); Debug.WriteLine(ConvertType <Double>(values[i])); } s++; } if (chart.SeriesColors != null) { RB_CusColors.IsChecked = true; foreach (Color col in chart.SeriesColors) { AddColor(col); } } }
public string[] SetValues(IChartValues collection, DataTable dataTable, int dataXcolumn, int dataYcolumn) { string[] labels = new string[dataTable.Rows.Count]; Queue <string> queue = new Queue <string>(); collection.Clear(); object[] values = new object[dataTable.Rows.Count]; for (int j = 0; j < dataTable.Rows.Count; j++) { queue.Enqueue(dataTable.Rows[j][dataXcolumn].ToString()); double st = Convert.ToDouble(dataTable.Rows[j][dataYcolumn]); collection.Add(st); } labels = queue.ToArray(); return(labels); }
public HistoryUserControlViewModel() { var mapper = new LiveCharts.Configurations.CartesianMapper <double>().X((values, index) => index).Y((values) => values).Fill((v, i) => i == DateTime.Now.Hour ? Brushes.White : Brushes.White).Stroke((v, i) => i == DateTime.Now.Hour ? Brushes.White : Brushes.White); LiveCharts.Charting.For <double>(mapper, LiveCharts.SeriesOrientation.Horizontal); Period = new List <string>() { "Day", "Month", "Year" }; Mesec = new List <string>() { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; Godina = new List <string>() { "2020", "2019", "2018", "2017", "2016", "2015" }; _itemsDay = new ObservableCollection <DayItem>(); _itemsMonth = new ObservableCollection <MonthItem>(); _itemsYear = new ObservableCollection <YearItem>(); SelectedPeriod = Period[0]; IsDan = Visibility.Visible; _chartValues = new ChartValues <double>(); for (int j = 0; j <= 24; j++) { _chartValues.Add(0.0); } _chartValuesMonth = new ChartValues <double>(); for (int j = 0; j <= 31; j++) { _chartValuesMonth.Add(0.0); } _chartValuesYear = new ChartValues <double>(); for (int j = 0; j <= 12; j++) { _chartValuesYear.Add(0.0); } _min = false; _max = false; _avg = false; _selectedGID = 0; }
private void CreateChart(string[] years, string title, IChartValues values, bool isMoney, string axisYtitle, double minValue, double maxValue, string axisXtitle) { Label labelTitle = ViewUtils.CreateLabel(title, "StyleLabel2Center", 18, -1); spMain.Children.Add(labelTitle); SeriesCollection averageClubLevelInGameCollection = new SeriesCollection { new LineSeries { Title = title, Values = values, } }; CartesianChart cc = new CartesianChart(); cc.Width = 800; cc.Height = 375; cc.Series = averageClubLevelInGameCollection; Axis axisY = new Axis(); axisY.Title = axisYtitle; axisY.MinValue = minValue; axisY.MaxValue = maxValue; if (isMoney) { axisY.LabelFormatter = YFormatter; } Axis axisX = new Axis(); axisX.Title = axisXtitle; axisX.Labels = years; cc.AxisY.Add(axisY); cc.AxisX.Add(axisX); spMain.Children.Add(cc); }
public void ToChartData(SeriesCollection series) { SeriesD.Clear(); int s = 0; foreach (Series ser in series) { ChartRowData rowdata = new ChartRowData(); IChartValues values = ser.Values; for (int i = 0; i < values.Count; i++) { rowdata.ColumnsValues.Add(ConvertType <Double>(values[i])); } rowdata.DataLabel = ser.DataLabels; rowdata.FontSize = ser.FontSize; rowdata.Title = ser.Title; rowdata.StrokeColor = (SolidColorBrush)ser.Stroke; SeriesD.Add(rowdata); s++; } }
public SpeedCharts() { InitializeComponent(); ResourceDictionarySet.Instance.FillResourceDic(this, this.Resources); if (Design.IsInDesignMode) { return; } Guid mainCoinId = NTMinerRoot.Current.MinerProfile.CoinId; VirtualRoot.On <GpuSpeedChangedEvent>("显卡算力变更后刷新算力图界面", LogEnum.DevConsole, action: (message) => { UIThread.Execute(() => { if (mainCoinId != NTMinerRoot.Current.MinerProfile.CoinId) { mainCoinId = NTMinerRoot.Current.MinerProfile.CoinId; foreach (var speedChartVm in Vm.SpeedChartVms) { SeriesCollection series = speedChartVm.Series; SeriesCollection seriesShadow = speedChartVm.SeriesShadow; foreach (var item in series) { item.Values.Clear(); } foreach (var item in seriesShadow) { item.Values.Clear(); } } } IGpuSpeed gpuSpeed = message.Source; int index = gpuSpeed.Gpu.Index; if (Vm.SpeedChartVms.ContainsKey(index)) { SpeedChartViewModel speedChartVm = Vm.SpeedChartVms[index]; SeriesCollection series = speedChartVm.Series; SeriesCollection seriesShadow = speedChartVm.SeriesShadow; DateTime now = DateTime.Now; if (gpuSpeed.MainCoinSpeed != null && series.Count > 0) { IChartValues chartValues = series[0].Values; chartValues.Add(new MeasureModel() { DateTime = gpuSpeed.MainCoinSpeed.SpeedOn, Value = gpuSpeed.MainCoinSpeed.Value }); if (((MeasureModel)chartValues[0]).DateTime.AddMinutes(NTMinerRoot.Current.SpeedHistoryLengthByMinute) < now) { chartValues.RemoveAt(0); } chartValues = seriesShadow[0].Values; chartValues.Add(new MeasureModel() { DateTime = gpuSpeed.MainCoinSpeed.SpeedOn, Value = gpuSpeed.MainCoinSpeed.Value }); if (((MeasureModel)chartValues[0]).DateTime.AddMinutes(NTMinerRoot.Current.SpeedHistoryLengthByMinute) < now) { chartValues.RemoveAt(0); } } if (gpuSpeed.DualCoinSpeed != null && series.Count > 1) { IChartValues chartValues = series[1].Values; chartValues.Add(new MeasureModel() { DateTime = gpuSpeed.DualCoinSpeed.SpeedOn, Value = gpuSpeed.DualCoinSpeed.Value }); if (((MeasureModel)chartValues[0]).DateTime.AddMinutes(NTMinerRoot.Current.SpeedHistoryLengthByMinute) < now) { chartValues.RemoveAt(0); } chartValues = seriesShadow[1].Values; chartValues.Add(new MeasureModel() { DateTime = gpuSpeed.DualCoinSpeed.SpeedOn, Value = gpuSpeed.DualCoinSpeed.Value }); if (((MeasureModel)chartValues[0]).DateTime.AddMinutes(NTMinerRoot.Current.SpeedHistoryLengthByMinute) < now) { chartValues.RemoveAt(0); } } speedChartVm.SetAxisLimits(now); } }); }).AddToCollection(_handlers); Vm.ItemsPanelColumns = 1; this.Unloaded += (object sender, RoutedEventArgs e) => { foreach (var handler in _handlers) { VirtualRoot.UnPath(handler); } foreach (var item in Vm.SpeedChartVms) { item.Series = null; item.SeriesShadow = null; item.AxisX = null; item.AxisY = null; item.AxisXShadow = null; item.AxisYShadow = null; } _chartDic.Clear(); }; SolidColorBrush White = new SolidColorBrush(Colors.White); Vm.PropertyChanged += (object sender, System.ComponentModel.PropertyChangedEventArgs e) => { if (e.PropertyName == nameof(Vm.CurrentSpeedChartVm)) { SpeedChartViewModel currentItem = Vm.CurrentSpeedChartVm; if (currentItem != null) { foreach (var item in _chartDic.Values) { item.Visibility = Visibility.Collapsed; } CartesianChart chart; if (!_chartDic.ContainsKey(currentItem)) { chart = new CartesianChart() { DisableAnimations = true, Hoverable = false, DataTooltip = null, Background = White, Padding = new Thickness(4, 0, 0, 0), Visibility = Visibility.Visible }; chart.Series = currentItem.SeriesShadow; chart.AxisX = currentItem.AxisXShadow; chart.AxisY = currentItem.AxisYShadow; _chartDic.Add(currentItem, chart); DetailsGrid.Children.Add(chart); } else { chart = _chartDic[currentItem]; chart.Visibility = Visibility.Visible; } } } }; Vm.SetCurrentSpeedChartVm(Vm.SpeedChartVms.FirstOrDefault()); if (MinerProfileViewModel.Current.CoinVm != null) { Guid coinId = MinerProfileViewModel.Current.CoinId; foreach (var item in NTMinerRoot.Current.GpuSet) { List <IGpuSpeed> gpuSpeedHistory = item.GetGpuSpeedHistory(); SpeedChartViewModel speedChartVm = Vm.SpeedChartVms[item.Index]; SeriesCollection series = speedChartVm.Series; SeriesCollection seriesShadow = speedChartVm.SeriesShadow; DateTime now = DateTime.Now; foreach (var gpuSpeed in gpuSpeedHistory) { if (gpuSpeed.MainCoinSpeed != null && series.Count > 0) { series[0].Values.Add(new MeasureModel() { DateTime = gpuSpeed.MainCoinSpeed.SpeedOn, Value = gpuSpeed.MainCoinSpeed.Value }); seriesShadow[0].Values.Add(new MeasureModel() { DateTime = gpuSpeed.MainCoinSpeed.SpeedOn, Value = gpuSpeed.MainCoinSpeed.Value }); } if (gpuSpeed.DualCoinSpeed != null && series.Count > 1) { series[0].Values.Add(new MeasureModel() { DateTime = gpuSpeed.DualCoinSpeed.SpeedOn, Value = gpuSpeed.DualCoinSpeed.Value }); seriesShadow[0].Values.Add(new MeasureModel() { DateTime = gpuSpeed.DualCoinSpeed.SpeedOn, Value = gpuSpeed.DualCoinSpeed.Value }); } } IChartValues values = series[0].Values; if (values.Count > 0 && ((MeasureModel)values[0]).DateTime.AddMinutes(NTMinerRoot.Current.SpeedHistoryLengthByMinute) < now) { series[0].Values.RemoveAt(0); } values = seriesShadow[0].Values; if (values.Count > 0 && ((MeasureModel)values[0]).DateTime.AddMinutes(NTMinerRoot.Current.SpeedHistoryLengthByMinute) < now) { seriesShadow[0].Values.RemoveAt(0); } speedChartVm.SetAxisLimits(now); } } }
private void autoCorrectInStance(ref List <int> inStanceArray, ref List <int> switches, ref IChartValues observables) { int singleSwitchSegmentAvgLen = GaitNumberOfFrames / switches.Count; int threshold = singleSwitchSegmentAvgLen / 4; //our clustering threshold is one quarter threshold++; //rounding up for (int i = 1; i < switches.Count - 2; i++) { if (switches[i + 1] - switches[i] < threshold) //if we have a bad one { if (switches[i] - switches[i - 1] > threshold && switches[i + 2] - switches[i + 1] > threshold && inStanceArray[switches[i - 1]] == inStanceArray[switches[i + 1]]) //check its immediate neighbors and see if they're good and the same type (stance/swing) { for (int j = switches[i]; j < switches[i + 1]; j++) //if so, correct this bad guy with the neighboring guys' value { inStanceArray[j] = inStanceArray[switches[i - 1]]; ((ObservablePoint)observables[j]).Y = inStanceArray[j]; //and update the actual 0 or 1 value in the corresponding chart values (ObservablePoint changes update the chart automatically) } } } } }
public string[] SetValues(IChartValues collection, DataTable dataTable, int dateColumn, int timeColumn, int dataColumn, System.DateTime startDate, System.DateTime endDate, int startHour, int endHour, int startMin, int endMin) { string[] labels = new string[dataTable.Rows.Count]; Queue <string> queue = new Queue <string>(); collection.Clear(); System.DateTime currentDate = startDate; System.DateTime currentTime = startDate; System.DateTime stopTime = endDate; stopTime = stopTime.AddHours(endHour); stopTime = stopTime.AddMinutes(endMin); System.DateTime startTime = startDate; startTime = startTime.AddHours(startHour); startTime = startTime.AddMinutes(startMin); object[] values = new object[dataTable.Rows.Count]; System.DateTime[] dataTime = new DateTime[dataTable.Rows.Count]; Dictionary <System.DateTime, int> dates = new Dictionary <System.DateTime, int>(); for (int j = 0; j < dataTable.Rows.Count; j++) { try { dataTime[j] = Convert.ToDateTime(dataTable.Rows[j][dateColumn]); int hours = Convert.ToDateTime(dataTable.Rows[j][timeColumn]).Hour; int minutes = Convert.ToDateTime(dataTable.Rows[j][timeColumn]).Minute; dataTime[j] = dataTime[j].AddHours(hours); dataTime[j] = dataTime[j].AddMinutes(minutes); dates.Add(dataTime[j], j); values[j] = dataTable.Rows[j][dataColumn]; } catch (Exception ex) { } } int increment = (int)Math.Ceiling(((stopTime - startTime).TotalMinutes) / 72); //System.DateTime timeOfMaxValue = dates.Aggregate((x, y) => x.Value > y.Value ? x : y).Key; int numberOfPoints = 0; int statrIndex = 0; int stopIndex = 0; if (dates.ContainsKey(startTime)) { statrIndex = dates[startTime]; } else { statrIndex = 0; } if (dates.ContainsKey(stopTime)) { stopIndex = dates[stopTime]; } else { stopIndex = dates.Count - 1; } while (startTime < stopTime) { queue.Enqueue(startTime.ToString()); if (dates.ContainsKey(startTime)) { collection.Add(Convert.ToDouble(values[dates[startTime]])); } else { collection.Add(0d); } startTime = startTime.AddMinutes(increment); //numberOfPoints++; } //numberOfPoints = numberOfPoints * increment; numberOfPoints = stopIndex - statrIndex; Double[] vs = new double[numberOfPoints]; int indexOfMax = 0; int indexOfMin = 0; maxValue = 0d; minValue = 0d; for (int i = 0; i < numberOfPoints - 1; i++) { try { vs[i] = Convert.ToDouble(values[i + statrIndex]); if (vs[i] > maxValue) { maxValue = vs[i]; indexOfMax = i + statrIndex; } if (vs[i] != 0d) { if ((minValue == 0d) || (vs[i] < minValue)) { minValue = vs[i]; indexOfMin = i + statrIndex; } } } catch (Exception ex) { System.Windows.MessageBox.Show(ex.Message + ";" + statrIndex.ToString() + ";" + numberOfPoints.ToString()); break; } } timeOfMaxValue = dataTime[indexOfMax]; timeOfMinValue = dataTime[indexOfMin]; //MessageBox.Show(timeOfMaxValue.ToString() + ";" + maxValue.ToString() + ";" + statrIndex.ToString() + ";" + numberOfPoints.ToString()); labels = queue.ToArray(); return(labels); }
private void RefreshTotalSpeedChart(int limit) { //NTMinerRoot.Current.DebugLine($"获取总算力数据,范围{leftTime} - {rightTime}"); RpcRoot.Server.ControlCenterService.GetLatestSnapshotsAsync( limit, (response, exception) => { if (response == null) { return; } if (!response.IsSuccess()) { Write.UserFail(response.ReadMessage(exception)); return; } UIThread.Execute(() => { bool isOnlyOne = limit == 1; Vm.TotalMiningCount = response.TotalMiningCount; Vm.TotalOnlineCount = response.TotalOnlineCount; foreach (var chartVm in Vm.ChartVms) { var list = response.Data.Where(a => a.CoinCode == chartVm.CoinVm.Code).ToList(); if (list.Count == 0) { list.Add(new CoinSnapshotData { CoinCode = chartVm.CoinVm.Code, DualCoinOnlineCount = 0, DualCoinMiningCount = 0, MainCoinOnlineCount = 0, MainCoinMiningCount = 0, RejectShareDelta = 0, ShareDelta = 0, Speed = 0, Timestamp = DateTime.Now.AddSeconds(-5) }); } CoinSnapshotData one = null; if (isOnlyOne) { one = list.Last(); } else { list = list.OrderBy(a => a.Timestamp).ToList(); } CoinSnapshotData latestData = list.Last(); chartVm.SnapshotDataVm.Update(latestData); foreach (var riser in chartVm.Series) { if (riser.Title == "speed") { if (list.Count > 0) { if (isOnlyOne) { riser.Values.Add(new MeasureModel() { DateTime = one.Timestamp, Value = one.Speed }); } else { foreach (var item in list) { riser.Values.Add(new MeasureModel() { DateTime = item.Timestamp, Value = item.Speed }); } } } } else if (riser.Title == "onlineCount") { if (isOnlyOne) { riser.Values.Add(new MeasureModel() { DateTime = one.Timestamp, Value = one.MainCoinOnlineCount + one.DualCoinOnlineCount }); } else { foreach (var item in list) { riser.Values.Add(new MeasureModel() { DateTime = item.Timestamp, Value = item.MainCoinOnlineCount + item.DualCoinOnlineCount }); } } } else if (riser.Title == "miningCount") { if (isOnlyOne) { riser.Values.Add(new MeasureModel() { DateTime = one.Timestamp, Value = one.MainCoinMiningCount + one.DualCoinMiningCount }); } else { foreach (var item in list) { riser.Values.Add(new MeasureModel() { DateTime = item.Timestamp, Value = item.MainCoinMiningCount + item.DualCoinMiningCount }); } } } else if (riser.Title == "rejectShare") { if (isOnlyOne) { riser.Values.Add(new MeasureModel() { DateTime = one.Timestamp, Value = one.RejectShareDelta }); } else { foreach (var item in list) { riser.Values.Add(new MeasureModel() { DateTime = item.Timestamp, Value = item.RejectShareDelta }); } } } else if (riser.Title == "acceptShare") { if (isOnlyOne) { riser.Values.Add(new MeasureModel() { DateTime = one.Timestamp, Value = one.ShareDelta }); } else { foreach (var item in list) { riser.Values.Add(new MeasureModel() { DateTime = item.Timestamp, Value = item.ShareDelta }); } } } } DateTime now = DateTime.Now.AddSeconds(10); foreach (var riser in chartVm.Series) { IChartValues valuesTotal = riser.Values; if (valuesTotal.Count > 0 && ((MeasureModel)valuesTotal[0]).DateTime.AddMinutes(NTMinerRoot.SpeedHistoryLengthByMinute) < now) { valuesTotal.RemoveAt(0); } } chartVm.SetAxisLimits(now); } }); }); }
public SpeedCharts() { if (WpfUtil.IsInDesignMode) { return; } this.Vm = new SpeedChartsViewModel(); this.DataContext = this.Vm; InitializeComponent(); if (WpfUtil.IsInDesignMode) { return; } Guid mainCoinId = NTMinerContext.Instance.MinerProfile.CoinId; this.OnLoaded((window) => { window.AddEventPath <GpuSpeedChangedEvent>("显卡算力变更后刷新算力图界面", LogEnum.DevConsole, action: (message) => { UIThread.Execute(() => { if (mainCoinId != NTMinerContext.Instance.MinerProfile.CoinId) { mainCoinId = NTMinerContext.Instance.MinerProfile.CoinId; foreach (var speedChartVm in Vm.SpeedChartVms.Items) { SeriesCollection series = speedChartVm.Series; SeriesCollection seriesShadow = speedChartVm.SeriesShadow; foreach (var item in series) { item.Values.Clear(); } foreach (var item in seriesShadow) { item.Values.Clear(); } } } IGpuSpeed gpuSpeed = message.Source; int index = gpuSpeed.Gpu.Index; if (Vm.SpeedChartVms.ContainsKey(index)) { SpeedChartViewModel speedChartVm = Vm.SpeedChartVms[index]; SeriesCollection series = speedChartVm.Series; SeriesCollection seriesShadow = speedChartVm.SeriesShadow; DateTime now = DateTime.Now; if (gpuSpeed.MainCoinSpeed != null && series.Count > 0) { IChartValues chartValues = series[0].Values; chartValues.Add(new MeasureModel() { DateTime = gpuSpeed.MainCoinSpeed.SpeedOn, Value = gpuSpeed.MainCoinSpeed.Value }); if (((MeasureModel)chartValues[0]).DateTime.AddMinutes(NTMinerContext.SpeedHistoryLengthByMinute) < now) { chartValues.RemoveAt(0); } chartValues = seriesShadow[0].Values; chartValues.Add(new MeasureModel() { DateTime = gpuSpeed.MainCoinSpeed.SpeedOn, Value = gpuSpeed.MainCoinSpeed.Value }); if (((MeasureModel)chartValues[0]).DateTime.AddMinutes(NTMinerContext.SpeedHistoryLengthByMinute) < now) { chartValues.RemoveAt(0); } } if (gpuSpeed.DualCoinSpeed != null && series.Count > 1) { IChartValues chartValues = series[1].Values; chartValues.Add(new MeasureModel() { DateTime = gpuSpeed.DualCoinSpeed.SpeedOn, Value = gpuSpeed.DualCoinSpeed.Value }); if (((MeasureModel)chartValues[0]).DateTime.AddMinutes(NTMinerContext.SpeedHistoryLengthByMinute) < now) { chartValues.RemoveAt(0); } chartValues = seriesShadow[1].Values; chartValues.Add(new MeasureModel() { DateTime = gpuSpeed.DualCoinSpeed.SpeedOn, Value = gpuSpeed.DualCoinSpeed.Value }); if (((MeasureModel)chartValues[0]).DateTime.AddMinutes(NTMinerContext.SpeedHistoryLengthByMinute) < now) { chartValues.RemoveAt(0); } } speedChartVm.SetAxisLimits(now); } }); }, location: this.GetType()); }); Vm.PropertyChanged += (object sender, System.ComponentModel.PropertyChangedEventArgs e) => { if (e.PropertyName == nameof(Vm.CurrentSpeedChartVm)) { SpeedChartViewModel currentItem = Vm.CurrentSpeedChartVm; if (currentItem != null) { foreach (var item in _chartDic.Values) { item.Visibility = Visibility.Collapsed; } CartesianChart chart; if (!_chartDic.ContainsKey(currentItem)) { chart = new CartesianChart() { DisableAnimations = true, Hoverable = false, DataTooltip = null, Background = WpfUtil.WhiteBrush, Padding = new Thickness(4, 0, 0, 0), Visibility = Visibility.Visible }; chart.Series = currentItem.SeriesShadow; chart.AxisX = currentItem.AxisXShadow; chart.AxisY = currentItem.AxisYShadow; _chartDic.Add(currentItem, chart); DetailsGrid.Children.Add(chart); } else { chart = _chartDic[currentItem]; chart.Visibility = Visibility.Visible; } } } }; Vm.CurrentSpeedChartVm = Vm.SpeedChartVms.Items.FirstOrDefault(); if (AppRoot.MinerProfileVm.CoinVm != null) { Guid coinId = AppRoot.MinerProfileVm.CoinId; foreach (var item in NTMinerContext.Instance.GpuSet.AsEnumerable()) { List <IGpuSpeed> gpuSpeedHistory = item.GetGpuSpeedHistory(); SpeedChartViewModel speedChartVm = Vm.SpeedChartVms[item.Index]; SeriesCollection series = speedChartVm.Series; SeriesCollection seriesShadow = speedChartVm.SeriesShadow; DateTime now = DateTime.Now; foreach (var gpuSpeed in gpuSpeedHistory) { if (gpuSpeed.MainCoinSpeed != null && series.Count > 0) { series[0].Values.Add(new MeasureModel() { DateTime = gpuSpeed.MainCoinSpeed.SpeedOn, Value = gpuSpeed.MainCoinSpeed.Value }); seriesShadow[0].Values.Add(new MeasureModel() { DateTime = gpuSpeed.MainCoinSpeed.SpeedOn, Value = gpuSpeed.MainCoinSpeed.Value }); } if (gpuSpeed.DualCoinSpeed != null && series.Count > 1) { series[0].Values.Add(new MeasureModel() { DateTime = gpuSpeed.DualCoinSpeed.SpeedOn, Value = gpuSpeed.DualCoinSpeed.Value }); seriesShadow[0].Values.Add(new MeasureModel() { DateTime = gpuSpeed.DualCoinSpeed.SpeedOn, Value = gpuSpeed.DualCoinSpeed.Value }); } } IChartValues values = series[0].Values; if (values.Count > 0 && ((MeasureModel)values[0]).DateTime.AddMinutes(NTMinerContext.SpeedHistoryLengthByMinute) < now) { series[0].Values.RemoveAt(0); } values = seriesShadow[0].Values; if (values.Count > 0 && ((MeasureModel)values[0]).DateTime.AddMinutes(NTMinerContext.SpeedHistoryLengthByMinute) < now) { seriesShadow[0].Values.RemoveAt(0); } speedChartVm.SetAxisLimits(now); } } }
/// <summary> /// Maps chart values to a line series. /// </summary> /// <param name="values">The values to map to a line series.</param> /// <returns>The line series mapped from the values.</returns> public static LineSeries AsLineSeries(this IChartValues values) { return(values.AsSeriesView <LineSeries>()); }
/// <summary> /// Maps chart values to a column series. /// </summary> /// <param name="values">The values to map to a column series.</param> /// <returns>The column series mapped from the values.</returns> public static ColumnSeries AsColumnSeries(this IChartValues values) { return(values.AsSeriesView <ColumnSeries>()); }
private void RefreshTotalSpeedChart(int limit) { //NTMinerRoot.Current.DebugLine($"获取总算力数据,范围{leftTime} - {rightTime}"); var coinCodes = NTMinerRoot.Current.CoinSet.Select(a => a.Code).ToList(); Server.ControlCenterService.GetLatestSnapshots( limit, coinCodes, (response) => { if (response == null) { return; } Execute.OnUIThread(() => { bool isOnlyOne = limit == 1; Vm.TotalMiningCount = response.TotalMiningCount; Vm.TotalOnlineCount = response.TotalOnlineCount; //NTMinerRoot.Current.DebugLine($"获取了{data.Count}条"); foreach (var chartVm in Vm.TotalVms) { var list = response.Data.Where(a => a.CoinCode == chartVm.CoinVm.Code).ToList(); if (list.Count != 0) { list = list.OrderBy(a => a.Timestamp).ToList(); CoinSnapshotData latestData = list.Last(); chartVm.SnapshotDataVm.Update(latestData); foreach (var seriy in chartVm.Series) { if (seriy.Title == "speed") { if (list.Count > 0) { if (isOnlyOne) { var item = list.Last(); seriy.Values.Add(new MeasureModel() { DateTime = item.Timestamp, Value = item.Speed }); } else { foreach (var item in list) { seriy.Values.Add(new MeasureModel() { DateTime = item.Timestamp, Value = item.Speed }); } } } } else if (seriy.Title == "onlineCount") { if (isOnlyOne) { var item = list.Last(); seriy.Values.Add(new MeasureModel() { DateTime = item.Timestamp, Value = item.MainCoinOnlineCount + item.DualCoinOnlineCount }); } else { foreach (var item in list) { seriy.Values.Add(new MeasureModel() { DateTime = item.Timestamp, Value = item.MainCoinOnlineCount + item.DualCoinOnlineCount }); } } } else if (seriy.Title == "miningCount") { if (isOnlyOne) { var item = list.Last(); seriy.Values.Add(new MeasureModel() { DateTime = item.Timestamp, Value = item.MainCoinMiningCount + item.DualCoinMiningCount }); } else { foreach (var item in list) { seriy.Values.Add(new MeasureModel() { DateTime = item.Timestamp, Value = item.MainCoinMiningCount + item.DualCoinMiningCount }); } } } } } DateTime now = DateTime.Now; foreach (var seriy in chartVm.Series) { IChartValues valuesTotal = seriy.Values; if (valuesTotal.Count > 0 && ((MeasureModel)valuesTotal[0]).DateTime.AddMinutes(NTMinerRoot.Current.SpeedHistoryLengthByMinute) < now) { valuesTotal.RemoveAt(0); } } } }); }); }
// MARK: Chart Setup Methods private void SetUpPawCharts() //set up the primary top 4 charts corresponding to mouse's paws // Temporary arrays to apply same operation to each component { var charts = new CartesianChart[] { LeftHindChart, LeftFrontChart, RightHindChart, RightFrontChart }; var observables = new IChartValues[] { HindLeftObservables, FrontLeftObservables, HindRightObservables, FrontRightObservables }; var scatters = new IChartValues[] { HindLeftScatter, FrontLeftScatter, HindRightScatter, FrontRightScatter }; GaitNumberOfFrames = HindLeftInStance.Count; //a few more values we need to initialize but needed to parse the .csv for first XMAX = GaitNumberOfFrames; FPS = (int)(GaitNumberOfFrames / GaitVideoLength); if (GaitFirstSetup) { // First time setup // Set up zooming along the X axis for all paw charts foreach (var chart in charts) { chart.Zoom = ZoomingOptions.X; } // Add a scatter plot to each chart with a single value // (it will be moving through the chart as the current frame updates to indicate to the user which x value corresponds to the frame they're seeing) foreach (var scatter in scatters) { scatter.Add(new ObservablePoint()); } GaitFirstSetup = false; } else { // Reset Charts for (int i = 0; i < charts.Length; i++) { charts[i].Series.Clear(); observables[i].Clear(); } } for (int i = 0; i < HindLeftInStance.Count; i++) //set the .csv results { HindLeftObservables.Add(new ObservablePoint(i, HindLeftInStance[i])); //set up list values for all charts as Observable Points (chart will automatically update if there's a change to any of its values) HindRightObservables.Add(new ObservablePoint(i, HindRightInStance[i])); FrontLeftObservables.Add(new ObservablePoint(i, FrontLeftInStance[i])); FrontRightObservables.Add(new ObservablePoint(i, FrontRightInStance[i])); } // Clear the x an y axes that are created by default and add custom ones PrimaryGaitGrid.Visibility = Visibility.Visible; foreach (var chart in charts) { chart.AxisX.Clear(); chart.AxisY.Clear(); } // Set Charts (leftHind, LeftFront, RightHind, RightFront) for (int i = 0; i < charts.Length; i++) { charts[i].AxisX.Add(new Axis { MaxValue = XMAX, MinValue = XMIN }); ((Axis)(charts[i].AxisX[0])).RangeChanged += new LiveCharts.Events.RangeChangedHandler(Axis_RangeChanged); //sync zooming charts[i].AxisY.Add(new Axis { MaxValue = YMAX, MinValue = YMIN, LabelFormatter = val => val == 0 ? "Swing" : "Stance" }); charts[i].Series.Add(new LineSeries { //also add all the values that indicate if the mouse is in stance or swing Values = observables[i], PointGeometrySize = 0, LineSmoothness = 0, }); charts[i].Series.Add(new ScatterSeries { //and add the single point that shows which x value we're looking at (i.e. which x corresponds to the current frame) Values = scatters[i], PointGeometry = DefaultGeometries.Circle, }); } FrameSlider.Value = 0; //move to the beginning with the slider FrameSlider.Maximum = GaitNumberOfFrames - 1; //sets its maximum ZoomSliderEndBox.Text = (GaitNumberOfFrames - 1).ToString(); //and update the zoom slider's end box (upper boundary of the zoom segment) with last frame's index }