Добрый день, хочу рисовать на полотне графика(TextLabel Lines) но нет идей как это можно сделать.
Код:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using OxyPlot;
using OxyPlot.Series;
using OxyPlot.Axes;
namespace WpfApplication14
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
Point currentPoint = new Point();
public MainWindow()
{
DataContext = new DataDraw();
InitializeComponent();
}
private void Canvas_MouseDown_1(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
if (e.ButtonState == MouseButtonState.Pressed)
currentPoint = e.GetPosition(this);
}
private void Canvas_MouseMove_1(object sender, System.Windows.Input.MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
Line line = new Line();
line.Stroke = SystemColors.WindowFrameBrush;
line.X1 = currentPoint.X;
line.Y1 = currentPoint.Y;
line.X2 = e.GetPosition(this).X;
line.Y2 = e.GetPosition(this).Y;
currentPoint = e.GetPosition(this);
paintSurface.Children.Add(line);
}
}
}
public class DataDraw
{
public PlotModel PlotModel { get; set; }
public PlotController PlotController { get; set; }
private LineSeries LS;
private LinearAxis XAxis;
private LinearAxis YAxis;
public DataDraw()
{
PlotController = new OxyPlot.PlotController();
XAxis = new LinearAxis()
{
Position= AxisPosition.Bottom
};
YAxis = new LinearAxis()
{
Position = AxisPosition.Left,
IsPanEnabled = false
};
PlotModel = new PlotModel();
LS = new LineSeries();
Random rnd = new Random();
for (int i=0;i<10;i++)
{
LS.Points.Add(new DataPoint(i,rnd.NextDouble()));
}
PlotModel.Series.Add(LS);
PlotModel.Axes.Add(XAxis);
PlotModel.Axes.Add(YAxis);
}
}
}
Код:
<Window x:Class="WpfApplication14.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:oxy="http://oxyplot.org/wpf"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Canvas Name="paintSurface" MouseDown="Canvas_MouseDown_1" MouseMove="Canvas_MouseMove_1" >
<oxy:Plot Width="300" Height="300" Model="{Binding PlotModel}" Controller="{Binding PlotController}">
</oxy:Plot>
<Line X1="10" Y1="10" X2="50" Y2="50" Stroke="Black"/>
<Canvas.Background>
<SolidColorBrush Color="White" Opacity="0"/>
</Canvas.Background>
</Canvas>
</Grid>
</Window>