<Window x:Class="Stocker.Win.WinStockCanvas" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:Stocker.Win" xmlns:oxy="http://oxyplot.org/wpf" mc:Ignorable="d" Title="WinStockCanvas" Height="450" Width="800"> <Grid x:Name="canvas_grid" Grid.Row="1" SizeChanged="canvas_grid_SizeChanged" Width="auto" Height="auto"> <Border HorizontalAlignment="Center" VerticalAlignment="Center" BorderBrush="Gray" BorderThickness="0" Background="#1e1e1e" Margin="0"> <oxy:PlotView x:Name="plot" Width="auto" Height="auto" Model="{Binding PModel}" /> </Border> </Grid> </Window>
public PlotModel MyModel { get; private set; }
draw_blank();
public void draw_blank() { MyModel = new PlotModel { Title = "绘图演示" }; MyModel.Background = OxyColor.FromRgb(0x1E, 0x1E, 0x1E);// visual studio 黑色 MyModel.TextColor = OxyColors.White; MyModel.PlotAreaBorderColor = OxyColors.Gray; MyModel.Axes.Add(new LinearAxis { Title = "Y轴标题", Position = AxisPosition.Left, MaximumPadding = 0.3, MinimumPadding = 0.3, AxislineColor = OxyColors.White, // 轴线 样式和颜色 MajorGridlineStyle = LineStyle.LongDashDot, MajorGridlineColor = OxyColors.Gray,
// 刻度颜色 TicklineColor = OxyColors.Gray, }); MyModel.Axes.Add(new LinearAxis { Title = "X轴标题", Position = AxisPosition.Bottom, MajorGridlineStyle = LineStyle.LongDashDotDot, MajorGridlineColor = OxyColors.Gray, TicklineColor = OxyColors.Gray, }); }
private void draw_demo() { //MyModel = new PlotModel { Title = "绘图演示" }; var ls = new LineSeries { Title = "叠加后的正弦波", Color = OxyColor.FromRgb(0xFF, 0xD7, 0x00), }; int n = 25; for (double x = -10; x < 10; x += 0.0001) { double y = 0; for (int i = 0; i < n; i++) { int j = i * 2 + 1; y += Math.Sin(j * x) / j; } ls.Points.Add(new DataPoint(x, y)); }
MyModel.Series.Add(ls); plot.InvalidatePlot(); }
private void btn_clear_Click(object sender, RoutedEventArgs e) { MyModel.Series.Clear(); plot.InvalidatePlot(); }
|