private void createAxis() { //Configuration of X-Axis label progressionChart.AxisX.Clear(); //Clear to redraw X-Axis labels Axis xAxis = new Axis(); xAxis.LabelFormatter = (Func <double, string>)((IRLVProgressionChartVM)ViewModel).XLabelFormatter; xAxis.Title = ((IRLVProgressionChartVM)ViewModel).XAxisTitle; var chartPointsCount = chartValues.Count; if (chartPointsCount <= 0) { return; } double max = chartValues.Select(a => a.Time).Max(); double min = chartValues.Select(a => a.Time).Min(); double max_min = max - min; double step = max_min / 20; if (step > 0 || chartPointsCount == 1) { if (chartPointsCount == 1) { step = max / 20; } var newStep = Math.Ceiling(max / step); if (chartPointsCount <= 10 && chartPointsCount > 1) { newStep = 10; } xAxis.Separator = new LiveCharts.Wpf.Separator { Step = step, IsEnabled = false }; xAxis.LabelsRotation = 20; progressionChart.AxisX.Add(xAxis); //Add back X-Axis to chart //Configuration of Y-Axis label progressionChart.AxisY.Clear(); //Clear to redraw Y-Axis labels Axis yAxis = new Axis(); yAxis.LabelFormatter = (Func <double, string>)((IRLVProgressionChartVM)ViewModel).YLabelFormatter; yAxis.Title = ((IRLVProgressionChartVM)ViewModel).YAxisTitle; progressionChart.AxisY.Add(yAxis); //Add back Y-Axis to chart progressionChart.Zoom = ZoomingOptions.Xy; } }
public async Task WhenCreatingViewModelForMetricChartWithDataThenThenItIsCreatedSuccessfully() { // Create view model MetricChartPropertyControlViewModel viewModel = await this.CreateViewModel(); // Verify results Assert.IsFalse(viewModel.ReadChartValuesTask.IsRunning); ChartValues <DateTimePoint> points = viewModel.ReadChartValuesTask.Result; Assert.IsNotNull(points); Enumerable.SequenceEqual(this.timestamps, points.Select(p => p.DateTime)); Enumerable.SequenceEqual(this.values, points.Select(p => p.Value)); }
public static (SeriesCollection ValueSeries, List <string> Labels) GetOhlcChartData(IReadOnlyList <IStockQuoteFromDataSource> stockQuoteFromDataSources) { var stockSeries = new ChartValues <OhlcPoint>(); var labels = new List <string>(); foreach (IStockQuoteFromDataSource item in stockQuoteFromDataSources) { stockSeries.Add(new OhlcPoint { Open = (double)item.OpenPrice, High = (double)item.HighPrice, Low = (double)item.LowPrice, Close = (double)item.ClosePrice }); labels.Add(item.TradeDateTime.ToShortDateString()); } var seriesCol = new SeriesCollection { new OhlcSeries() { Title = stockQuoteFromDataSources[0].StockId, Values = stockSeries }, new LineSeries { Title = stockQuoteFromDataSources[0].StockId, Values = new ChartValues <double>(stockSeries.Select(x => x.Close)), Fill = Brushes.Transparent } }; return(seriesCol, labels); }
// static readonly CancellationTokenSource s_cts = new CancellationTokenSource(); public Graph() { InitializeComponent(); var mapper = Mappers.Xy <MeasureModel>() .X(model => model.ValueX) //use DateTime.Ticks as X .Y(model => model.ValueY); //use the value property as Y Charting.For <MeasureModel>(mapper); // ChartValues = new ChartValues<MeasureModel>(); ChartValues = SQLAdapter.FetchAsync().Result; LineSeries lineSeries = new LineSeries { Title = "Длина волны", Values = ChartValues, StrokeThickness = 1, Stroke = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(0, 0, 0)), Fill = System.Windows.Media.Brushes.Transparent, LineSmoothness = 0, PointGeometrySize = 0, PointForeground = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(0, 0, 0)), Opacity = 0, OpacityMask = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(0, 0, 0)) }; SeriesCollection = new SeriesCollection(); SeriesCollection.Add(lineSeries); MaxX = ChartValues.Select(x => x.ValueX).Max(); MinX = ChartValues.Select(x => x.ValueX).Min(); MinY = 0; DataContext = this; }
private void CalculateRegression() { var x = Vector.Create(ChartValues.Select(v => v.NDouble).ToArray()); var y = Vector.Create(ChartValues.Select(v => v.TotDouble).ToArray()); _regression = new SimpleRegressionModel(y, x); _regression.Fit(); UpperValues.Clear(); LowerValues.Clear(); RegressionValues.Clear(); NToNValues.Clear(); XAxis.Clear(); YAxis.Clear(); var max = ChartValues.Max(p => p.NDouble); XAxis.Add(new ObservablePoint(0, 0)); XAxis.Add(new ObservablePoint(0, max)); YAxis.Add(new ObservablePoint(0, 0)); YAxis.Add(new ObservablePoint(max, 0)); NToNValues.Add(new ObservablePoint(0, 0)); NToNValues.Add(new ObservablePoint(max, max)); var ci = _regression.GetPredictionInterval(0, .99); UpperValues.Add(new ObservablePoint(0, ci.UpperBound)); LowerValues.Add(new ObservablePoint(0, ci.LowerBound)); RegressionValues.Add(new ObservablePoint(0, ci.Center)); ci = _regression.GetPredictionInterval(max, .99); UpperValues.Add(new ObservablePoint(max, ci.UpperBound)); LowerValues.Add(new ObservablePoint(max, ci.LowerBound)); RegressionValues.Add(new ObservablePoint(max, ci.Center)); var above = 0.0; var below = 0.0; foreach (var point in ChartValues) { var interval = _regression.GetPredictionInterval(point.NDouble, .99); if (point.TotDouble <= interval.UpperBound && point.TotDouble > interval.Center) { above++; } else if (point.TotDouble <= interval.Center && point.TotDouble >= interval.LowerBound) { below++; } } Console.WriteLine("Above Center: " + above / ChartValues.Count); Console.WriteLine("Below Center: " + below / ChartValues.Count); }
private void GetButton_Click(object sender, RoutedEventArgs e) { ushort[] b = ModbusCommand.command.Operation(Getter.channel_ch1); var x = (double)((float)b[0]) / 1000 + 1520; //26 page nm var y = (double)Utility.GetSingle(0, b[1]); string s = x.ToString("R") + " " + y.ToString("R") + Environment.NewLine; Showblock.Text += s; MeasureModel measureModel = new MeasureModel() { ValueX = x, ValueY = y }; if (_values.Count > 800) { _values.RemoveAt(0); } _values.Add(measureModel); Graph2.MaxX = _values.Select(m => m.ValueX).Max(); Graph2.MinX = _values.Select(m => m.ValueX).Min(); Graph2.MinY = 0; // Graph2.max = 0; }
private void LoadJson(string fileFullPath) { try { ohlcChartValues.Clear(); volumeChartValues.Clear(); string jsonString = File.ReadAllText(fileFullPath); var candles = JsonConvert.DeserializeObject <List <MarketCandle> >(jsonString); foreach (var candle in candles.Take(250)) { var ohlc = new OhlcPoint((double)candle.OpenPrice, (double)candle.HighPrice, (double)candle.LowPrice, (double)candle.ClosePrice); ohlcChartValues.Add(ohlc); volumeChartValues.Add(new VolumePair(candle.QuoteCurrencyVolume, (ohlc.Close >= ohlc.Open))); } Y2Max = volumeChartValues.Select(v => v.Volume).Max() * 5; // stretch the y-axis by 5x. } catch (Exception ex) { MessageBox.Show(ex.Message); } }