2016-07-27 7 views
0

私は現在、縦棒グラフを表示する必要がある単純なC#WPFプログラムで作業しています。しかし、System.Windows.Controls.DataVisualization.Charting名前空間の基本的な縦棒グラフは、グラデーションの列の塗りつぶしの色が付いているので、プログラムではそのようにしたくありません。WPF Chartsがグラデーションの塗りつぶしを取り除きます

xamlやC#コードで列の塗りつぶしブラシをSolidBrushに設定する方法はありますか? ColumnSeriesは、プログラムの実行中にプログラムで追加されるため、xamlにはアクセスできません。私はまだWPFとXAMLにはかなり新しいですので、私は本当に答え

ここに私のコードは、それはかなりかかわらず基本だし、今「ゴマだ、見て本当に多くはありませんを探し始めるためにどこか分からない:

をここ WPF Column Chart Styling: Remove the gradient effect, set the color of the hash marks on y axis (the minor grid lines):私はこの記事を見つけた

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.Controls.DataVisualization.Charting; 
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 WpfApplication1 
{ 
    public partial class MainWindow : Window 
    { 
     public MainWindow() 
     { 
      InitializeComponent(); 
      ColumnSeries lC = new ColumnSeries(); 
      List<KeyValuePair<string, int>> valueList1 = new List<KeyValuePair<string, int>>(); 
      valueList1.Add(new KeyValuePair<string, int>("Developer", 60)); 
      valueList1.Add(new KeyValuePair<string, int>("Misc", 20)); 
      valueList1.Add(new KeyValuePair<string, int>("Tester", 50)); 
      valueList1.Add(new KeyValuePair<string, int>("QA", 30)); 
      valueList1.Add(new KeyValuePair<string, int>("Project Manager", 40)); 

      lC.DependentValuePath = "Value"; 
      lC.IndependentValuePath = "Key"; 
      lC.ItemsSource = valueList1; 

      chart.Series.Add(lC); 
     } 
    } 
} 

MainWindow.xaml

<Window x:Class="WpfApplication1.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:chartingToolkit="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit" 
     Title="MainWindow" Height="350" Width="525"> 
    <Grid x:Name="grid"> 
     <chartingToolkit:Chart x:Name="chart"> 

     </chartingToolkit:Chart> 
    </Grid> 
</Window> 

。ポスターの最初の問題は私とほとんど同じです。最初の答えはコラムを埋めるために境界線のサイズを増やすように指示しますが、私のプログラムではまだ列の境界線が必要なので、これは欲しいものではなく、それが唯一の答えです。私は本当にあなたの助けに感謝します。ありがとうございました!

答えて

0

外観を変更するには、ColumnSeries.DataPointStyleでテンプレートを変更します。コードの背後からこれを行うには非常に不自然に感じるので、コードを変更して XAMLのスタイルを定義できるようにしました。

<Window x:Class="WpfApplication1.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:chartingToolkit="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit" 
     xmlns:local="clr-namespace:WpfApplication1" 
     Title="MainWindow" Height="350" Width="525"> 
    <Window.DataContext> 
     <local:MainWindowViewModel /> 
    </Window.DataContext> 
    <Grid x:Name="grid"> 
     <Grid.Resources> 
      <!--Set ColumnColor--> 
      <Brush x:Key="MyColumnColor">Red</Brush> 
      <!--Style override--> 
      <Style x:Key="MyColumnDataPointStyle" 
        TargetType="{x:Type chartingToolkit:ColumnDataPoint}"> 
       <Setter Property="Background" 
        Value="{StaticResource MyColumnColor}" /> 
       <Setter Property="BorderBrush" 
        Value="Black" /> 
       <Setter Property="BorderThickness" 
        Value="1" /> 
       <Setter Property="IsTabStop" 
        Value="False" /> 
       <Setter Property="Template"> 
        <Setter.Value> 
         <ControlTemplate TargetType="{x:Type chartingToolkit:ColumnDataPoint}"> 
          <Border x:Name="Root" 
            BorderBrush="{TemplateBinding BorderBrush}" 
            BorderThickness="{TemplateBinding BorderThickness}"> 
           <Border.ToolTip> 
            <ContentControl Content="{TemplateBinding FormattedDependentValue}" /> 
           </Border.ToolTip> 
           <Grid Background="{TemplateBinding Background}"> 
            <!--Change Border appearance--> 
            <Border BorderBrush="#CCFFFFFF" 
             BorderThickness="1"> 
             <Border BorderBrush="#77FFFFFF" 
             BorderThickness="1" /> 
            </Border> 
           </Grid> 
          </Border> 
         </ControlTemplate> 
        </Setter.Value> 
       </Setter> 
      </Style> 
     </Grid.Resources> 
     <chartingToolkit:Chart> 
      <chartingToolkit:ColumnSeries ItemsSource="{Binding ValueList}" 
              DependentValuePath = "Value" 
              IndependentValuePath = "Key" 
              DataPointStyle="{StaticResource MyColumnDataPointStyle}"> 
      </chartingToolkit:ColumnSeries> 
     </chartingToolkit:Chart> 
    </Grid> 
</Window> 

MainWindow.xaml.cs

using System.Windows; 
using System.Collections.Generic; 
using System.Windows.Controls.DataVisualization.Charting; 

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

    public class MainWindowViewModel 
    { 
     private List<KeyValuePair<string, int>> valueList = new List<KeyValuePair<string, int>>() 
     { 
      (new KeyValuePair<string, int>("Developer", 60)), 
      (new KeyValuePair<string, int>("Misc", 20)), 
      (new KeyValuePair<string, int>("Tester", 50)), 
      (new KeyValuePair<string, int>("QA", 30)), 
      (new KeyValuePair<string, int>("Project Manager", 40)) 
     }; 

     public List<KeyValuePair<string, int>> ValueList 
     { 
      get { return valueList; } 
     } 
    } 
} 
0

WPFコントロールをスタイルする方法を学習するには、最も簡単な方法はExpression Blendを使用することです。 Look here for an example how to styleチャートコントロール

+0

リンクのおかげで、私がまさに必要でした。年齢のためのチャートスタイリングの良い例を探していましたが、それほど多くは見つかりませんでした... – zockDoc

関連する問題