作成日: 2021/03/02 最終更新日: 2021/03/02
文書種別
使用方法
詳細
FlexChartでは、X軸ラベルの重なりを防ぐため一部が自動的に非表示になり、すべての軸ラベルが表示されないことがあります。
このような場合にすべてのX軸ラベルを表示させるには、AxisのItemsSourceプロパティとBindingプロパティを手動で設定したのち、OverlappingLabelsプロパティを「Show」に設定して、重なり合っているラベルでも表示するように指定します。
flexChart.AxisX.ItemsSource = GetAxisLabels();
flexChart.AxisX.Binding = "Value,Text";
flexChart.AxisX.OverlappingLabels = OverlappingLabels.Show;
なお、AxisのStaggeredLinesプロパティを2以上に設定してラベルを複数行で表示し、重なりを防ぐことも可能です。
flexChart.AxisX.StaggeredLines = 2;
以下に、上述の設定を行ったサンプルプロジェクト全体のコードを記載します。
(MainWindow.xaml)
このような場合にすべてのX軸ラベルを表示させるには、AxisのItemsSourceプロパティとBindingプロパティを手動で設定したのち、OverlappingLabelsプロパティを「Show」に設定して、重なり合っているラベルでも表示するように指定します。
flexChart.AxisX.ItemsSource = GetAxisLabels();
flexChart.AxisX.Binding = "Value,Text";
flexChart.AxisX.OverlappingLabels = OverlappingLabels.Show;
なお、AxisのStaggeredLinesプロパティを2以上に設定してラベルを複数行で表示し、重なりを防ぐことも可能です。
flexChart.AxisX.StaggeredLines = 2;
以下に、上述の設定を行ったサンプルプロジェクト全体のコードを記載します。
(MainWindow.xaml)
<Window
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:Sample"
xmlns:c1="http://schemas.componentone.com/winfx/2006/xaml" x:Class="Sample.MainWindow"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<c1:C1FlexChart x:Name="flexChart" ItemsSource="{Binding}" BindingX="Index">
<c1:Series SeriesName="area" Binding="Value" ChartType="Bar"/>
</c1:C1FlexChart>
</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;
namespace Sample
{
/// <summary>
/// MainWindow.xaml の相互作用ロジック
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.DataContext = GetList();
// すべてのXラベルを表示
flexChart.AxisX.ItemsSource = GetList();
flexChart.AxisX.Binding = "Index";
flexChart.AxisX.OverlappingLabels = C1.Chart.OverlappingLabels.Show;
// ラベルを複数行で表示
flexChart.AxisX.StaggeredLines = 2;
}
private List- GetList()
{
List
- ItemList = new List
- ();
for (var i = 0; i < 34; i++)
{
Item x = new Item();
x.Index = (i+100).ToString();
x.Value = i*5;
ItemList.Add(x);
}
return ItemList;
}
private class Item
{
public string Index { get; set; }
public double Value { get; set; }
}
}
}
旧文書番号
86459