private void addDataSourceBtn_Click(object sender, RoutedEventArgs e) { var line = plotter.AddLineGraph(CreateSineDataSource(rnd.NextDouble())); DataFollowChart followChart = new DataFollowChart(line); plotter.Children.Add(followChart); //plotter.AddLineGraph(CreateLineDataSource(rnd.NextDouble()), 2); }
void dataFollowChart_MarkerPositionChanged(object sender, EventArgs e) { DataFollowChart chart = (DataFollowChart)sender; ValueStore store; if (chart.FollowDataContext.Data == null) { store = new ValueStore("X", "Y"); chart.FollowDataContext.Data = store; } else { store = (ValueStore)chart.FollowDataContext.Data; } if (chart.ClosestPointIndex != -1) { var closestPoint = ((List <TPoint>)edsLog10.Data)[chart.ClosestPointIndex]; store["X"] = closestPoint.Y.ToString(); store["Y"] = closestPoint.X.ToShortDateString(); } }
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; }