1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Visual Studio | WPF > グラフ > LiveCharts > 凡例を表示する

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

処理内容

  • 凡例を表示する

実装方法

参考: Basic Line Chart @ LiveCharts

  • XAML
    • lvc:CartesianChart に対して「LegendLocation」を指定する
  • code behind
    • LineSeriesなどに「Title」を追加する

code

MainWindow.xaml
<Window x:Class="_171124_t1600_legend.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_t1600_legend"
        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"/>
        </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_t1600_legend
{
    /// <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; }
        }       
    }
}

qiita.png

検索用キーワード

  • legend
1
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
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?