void RefreshPeaksGraph() { Part_Plotter.Children.Remove(m_peaksGraph); m_peaksGraph = null; var data = this.ViewModel.CurrentDataItem?.DataItem; if (data != null && data.LocatedPeaks != null) { EnumerableDataSource <PeakInfo> locatedPeaksDS = new EnumerableDataSource <PeakInfo>(data.LocatedPeaks); locatedPeaksDS.SetXMapping((item) => item.Pos.X); locatedPeaksDS.SetYMapping((item) => item.Pos.Y); m_peaksGraph = new ElementMarkerPointsGraph(locatedPeaksDS) { Marker = new PeaksMarker() { Size = 10, Fill = Brushes.Yellow, ContextMenu = this.TryFindResource("PeakMarkerContextMenu") as ContextMenu } //Marker = new CircleElementPointMarker() { Size = 10, Fill = Brushes.Yellow, ToolTipText = "Jouda" } }; locatedPeaksDS.AddMapping(PeaksMarker.ToolTipTextProperty, (peakInfo) => peakInfo.ArtifactPeakSample.ToString()); locatedPeaksDS.AddMapping(PeaksMarker.DataContextProperty, (peakInfo) => peakInfo); Part_Plotter.Children.Add(m_peaksGraph); } RefreshSelectedPeakGraph(); RefreshCalculatedThresholdGraph(); OrderGraphs(); }
void RefreshSelectedPeakGraph() { Part_Plotter.Children.Remove(m_selectedPeakGraph); m_selectedPeakGraph = null; var peakInfo = this.ViewModel.CurrentDataItem?.SelectedPeakInfo; if (peakInfo != null) { PeakInfo[] point = new PeakInfo[] { peakInfo.PeakInfo }; EnumerableDataSource <PeakInfo> locatedPeaksDS = new EnumerableDataSource <PeakInfo>(point); locatedPeaksDS.SetXMapping((item) => item.Pos.X); locatedPeaksDS.SetYMapping((item) => item.Pos.Y); locatedPeaksDS.AddMapping(PeaksMarker.DataContextProperty, (peakInfoItem) => peakInfoItem); m_selectedPeakGraph = new ElementMarkerPointsGraph(locatedPeaksDS) { Marker = new SelectedPeaksMarker() { Size = 10, Pen = new Pen(Brushes.BlanchedAlmond, 1), Fill = Brushes.Transparent, ContextMenu = this.TryFindResource("PeakMarkerContextMenu") as ContextMenu } }; Part_Plotter.Children.Add(m_selectedPeakGraph); OrderGraphs(); } }
/// <summary> /// 显示曲线图表 /// </summary> /// <param name="vm"></param> private void ShowCurve(WeightCurveViewModel vm) { DateTime[] dates = (from r in vm.WeightCurveDataList select DateTime.Parse(r.recordtime)).ToArray(); decimal[] weightList = (from r in vm.WeightCurveDataList select r.recorddata).ToArray(); var xDataSource = new EnumerableDataSource <DateTime>(dates); xDataSource.SetXMapping(x => dateAxis.ConvertToDouble(x)); var yDataSource = new EnumerableDataSource <decimal>(weightList); yDataSource.SetYMapping(y => Convert.ToDouble(y)); yDataSource.AddMapping(ShapeElementPointMarker.ToolTipTextProperty, Y => String.Format("{0}", Y)); ds = new CompositeDataSource(xDataSource, yDataSource); plotter.Children.RemoveAll(typeof(LineGraph)); plotter.Children.RemoveAll(typeof(MarkerPointsGraph)); plotter.Children.RemoveAll(typeof(ElementMarkerPointsGraph)); plotter.Children.RemoveAll(typeof(Microsoft.Research.DynamicDataDisplay.Charts.Navigation.CursorCoordinateGraph)); chart = plotter.AddLineGraph(ds, new Pen(Brushes.LimeGreen, 2), new CircleElementPointMarker { Size = 5, Brush = Brushes.Red, Fill = Brushes.Orange, Pen = new Pen(Brushes.Blue, 5) }, new PenDescription("重量曲线")); plotter.Children.Add(new CursorCoordinateGraph()); plotter.FitToView(); }
private void MainWindow_Loaded(object sender, RoutedEventArgs e) { // Prepare data in arrays const int N = 100; double[] x = new double[N]; double[] y = new double[N]; for (int i = 0; i < N; i++) { x[i] = i * 0.1; y[i] = Math.Cos(x[i]); } // Add data sources: var yDataSource = new EnumerableDataSource<double>(y); yDataSource.SetYMapping(Y => Y); yDataSource.AddMapping(ShapeElementPointMarker.ToolTipTextProperty, Y => string.Format("Value is {0}", Y)); var xDataSource = new EnumerableDataSource<double>(x); xDataSource.SetXMapping(X => X); CompositeDataSource compositeDataSource = new CompositeDataSource(xDataSource, yDataSource); plotter.Viewport.Restrictions.Add(new PhysicalProportionsRestriction { ProportionRatio = 1 }); // adding graph to plotter plotter.AddLineGraph(compositeDataSource, new Pen(Brushes.Goldenrod, 3), new SampleMarker(), new PenDescription("Cosine")); }
private void Button_Click(object sender, RoutedEventArgs e) { List <Point> list = new List <Point>(); Random rnd = new Random(); for (int i = 0; i < 300; i++) { list.Add(new Point(i, rnd.Next(50))); } EnumerableDataSource <Point> edc; edc = new EnumerableDataSource <Point>(list); edc.SetXMapping(x => x.X); edc.SetYMapping(y => Convert.ToDouble(y.Y)); edc.AddMapping(CircleElementPointMarker.ToolTipTextProperty, s => String.Format("Y-Data : {0}\nX-Data : {1}", s.Y, s.X)); LineGraph line = new LineGraph(edc); plotter.Children.Add(line); //, line.LinePen = new Pen(Brushes.Transparent, 3); //line. new CircleElementPointMarker //{ // Size = 15, // Brush = border, // Fill = c2 //}; // null // )); }
private void MainWindow_Loaded(object sender, RoutedEventArgs e) { // Prepare data in arrays const int N = 1000; double[] x = new double[N]; double[] y = new double[N]; for (int i = 0; i < N; i++) { x[i] = i * 0.1; y[i] = Math.Cos(x[i]); } // Add data sources: var yDataSource = new EnumerableDataSource <double>(y); yDataSource.SetYMapping(Y => Y); yDataSource.AddMapping(ShapeElementPointMarker.ToolTipTextProperty, Y => string.Format("Value is {0}", Y)); var xDataSource = new EnumerableDataSource <double>(x); xDataSource.SetXMapping(X => X); CompositeDataSource compositeDataSource = new CompositeDataSource(xDataSource, yDataSource); Matrix m = Matrix.Identity; m.RotateAt(45, 10, 10); line = new LineGraph { Stroke = Brushes.Green, StrokeThickness = 2, DataTransform = //new MatrixDataTransform(m) new RotateDataTransform(45.0.DegreesToRadians()) }; line.DataSource = compositeDataSource; line.AddToPlotter(plotter); plotter.Viewport.Restrictions.Add(new PhysicalProportionsRestriction { ProportionRatio = 1 }); // adding graph to plotter plotter.AddLineGraph(compositeDataSource, new Pen(Brushes.Goldenrod, 3), new SampleMarker(), new PenDescription("Cosine")); //plotter.Viewport.FitToViewRestrictions.Add(new FollowDataWidthRestriction { Width = 1 }); plotter.PreviewKeyDown += plotter_KeyDown; }
private void MainWindow_Loaded(object sender, RoutedEventArgs e) { // Prepare data in arrays const int N = 100; double[] x = new double[N]; double[] y = new double[N]; for (int i = 0; i < N; i++) { x[i] = i * 0.1; y[i] = Math.Cos(x[i]); } // Add data sources: var yDataSource = new EnumerableDataSource<double>(y); yDataSource.SetYMapping(Y => Y); yDataSource.AddMapping(ShapeElementPointMarker.ToolTipTextProperty, Y => string.Format("Value is {0}", Y)); var xDataSource = new EnumerableDataSource<double>(x); xDataSource.SetXMapping(X => X); CompositeDataSource compositeDataSource = new CompositeDataSource(xDataSource, yDataSource); Matrix m = Matrix.Identity; m.RotateAt(45, 10, 10); line = new LineGraph { Stroke = Brushes.Green, StrokeThickness = 2, DataTransform = //new MatrixDataTransform(m) new RotateDataTransform(45.0.DegreesToRadians()) }; line.DataSource = compositeDataSource; line.AddToPlotter(plotter); plotter.Viewport.Constraints.Add(new PhysicalProportionsConstraint { ProportionRatio = 1 }); // adding graph to plotter plotter.AddLineGraph(compositeDataSource, new Pen(Brushes.Goldenrod, 3), new SampleMarker(), new PenDescription("Cosine")); //plotter.Viewport.FitToViewRestrictions.Add(new FollowDataWidthRestriction { Width = 1 }); plotter.PreviewKeyDown += plotter_KeyDown; }
public LineGraphData(int size, string description) { // Array for data data = new RingArray<DataPoint>(size); // Convert to an enumerable data source for line graph ds = new EnumerableDataSource<DataPoint>(data); // and set mappings ds.SetXMapping(x => x.X); ds.SetYMapping(y => y.Y); ds.AddMapping(ShapeElementPointMarker.ToolTipTextProperty, p => string.Format("{0}, {1}, " + description, p.X, p.Y)); }
private EnumerableDataSource <DataPoint> CreateDataSource(IEnumerable <DataPoint> data) { EnumerableDataSource <DataPoint> ds = new EnumerableDataSource <DataPoint>(data); MercatorTransform transform = new MercatorTransform(); ds.SetXMapping(p => p.X); ds.SetYMapping(p => transform.DataToViewport(new Point(0, p.Y)).Y); ds.AddMapping(CirclePointMarker.FillProperty, dp => { double alpha = (dp.Data - currentRange.Min) / (currentRange.Max - currentRange.Min); Debug.Assert(0 <= alpha && alpha <= 1); const double hueWidth = 100; double hue = hueWidth * (alpha - 0.5) + hueSlider.Value; if (hue > 360) { hue -= 360; } else if (hue < 0) { hue += 360; } Debug.Assert(0 <= hue && hue <= 360); Color mainColor = new HsbColor(hue, 1, 0 + 1 * alpha, 0.3 + 0.7 * alpha).ToArgbColor(); const int colorCount = 5; GradientStopCollection colors = new GradientStopCollection(colorCount); double step = 1.0 / (colorCount - 1); for (int i = 0; i < colorCount; i++) { Color color = mainColor; double x = attSlider.Value * step * i; color.A = (byte)(255 * Math.Exp(-x * x)); colors.Add(new GradientStop(color, step * i)); } return(new RadialGradientBrush(colors)); }); return(ds); }
private EnumerableDataSource<DataPoint> CreateDataSource(IEnumerable<DataPoint> data) { EnumerableDataSource<DataPoint> ds = new EnumerableDataSource<DataPoint>(data); MercatorTransform transform = new MercatorTransform(); ds.SetXMapping(p => p.X); ds.SetYMapping(p => transform.DataToViewport(new Point(0, p.Y)).Y); ds.AddMapping(CirclePointMarker.FillProperty, dp => { double alpha = (dp.Data - currentRange.Min) / (currentRange.Max - currentRange.Min); Debug.Assert(0 <= alpha && alpha <= 1); const double hueWidth = 100; double hue = hueWidth * (alpha - 0.5) + hueSlider.Value; if (hue > 360) hue -= 360; else if (hue < 0) hue += 360; Debug.Assert(0 <= hue && hue <= 360); Color mainColor = new HsbColor(hue, 1, 0 + 1 * alpha, 0.3 + 0.7 * alpha).ToArgbColor(); const int colorCount = 5; GradientStopCollection colors = new GradientStopCollection(colorCount); double step = 1.0 / (colorCount - 1); for (int i = 0; i < colorCount; i++) { Color color = mainColor; double x = attSlider.Value * step * i; color.A = (byte)(255 * Math.Exp(-x * x)); colors.Add(new GradientStop(color, step * i)); } return new RadialGradientBrush(colors); }); return ds; }
public TooltipSample() { InitializeComponent(); // Prepare data in arrays for (int i = 0; i < N; i++) { x[i] = i * 0.2; y[i] = Math.Cos(x[i]); } // Add data sources: yDataSource = new EnumerableDataSource<double>(y); yDataSource.SetYMapping(Y => Y); yDataSource.AddMapping(ShapeElementPointMarker.ToolTipTextProperty, Y => String.Format("Value is {0}", Y)); xDataSource = new EnumerableDataSource<double>(x); xDataSource.SetXMapping(X => X); ds = new CompositeDataSource(xDataSource, yDataSource); // adding graph to plotter // todo //chart = plotter.AddLineGraph(ds, // new Pen(Brushes.LimeGreen, 3), // new CircleElementPointMarker // { // Size = 10, // Brush = Brushes.Red, // Fill = Brushes.Orange // }, // new PenDescription("Cosine")); plotter.Children.Add(new CursorCoordinateGraph()); // Force evertyhing plotted to be visible plotter.FitToView(); }
private void dataSource(List <CurrencyInfo> rates) { EnumerableDataSource <CurrencyInfo> xDataSource = new EnumerableDataSource <CurrencyInfo>(rates); EnumerableDataSource <CurrencyInfo> yDataSource = new EnumerableDataSource <CurrencyInfo>(rates); yDataSource.SetYMapping(y => y.BidPrice); yDataSource.AddMapping(ShapeElementPointMarker.ToolTipTextProperty, y => String.Format("BidPrice is {0}", y.BidPrice)); xDataSource.SetXMapping(x => x.CurrentTime); ds = new CompositeDataSource(xDataSource, yDataSource); chart = plotter.AddLineGraph(ds, new Pen(Brushes.LimeGreen, 1), new CircleElementPointMarker { Size = 5, Brush = Brushes.Red, Fill = Brushes.Orange }, new PenDescription("BidPrice")); plotter.Children.Add(new CursorCoordinateGraph()); plotter.FitToView(); }
public TooltipSample() { InitializeComponent(); // Prepare data in arrays for (int i = 0; i < N; i++) { x[i] = i * 0.2; y[i] = Math.Cos(x[i]); } // Add data sources: yDataSource = new EnumerableDataSource <double>(y); yDataSource.SetYMapping(Y => Y); yDataSource.AddMapping(ShapeElementPointMarker.ToolTipTextProperty, Y => String.Format("Value is {0}", Y)); xDataSource = new EnumerableDataSource <double>(x); xDataSource.SetXMapping(X => X); ds = new CompositeDataSource(xDataSource, yDataSource); // adding graph to plotter // todo //chart = plotter.AddLineGraph(ds, // new Pen(Brushes.LimeGreen, 3), // new CircleElementPointMarker // { // Size = 10, // Brush = Brushes.Red, // Fill = Brushes.Orange // }, // new PenDescription("Cosine")); plotter.Children.Add(new CursorCoordinateGraph()); // Force evertyhing plotted to be visible plotter.FitToView(); }
private void MainWindow_Loaded(object sender, RoutedEventArgs e) { // Prepare data in arrays const int N = 100; double[] x = new double[N]; double[] y = new double[N]; for (int i = 0; i < N; i++) { x[i] = i * 0.1; y[i] = Math.Cos(x[i]); } // Add data sources: var yDataSource = new EnumerableDataSource <double>(y); yDataSource.SetYMapping(Y => Y); yDataSource.AddMapping(ShapeElementPointMarker.ToolTipTextProperty, Y => string.Format("Value is {0}", Y)); var xDataSource = new EnumerableDataSource <double>(x); xDataSource.SetXMapping(X => X); CompositeDataSource compositeDataSource = new CompositeDataSource(xDataSource, yDataSource); plotter.Viewport.Restrictions.Add(new PhysicalProportionsRestriction { ProportionRatio = 1 }); // adding graph to plotter plotter.AddLineGraph(compositeDataSource, new Pen(Brushes.Goldenrod, 3), new SampleMarker(), new PenDescription("Cosine")); }
private void dataSource1(List <Record> rates) { EnumerableDataSource <Record> xDataSource = new EnumerableDataSource <Record>(rates); EnumerableDataSource <Record> yDataSource = new EnumerableDataSource <Record>(rates); yDataSource.SetYMapping(y => y.BidPrices[0]); yDataSource.AddMapping(ShapeElementPointMarker.ToolTipTextProperty, y => String.Format("BidPrice is {0}", y.BidPrices[0])); xDataSource.SetXMapping(x => dateAxisBidP.ConvertToDouble(x.Time)); xDataSource.AddMapping(ShapeElementPointMarker.ToolTipTextProperty, x => String.Format("Time is {0}", x.Time.ToString(CultureInfo.InvariantCulture))); ds = new CompositeDataSource(xDataSource, yDataSource); chart = plotter.AddLineGraph(ds, new Pen(Brushes.LimeGreen, 3), new CircleElementPointMarker { Size = 5, Brush = Brushes.Red, Fill = Brushes.Orange }, new PenDescription("BidPrice")); plotter.Children.Add(new CursorCoordinateGraph()); //plotter.FitToView(); }
private void Button_Click(object sender, RoutedEventArgs e) { List<Point> list = new List<Point>(); Random rnd = new Random(); for (int i = 0; i < 300; i++) { list.Add(new Point(i, rnd.Next(50))); } EnumerableDataSource<Point> edc; edc = new EnumerableDataSource<Point>(list); edc.SetXMapping(x => x.X); edc.SetYMapping(y => Convert.ToDouble(y.Y)); edc.AddMapping(CircleElementPointMarker.ToolTipTextProperty, s => String.Format("Y-Data : {0}\nX-Data : {1}", s.Y, s.X)); LineGraph line =new LineGraph(edc); plotter.Children.Add(line); //, line.LinePen = new Pen(Brushes.Transparent, 3); //line. new CircleElementPointMarker //{ // Size = 15, // Brush = border, // Fill = c2 //}; // null // )); }
private void PlotNormalDistribution(double[] data, Histogram histogram, string distributionName, Color color) { if (data == null || histogram == null) return; var points = 50; var normalDistribution = new NormalDistribution(data.Average(), Math.Variance(data), points, histogram.LowerBound, histogram.UpperBound); //var normalDistribution = new NormalDistribution(histogram.Mean(), histogram.Variance(), points, histogram.LowerBound, histogram.UpperBound); var densityCurve = normalDistribution.DensityCurve; var xValues = new double[points]; var yValues = new double[points]; for (var index = 0; index < points; index++) { xValues[index] = densityCurve[index, 0]; yValues[index] = densityCurve[index, 1]; } // Add data sources. var yDataSource = new EnumerableDataSource<double>(yValues); yDataSource.SetYMapping(Y => Y); yDataSource.AddMapping(ShapeElementPointMarker.ToolTipTextProperty, Y => string.Format("Normal Value \n\n{0}", Y)); var xDataSource = new EnumerableDataSource<double>(xValues); xDataSource.SetXMapping(X => X); var compositeDataSource = new CompositeDataSource(xDataSource, yDataSource); // MatchValuePlotter.Viewport.Restrictions.Add(new PhysicalProportionsRestriction { ProportionRatio = 500000 }); var graph = ChartPlotter.AddLineGraph(compositeDataSource, color, 0.5, distributionName); // Cache for later usage (e.g. change visibility). if (graph != null) _histogramGraphs.Add(graph); }
private void PlotNonlinearity(Nonlinearity nonlinearity, string distributionName, Color color, double lineThickness) { if (nonlinearity == null) return; var curve = nonlinearity.FiringRateCurve; // Prepare data in arrays. var x = new double[curve.GetLength(0)]; var y = new double[curve.GetLength(0)]; for (var index = 0; index < curve.GetLength(0); index++) { x[index] = curve[index, 0]; y[index] = curve[index, 1]; } // Add data sources. var yDataSource = new EnumerableDataSource<double>(y); yDataSource.SetYMapping(Y => Y); yDataSource.AddMapping(ShapeElementPointMarker.ToolTipTextProperty, Y => string.Format("Normal Value \n\n{0}", Y)); var xDataSource = new EnumerableDataSource<double>(x); xDataSource.SetXMapping(X => X); var compositeDataSource = new CompositeDataSource(xDataSource, yDataSource); // MatchValuePlotter.Viewport.Restrictions.Add(new PhysicalProportionsRestriction { ProportionRatio = 500000 }); var graph = ChartPlotter.AddLineGraph(compositeDataSource, color, lineThickness, distributionName); // Cache for later usage (e.g. change visibility). if (graph != null) _histogramGraphs.Add(graph); }
private void PlotHistogram(Histogram histogram, string histogramName, Color color) { if (histogram == null) return; // Prepare data in arrays. var pointIndex = 0; var dataPointCount = 4 * histogram.BucketCount; var x = new double[dataPointCount]; var y = new double[dataPointCount]; foreach (var bucket in histogram.Buckets()) { //var yValue = bucket.Count; var yValue = bucket.RelativeCount(histogram); // lower left point of the histogram bar x[pointIndex] = bucket.LowerBound; y[pointIndex] = 0; // upper left point of the histogram bar x[pointIndex + 1] = bucket.LowerBound; y[pointIndex + 1] = yValue; // upper right point of the histogram bar x[pointIndex + 2] = bucket.UpperBound; y[pointIndex + 2] = yValue; // lower right point of the histogram bar x[pointIndex + 3] = bucket.UpperBound; y[pointIndex + 3] = 0; pointIndex += 4; } // Add data sources. var yDataSource = new EnumerableDataSource<double>(y); yDataSource.SetYMapping(Y => Y); yDataSource.AddMapping(ShapeElementPointMarker.ToolTipTextProperty, Y => string.Format("Match Value \n\n{0}", Y)); var xDataSource = new EnumerableDataSource<double>(x); xDataSource.SetXMapping(X => X); var compositeDataSource = new CompositeDataSource(xDataSource, yDataSource); // MatchValuePlotter.Viewport.Restrictions.Add(new PhysicalProportionsRestriction { ProportionRatio = 500000 }); var graph = ChartPlotter.AddLineGraph(compositeDataSource, color, 1, histogramName); // Cache for later usage (e.g. change visibility). if (graph != null) _histogramGraphs.Add(graph); }
private LineAndMarker<ElementMarkerPointsGraph> PlotEigenvalues(int cell, Brush brush) { double[] eigenValues; double[][] eigenVectors; var stc = SpikeTriggeredAnalysis.CalculateSTC(_stimuli, new double[][][] { _spikes[cell - 1] }, RoundStrategy.Round); SpikeTriggeredAnalysis.CalculateEigenValues(stc, out eigenValues, out eigenVectors); // Prepare data in arrays var N = eigenValues.Length; var x = new double[N]; var y = new double[N]; for (var index = 0; index < N; index++) { x[index] = index; y[index] = eigenValues[index]; } // Add data sources: var yDataSource = new EnumerableDataSource<double>(y); yDataSource.SetYMapping(Y => Y); yDataSource.AddMapping(ShapeElementPointMarker.ToolTipTextProperty, Y => string.Format("Cell {0} - Eigenvalue \n\n{1}", cell, Y)); var xDataSource = new EnumerableDataSource<double>(x); xDataSource.SetXMapping(X => X); var compositeDataSource = new CompositeDataSource(xDataSource, yDataSource); EigenvaluePlotter.Viewport.Restrictions.Add(new PhysicalProportionsRestriction { ProportionRatio = 30 }); var graph = EigenvaluePlotter.AddLineGraph(compositeDataSource, new Pen(brush, 1), new SampleMarker() { Brush = brush }, new PenDescription(string.Format("Eigenvalues of Cell {0}", cell))); return graph; }
void LogYWindow_Loaded(object sender, RoutedEventArgs e) { //ChartPlotter plotter = new ChartPlotter(); //plotter.Children.Add(new CursorCoordinateGraph()); //plotter.DataTransform = new Log10YTransform(); //VerticalAxis axis = new VerticalAxis //{ // TicksProvider = new LogarithmNumericTicksProvider(10), // LabelProvider = new UnroundingLabelProvider() //}; //plotter.MainVerticalAxis = axis; //plotter.AxisGrid.DrawVerticalMinorTicks = true; //const int count = 500; //double[] xs = Enumerable.Range(1, count).Select(x => x * 0.01).ToArray(); //EnumerableDataSource<double> xDS = xs.AsXDataSource(); //var pows = xs.Select(x => Math.Pow(10, x)); //var linear = xs.Select(x => x); //var logXs = Enumerable.Range(101, count).Select(x => x * 0.01); //var logarithmic = logXs.Select(x => Math.Log10(x)); //plotter.AddLineGraph(pows.AsYDataSource().Join(xDS), "f(x) = 10^x"); //plotter.AddLineGraph(linear.AsYDataSource().Join(xDS), "f(x) = x"); //plotter.AddLineGraph(logarithmic.AsYDataSource().Join(logXs.AsXDataSource()), "f(x) = log(x)"); //Content = plotter; ChartPlotter plotter = new ChartPlotter(); plotter.DataTransform = new Log10YTransform(); VerticalAxis yAxis = new VerticalAxis { TicksProvider = new LogarithmNumericTicksProvider(10), LabelProvider = new UnroundingLabelProvider() }; plotter.MainVerticalAxis = yAxis; plotter.AxisGrid.DrawVerticalMinorTicks = true; HorizontalDateTimeAxis xAxis = new HorizontalDateTimeAxis(); plotter.MainHorizontalAxis = xAxis; EnumerableDataSource<TPoint> edsPow = new EnumerableDataSource<TPoint>( Enumerable.Range(1, 2000).Select(s => new TPoint { X = DateTime.Now.AddYears(-20).AddDays(s), Y = Math.Pow(10, s / 5000.0) } ).ToList()); //edsPow.SetXYMapping(s => new Point(xax.ConvertToDouble(s.X), s.Y)); edsPow.SetXMapping(s => xAxis.ConvertToDouble(s.X)); edsPow.SetYMapping(s => yAxis.ConvertToDouble(s.Y)); edsPow.AddMapping(ShapeElementPointMarker.ToolTipTextProperty, s => String.Format("Vol:{0}\r\nOn:{1}", s.Y, s.X.ToShortDateString())); EnumerableDataSource<TPoint> edsLinear = new EnumerableDataSource<TPoint>( Enumerable.Range(1, 2000).Select(s => new TPoint { X = DateTime.Now.AddYears(-20).AddDays(s), Y = s / 2000.0 } ).ToList()); //edsLinear.SetXYMapping(s => new Point(xax.ConvertToDouble(s.X), s.Y)); edsLinear.SetXMapping(s => xAxis.ConvertToDouble(s.X)); edsLinear.SetYMapping(s => yAxis.ConvertToDouble(s.Y)); edsLinear.AddMapping(ShapeElementPointMarker.ToolTipTextProperty, s => String.Format("Vol:{0}\r\nOn:{1}", s.Y, s.X.ToShortDateString())); edsLog10 = new EnumerableDataSource<TPoint>( Enumerable.Range(1, 2000).Select(s => new TPoint { X = DateTime.Now.AddYears(-20).AddDays(s), Y = Math.Log10(s) } ).Where(s => s.Y > 0).ToList()); //edsLog10.SetXYMapping(s => new Point(xax.ConvertToDouble(s.X), s.Y)); edsLog10.SetXMapping(s => xAxis.ConvertToDouble(s.X)); edsLog10.SetYMapping(s => yAxis.ConvertToDouble(s.Y)); edsLog10.AddMapping(ShapeElementPointMarker.ToolTipTextProperty, s => String.Format("Vol:{0}\r\nOn:{1}", s.Y, s.X.ToShortDateString())); SolidColorBrush brushPow = new SolidColorBrush(Colors.Green); Pen linePenPow = new Pen(brushPow, 2.0); CircleElementPointMarker markerPow = new CircleElementPointMarker { Size = 4, Brush = brushPow, Fill = brushPow }; PenDescription descPow = new PenDescription("f(x) = 10 ^ x"); //var chartPow = plotter.AddLineGraph(edsPow, linePenPow, (ShapeElementPointMarker)null/*markerPow*/, descPow); SolidColorBrush brushLinear = new SolidColorBrush(Colors.Blue); Pen linePenLinear = new Pen(brushLinear, 2.0); CircleElementPointMarker markerLinear = new CircleElementPointMarker { Size = 4, Brush = brushLinear, Fill = brushLinear }; PenDescription descLinear = new PenDescription("f(x) = x"); //var chartLinear = plotter.AddLineGraph(edsLinear, linePenLinear, (ShapeElementPointMarker)null/*markerLinear*/, descLinear); SolidColorBrush brushLog10 = new SolidColorBrush(Colors.Red); Pen linePenLog10 = new Pen(brushLog10, 2.0); CircleElementPointMarker markerLog10 = new CircleElementPointMarker { Size = 4, Brush = brushLog10, Fill = brushLog10 }; PenDescription descLog10 = new PenDescription("f(x) = log(x)"); var chartLog10 = plotter.AddLineGraph(edsLog10, linePenLog10, (ShapeElementPointMarker)null/*markerLog10*/, descLog10); //plotter.Children.Add(new DataFollowChart(chartPow.LineGraph).WithProperty(c => //{ // c.Marker.SetValue(Shape.FillProperty, brushPow); // c.Marker.SetValue(Shape.StrokeProperty, brushPow.MakeDarker(0.2)); //})); //plotter.Children.Add(new DataFollowChart(chartLinear.LineGraph).WithProperty(c => //{ // c.Marker.SetValue(Shape.FillProperty, brushLinear); // c.Marker.SetValue(Shape.StrokeProperty, brushLinear.MakeDarker(0.2)); //})); plotter.Children.Add(new CursorCoordinateGraph()); ValueStore store = new ValueStore(); DataFollowChart dataFollowChart = new DataFollowChart(chartLog10.LineGraph); dataFollowChart.Marker.SetValue(Shape.FillProperty, brushLog10); dataFollowChart.Marker.SetValue(Shape.StrokeProperty, brushLog10.ChangeLightness(0.8)); dataFollowChart.MarkerPositionChanged += new EventHandler(dataFollowChart_MarkerPositionChanged); //dataFollowChart.CustomDataContextCallback = () => // { // if (dataFollowChart.ClosestPointIndex != -1) // { // var closestPoint = ((List<TPoint>)edsLog10.Data)[dataFollowChart.ClosestPointIndex]; // return store.SetValue("X", closestPoint.Y.ToString()).SetValue("Y", closestPoint.X.ToShortDateString()); // } // else return null; // }; #if true dataFollowChart.MarkerTemplate = (DataTemplate)FindResource("followMarkerTemplate"); #else dataFollowChart.MarkerAdjustCallback = marker => { Ellipse ellipse = (Ellipse)marker; var markerPosition = c.MarkerPosition; var date = xAxis.ConvertFromDouble(markerPosition.X); var y = yAxis.ConvertFromDouble(markerPosition.Y); ellipse.ToolTip = String.Format("Vol:{0}\r\nOn:{1}", y, date.ToShortDateString()); }; #endif plotter.Children.Add(dataFollowChart); Content = plotter; }
void UC_CurveChart_Loaded(object sender, RoutedEventArgs e) { List <HouseData> houseDataList = LoadHouseData("..\\..\\Data.txt"); DateTime[] dates = new DateTime[houseDataList.Count]; int[] numberSalesCompletion = new int[houseDataList.Count]; int[] numberRentCompletion = new int[houseDataList.Count]; int[] numberSalesTarget = new int[houseDataList.Count]; int[] numberRentTarget = new int[houseDataList.Count]; int totalSalesCompletion = 0; int totalRentCompletion = 0; for (int i = 0; i < houseDataList.Count; ++i) { dates[i] = houseDataList[i].date; numberSalesCompletion[i] = houseDataList[i].i_SalesCompletion; numberRentCompletion[i] = houseDataList[i].i_RentCompletion; numberSalesTarget[i] = houseDataList[i].i_SalesTarget; numberRentTarget[i] = houseDataList[i].i_RentTarget; totalSalesCompletion = totalSalesCompletion + houseDataList[i].i_SalesCompletion; totalRentCompletion = totalRentCompletion + houseDataList[i].i_RentCompletion; } var datesDataSource = new EnumerableDataSource <DateTime>(dates); datesDataSource.SetXMapping(x => dateAxis.ConvertToDouble(x)); var numberSalesDataSource = new EnumerableDataSource <int>(numberSalesCompletion); numberSalesDataSource.SetYMapping(y => y); numberSalesDataSource.AddMapping(ShapeElementPointMarker.ToolTipTextProperty, Y => String.Format("出售数量:{0}", Y)); var numberRentDataSource = new EnumerableDataSource <int>(numberRentCompletion); numberRentDataSource.SetYMapping(y => y); numberRentDataSource.AddMapping(ShapeElementPointMarker.ToolTipTextProperty, Y => String.Format("出租数量:{0}", Y)); header.Content = string.Format(@"房源总量:" + (totalSalesCompletion + totalRentCompletion).ToString() + "套(出售:" + totalSalesCompletion + "套,出租:" + totalRentCompletion + "套)"); CompositeDataSource compositeDataSource1 = new CompositeDataSource(datesDataSource, numberSalesDataSource); CompositeDataSource compositeDataSource2 = new CompositeDataSource(datesDataSource, numberRentDataSource); plotter.AddLineGraph(compositeDataSource1, new Pen(Brushes.Blue, 2), new CircleElementPointMarker { Size = 10.0, Fill = Brushes.Red }, new PenDescription("完成量")); plotter.AddLineGraph(compositeDataSource2, new Pen(Brushes.LimeGreen, 2), new CircleElementPointMarker { Size = 10.0, //Pen = new Pen(Brushes.Black, 2.0), Fill = Brushes.Orange }, new PenDescription("目标量")); CursorCoordinateGraph cursorCoordinateGraph = new CursorCoordinateGraph(); cursorCoordinateGraph.IsHorizontalDateTimeAxis = true;//横轴显示时间 plotter.Children.Add(cursorCoordinateGraph); plotter.Viewport.FitToView(); }
void LogYWindow_Loaded(object sender, RoutedEventArgs e) { //ChartPlotter plotter = new ChartPlotter(); //plotter.Children.Add(new CursorCoordinateGraph()); //plotter.DataTransform = new Log10YTransform(); //VerticalAxis axis = new VerticalAxis //{ // TicksProvider = new LogarithmNumericTicksProvider(10), // LabelProvider = new UnroundingLabelProvider() //}; //plotter.MainVerticalAxis = axis; //plotter.AxisGrid.DrawVerticalMinorTicks = true; //const int count = 500; //double[] xs = Enumerable.Range(1, count).Select(x => x * 0.01).ToArray(); //EnumerableDataSource<double> xDS = xs.AsXDataSource(); //var pows = xs.Select(x => Math.Pow(10, x)); //var linear = xs.Select(x => x); //var logXs = Enumerable.Range(101, count).Select(x => x * 0.01); //var logarithmic = logXs.Select(x => Math.Log10(x)); //plotter.AddLineGraph(pows.AsYDataSource().Join(xDS), "f(x) = 10^x"); //plotter.AddLineGraph(linear.AsYDataSource().Join(xDS), "f(x) = x"); //plotter.AddLineGraph(logarithmic.AsYDataSource().Join(logXs.AsXDataSource()), "f(x) = log(x)"); //Content = plotter; ChartPlotter plotter = new ChartPlotter(); plotter.DataTransform = new Log10YTransform(); VerticalAxis yAxis = new VerticalAxis { TicksProvider = new LogarithmNumericTicksProvider(10), LabelProvider = new UnroundingLabelProvider() }; plotter.MainVerticalAxis = yAxis; plotter.AxisGrid.DrawVerticalMinorTicks = true; HorizontalDateTimeAxis xAxis = new HorizontalDateTimeAxis(); plotter.MainHorizontalAxis = xAxis; EnumerableDataSource <TPoint> edsPow = new EnumerableDataSource <TPoint>( Enumerable.Range(1, 2000).Select(s => new TPoint { X = DateTime.Now.AddYears(-20).AddDays(s), Y = Math.Pow(10, s / 5000.0) } ).ToList()); //edsPow.SetXYMapping(s => new Point(xax.ConvertToDouble(s.X), s.Y)); edsPow.SetXMapping(s => xAxis.ConvertToDouble(s.X)); edsPow.SetYMapping(s => yAxis.ConvertToDouble(s.Y)); edsPow.AddMapping(ShapeElementPointMarker.ToolTipTextProperty, s => string.Format("Vol:{0}\r\nOn:{1}", s.Y, s.X.ToShortDateString())); EnumerableDataSource <TPoint> edsLinear = new EnumerableDataSource <TPoint>( Enumerable.Range(1, 2000).Select(s => new TPoint { X = DateTime.Now.AddYears(-20).AddDays(s), Y = s / 2000.0 } ).ToList()); //edsLinear.SetXYMapping(s => new Point(xax.ConvertToDouble(s.X), s.Y)); edsLinear.SetXMapping(s => xAxis.ConvertToDouble(s.X)); edsLinear.SetYMapping(s => yAxis.ConvertToDouble(s.Y)); edsLinear.AddMapping(ShapeElementPointMarker.ToolTipTextProperty, s => string.Format("Vol:{0}\r\nOn:{1}", s.Y, s.X.ToShortDateString())); edsLog10 = new EnumerableDataSource <TPoint>( Enumerable.Range(1, 2000).Select(s => new TPoint { X = DateTime.Now.AddYears(-20).AddDays(s), Y = Math.Log10(s) } ).Where(s => s.Y > 0).ToList()); //edsLog10.SetXYMapping(s => new Point(xax.ConvertToDouble(s.X), s.Y)); edsLog10.SetXMapping(s => xAxis.ConvertToDouble(s.X)); edsLog10.SetYMapping(s => yAxis.ConvertToDouble(s.Y)); edsLog10.AddMapping(ShapeElementPointMarker.ToolTipTextProperty, s => string.Format("Vol:{0}\r\nOn:{1}", s.Y, s.X.ToShortDateString())); SolidColorBrush brushPow = new SolidColorBrush(Colors.Green); Pen linePenPow = new Pen(brushPow, 2.0); CircleElementPointMarker markerPow = new CircleElementPointMarker { Size = 4, Brush = brushPow, Fill = brushPow }; PenDescription descPow = new PenDescription("f(x) = 10 ^ x"); //var chartPow = plotter.AddLineGraph(edsPow, linePenPow, (ShapeElementPointMarker)null/*markerPow*/, descPow); SolidColorBrush brushLinear = new SolidColorBrush(Colors.Blue); Pen linePenLinear = new Pen(brushLinear, 2.0); CircleElementPointMarker markerLinear = new CircleElementPointMarker { Size = 4, Brush = brushLinear, Fill = brushLinear }; PenDescription descLinear = new PenDescription("f(x) = x"); //var chartLinear = plotter.AddLineGraph(edsLinear, linePenLinear, (ShapeElementPointMarker)null/*markerLinear*/, descLinear); SolidColorBrush brushLog10 = new SolidColorBrush(Colors.Red); Pen linePenLog10 = new Pen(brushLog10, 2.0); CircleElementPointMarker markerLog10 = new CircleElementPointMarker { Size = 4, Brush = brushLog10, Fill = brushLog10 }; PenDescription descLog10 = new PenDescription("f(x) = log(x)"); var chartLog10 = plotter.AddLineGraph(edsLog10, linePenLog10, (ShapeElementPointMarker)null /*markerLog10*/, descLog10); //plotter.Children.Add(new DataFollowChart(chartPow.LineGraph).WithProperty(c => //{ // c.Marker.SetValue(Shape.FillProperty, brushPow); // c.Marker.SetValue(Shape.StrokeProperty, brushPow.MakeDarker(0.2)); //})); //plotter.Children.Add(new DataFollowChart(chartLinear.LineGraph).WithProperty(c => //{ // c.Marker.SetValue(Shape.FillProperty, brushLinear); // c.Marker.SetValue(Shape.StrokeProperty, brushLinear.MakeDarker(0.2)); //})); plotter.Children.Add(new CursorCoordinateGraph()); ValueStore store = new ValueStore(); DataFollowChart dataFollowChart = new DataFollowChart(chartLog10.LineGraph); dataFollowChart.Marker.SetValue(Shape.FillProperty, brushLog10); dataFollowChart.Marker.SetValue(Shape.StrokeProperty, brushLog10.ChangeLightness(0.8)); dataFollowChart.MarkerPositionChanged += new EventHandler(dataFollowChart_MarkerPositionChanged); //dataFollowChart.CustomDataContextCallback = () => // { // if (dataFollowChart.ClosestPointIndex != -1) // { // var closestPoint = ((List<TPoint>)edsLog10.Data)[dataFollowChart.ClosestPointIndex]; // return store.SetValue("X", closestPoint.Y.ToString()).SetValue("Y", closestPoint.X.ToShortDateString()); // } // else return null; // }; #if true dataFollowChart.MarkerTemplate = (DataTemplate)FindResource("followMarkerTemplate"); #else dataFollowChart.MarkerAdjustCallback = marker => { Ellipse ellipse = (Ellipse)marker; var markerPosition = c.MarkerPosition; var date = xAxis.ConvertFromDouble(markerPosition.X); var y = yAxis.ConvertFromDouble(markerPosition.Y); ellipse.ToolTip = String.Format("Vol:{0}\r\nOn:{1}", y, date.ToShortDateString()); }; #endif plotter.Children.Add(dataFollowChart); Content = plotter; }
public void plot_template() { double[] x_1 = new double[pattern.length]; double[] y_1 = new double[pattern.length]; ; for (int i = 0; i < pattern.length; i++) { x_1[i] = (double)pattern.template_x[i]; y_1[i] = (double)pattern.template_y[i]; } var yDataSource = new EnumerableDataSource<double>(y_1); yDataSource.SetYMapping(Y => Y); yDataSource.AddMapping(Microsoft.Research.DynamicDataDisplay.PointMarkers.ShapeElementPointMarker.ToolTipTextProperty, Y => string.Format("Value is {0}", Y)); var xDataSource = new EnumerableDataSource<double>(x_1); xDataSource.SetXMapping(X => X); CompositeDataSource compositeDataSource = new CompositeDataSource(xDataSource, yDataSource); chart_plotter_template = plotter.AddLineGraph(compositeDataSource, Color.FromRgb(12, 0, 4), 2, "Шаблон"); }
private void Control_Loaded(object sender, RoutedEventArgs e) { var operations = new List <Operation>(); Operation curr = null; foreach (var op in OperationsList) { if (IsFiltered(op)) { continue; } if (curr == null) { curr = new Operation(0, op.Date.AddDays(-1), string.Format("{0} ({1})", op.Date.AddDays(-1).ToShortDateString(), op.CurrentBalance.Value - op.OperationMove.Value), new OperationValue(0), new OperationValue(op.CurrentBalance.Value - op.OperationMove.Value), null); operations.Add(curr); } if ((curr == null) || (curr.Date != op.Date)) { curr = new Operation(op.ID, op.Date, string.Format("{0}\r\n {1}", op.Date.ToShortDateString(), op.ToString()), (OperationValue)op.OperationMove.Clone(), (OperationValue)op.CurrentBalance.Clone(), null); operations.Add(curr); } else { curr.Description += "\r\n " + op.ToString(); curr.OperationMove.Value += op.OperationMove.Value; curr.CurrentBalance.Value = op.CurrentBalance.Value; } } DateTime[] dates = operations.Select <Operation, DateTime>((o) => o.Date).ToArray(); var currBalanceDataSource = new EnumerableDataSource <Operation>(operations); currBalanceDataSource.SetXMapping(x => dateAxis.ConvertToDouble(x.Date)); currBalanceDataSource.SetYMapping(y => y.CurrentBalance.Value); currBalanceDataSource.AddMapping(CircleElementPointMarker.ToolTipTextProperty, y => y.Description); plotter.Children.RemoveAll(typeof(LineGraph)); plotter.Children.RemoveAll(typeof(ElementMarkerPointsGraph)); plotter.AddLineGraph(currBalanceDataSource, new Pen(Brushes.Blue, 2), new CircleElementPointMarker { Size = 10.0, Fill = Brushes.Blue, Brush = Brushes.Blue }, new PenDescription("Current balance")); plotter.Viewport.FitToView(); }