Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > .NET Frameworks (точка нет фреймворки) > WPF, UWP, WinRT, XAML
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 25.04.2015, 20:05   #1
CWD
Пользователь
 
Регистрация: 10.11.2009
Сообщений: 50
По умолчанию OxyPlot canvas

Добрый день, хочу рисовать на полотне графика(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>
CWD вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц

Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск


Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
canvas в FF Fenex JavaScript, Ajax 3 06.12.2014 18:40
Canvas Auron Общие вопросы Delphi 8 13.12.2010 23:14
Canvas jaxik Помощь студентам 0 26.11.2010 18:13
3D canvas konikovskit Мультимедиа в Delphi 1 06.09.2010 22:02
Canvas guffer Обсуждение статей 1 21.08.2009 10:19