LoginSignup
2
2

More than 5 years have passed since last update.

Visual Studio | WPF > グラフ > LiveCharts > zooming and panning

Posted at
動作環境
Windows 8.1 Pro (64bit)
Microsoft Visual Studio 2017 Community
Sublime Text 2

処理内容

下記の機能を使う。

  • zooming
    • 拡大、縮小
  • panning
    • 表示位置をずらす

参考

code

上記の参考リンクではcode behindで設定している。
下記ではXAMLでの設定。

Zoom="Xy"を追加する。
他に"X", "Y", "None"があるようだ。

MainWindow.xaml.cs
<Window x:Class="_171124_t1650_zooming.MainWindow"
        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:_171124_t1650_zooming"
        xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <StackPanel>
            <lvc:CartesianChart Series="{Binding seriesCollection}" Height="250"
                                LegendLocation="Right"
                                Zoom="Xy"/>
        </StackPanel>        
    </Grid>
</Window>
MainWindow.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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 LiveCharts;
using LiveCharts.Wpf;

namespace _171124_t1650_zooming
{
    /// <summary>
    /// MainWindow.xaml の相互作用ロジック
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            graph_init();
        }

        private void graph_init()
        {
            gd = new GraphData();

            var sc = new SeriesCollection {
                new LineSeries
                {
                    Title = "pi",
                    Values = new ChartValues<double> { 3, 1, 4, 1, 5, 9, 2 }
                },
                new LineSeries
                {
                    Title = "napier",
                    Values = new ChartValues<double> { 2, 7, 1, 8, 2, 8, 1, 8 }
                }
            };

            gd.seriesCollection = sc;
            this.DataContext = gd;
        }

        GraphData gd;
        public class GraphData
        {
            public SeriesCollection seriesCollection { get; set; }
        }
    }
}

使い方

Zooming and panning

use the mouse wheel to zoom in/out, click, hold and drag for panning.

  • マウス真ん中のwheel上下: 拡大、縮小
  • マウスでドラッグ: 表示位置をずらす

qiita.png

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2