2017-08-30 24 views
1

私はwpfで棒グラフコントロールをsystem.windows.controls.datavisualization.toolkit dllを使用して作成しました。 Y軸の最小値と最大値を指定します。ここで棒グラフのY軸の最小、最大、およびグリッド線を指定

バーチャート `

<Grid > 
    <barChartToolkit:Chart Height="280" HorizontalAlignment="Stretch" Title="Resource Availability" Name="columnChart" Background="White" VerticalAlignment="Stretch" Width="360"> 
     <barChartToolkit:ColumnSeries DependentValuePath="Value" IndependentValuePath="Name" ItemsSource="{Binding}" Title="Resources" /> 
    </barChartToolkit:Chart> 
</Grid> 

` は今、私はリストを作成したことだし、私の棒グラフは、画像の下のようにプロットし、ここで、チャートのDataContextの

public partial class MainWindow : Window 
{ 
    public MainWindow() 
    { 
     InitializeComponent(); 
     showColumnChart(); 
    } 

    private void showColumnChart() 
    { 
     List<BarCHartData> valueList = new List<BarCHartData>(); 
     valueList.Add(new BarCHartData() { Name = "Developer", Value = 10 }); 
     valueList.Add(new BarCHartData() { Name = "Tester", Value = 20 }); 
     valueList.Add(new BarCHartData() { Name = "QA", Value = 30 }); 
     columnChart.DataContext = valueList; 
    } 

} 

public class BarCHartData 
{ 
    public string Name { get; set; } 

    public int Value { get; set; } 
} 

をバインドさ enter image description here

私は以下のコードで試しました

<Window x:Class="WpfToolkitChart.MainWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:barChartToolkit="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"> 

<Grid > 
    <barChartToolkit:Chart Height="280" HorizontalAlignment="Stretch" Title="Resource Availability" Name="columnChart" Background="White" VerticalAlignment="Stretch" Width="360"> 
     <barChartToolkit:ColumnSeries DependentValuePath="Value" IndependentValuePath="Name" ItemsSource="{Binding}" Title="Resources" /> 
     <barChartToolkit:Chart.Axes> 
      <barChartToolkit:LinearAxis Orientation="Y" Minimum="0" Maximum="100"/> 
     </barChartToolkit:Chart.Axes> 
    </barChartToolkit:Chart> 
</Grid> 

が、画像Iはグリッド線とY軸に最大値と最小値を設定する方法

enter image description here

以下のようにグラフのグリッド線を除去すること、このコード?

+0

あなたは二度同じ画像をリンクし、私はあなたが話しているかのグリッドラインを理解していません。 – grek40

答えて

0

あなたの中にShowGridLines="True"を設定するだけです。LinearAxis

enter image description here

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:WpfApp55" 
    xmlns:chartingToolkit="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit" 
    x:Class="WpfApp55.MainWindow" 
    mc:Ignorable="d" 
    Title="MainWindow" Height="350" Width="525"> 
<Window.Resources> 
    <x:Array x:Key="array1" Type="{x:Type local:BarChartData}"> 
     <local:BarChartData Name="Developer" Value="25" /> 
     <local:BarChartData Name="Tester" Value="50" /> 
     <local:BarChartData Name="QA" Value="75" /> 
    </x:Array> 
</Window.Resources> 

<Grid> 

    <chartingToolkit:Chart Title="Sample Chart"> 
     <chartingToolkit:Chart.Axes> 
      <chartingToolkit:LinearAxis Minimum="0" 
             Maximum="100" 
             Orientation="Y" 
             ShowGridLines="True" /> 
     </chartingToolkit:Chart.Axes> 
     <chartingToolkit:ColumnSeries DependentValuePath="Value" 
             IndependentValuePath="Name" 
             ItemsSource="{StaticResource array1}"/> 
    </chartingToolkit:Chart> 

</Grid> 

+0

ありがとう@ jstreet..itsうまく動作します –

0

あなたはディスプレイの値を制限したい場合は、代わりのDependentValuePath

public class RangeConverter : IValueConverter 
{ 
    public double Min { get; set; } 
    public double Max { get; set; } 
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 
    { 
     var d = System.Convert.ToDouble(value, culture); 
     return Math.Max(Min, Math.Min(Max, d)); 
    } 

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 
    { 
     throw new NotImplementedException(); 
    } 
} 

コンバータリソースコンバータとDependentValueBindingを使用することができます:あなたは

<local:RangeConverter x:Key="rangeConverter" Max="100" Min="0"/> 

使用

<DVC:ColumnSeries 
    DependentValueBinding="{Binding Value,Converter={StaticResource rangeConverter}}" 
    IndependentValuePath="Name" 
    ItemsSource="{Binding}" 
    Title="Resources"/> 
+0

は、Barchartの値の範囲を制限します。しかし、私はbarchartのY軸の静的範囲を設定する必要があります。 –

関連する問題