2011-02-03 215 views
1
<Window x:Class="tradtest.chart" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:toolkit="http://schemas.microsoft.com/wpf/2008/toolkit" 
xmlns:charting="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit" 

Title="chart" Height="300" Width="500"> 
<Window.Resources> 
    <Style x:Key="SimpleLineSeriesStyle" TargetType="charting:LineDataPoint"> 
     <Setter Property="Width" Value="0"/> 
     <Setter Property="Height" Value="0"/> 
    </Style> 


</Window.Resources> 
<Grid> 
    <charting:Chart x:Name="chart1" > 
     <charting:LineSeries ItemsSource="{Binding}" 

       DependentValuePath="Value" 

       IndependentValuePath="Key" 

       Title="Pet Preference" IsSelectionEnabled="True" /> 
    </charting:Chart> 

</Grid> 

刻度線爲X軸

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
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.Shapes; 
using System.Windows.Controls.DataVisualization.Charting; 

namespace tradtest 
{ 
    /// <summary> 
    /// Interaction logic for chart.xaml 
    /// </summary> 
    public partial class chart : Window 
    { 
     void AddSeries(string title, KeyValuePair<string, decimal>[] data, SolidColorBrush linecolor) 
     { 
      LineSeries ls = new LineSeries(); 
      ls.DependentValuePath = "Value"; 
      ls.IndependentValuePath = "Key"; 
      ls.ItemsSource = data; 
      ls.Title = title; 
      Style dpstyle = ls.DataPointStyle; 
      //Style tmp1 = this.Resources["SimpleLineSeriesStyle"] as Style; 
      Style tmp1 = new Style(); 
      tmp1.Setters.Add(new Setter(LineDataPoint.BackgroundProperty, linecolor)); 
      tmp1.Setters.Add(new Setter(LineDataPoint.WidthProperty, 0.0)); 
      tmp1.Setters.Add(new Setter(LineDataPoint.HeightProperty, 0.0)); 
      //wi 
      //dpstyle = tmp1; 
      ls.DataPointStyle = tmp1; 
      //SetterBaseCollection sr = dpstyle.Setters; 
      //SetterBase sb = new Setter(Background, (object)Brushes.AliceBlue); 
      chart1.Series.Add(ls); 
     } 
     public chart(KeyValuePair<string, decimal>[] spreadseries, 
      KeyValuePair<string, decimal>[] meanspreadseries, 
      KeyValuePair<string, decimal>[] enterlongseries, 
      KeyValuePair<string, decimal>[] entershortseries, 
      KeyValuePair<string, decimal>[] exitlongseries, 
      KeyValuePair<string, decimal>[] exitshortseries) 
     { 
      InitializeComponent(); 
      chart1.Series.Clear(); 
      AddSeries("Current Spread", spreadseries, Brushes.MediumPurple); 
      AddSeries("Mean Spread", meanspreadseries, Brushes.Black); 
      AddSeries("Enter Long Spread", enterlongseries, Brushes.Red); 
      AddSeries("Enter Short Spread", entershortseries, Brushes.Red); 
      AddSeries("Exit Long Spread", exitlongseries, Brushes.Orange); 
      AddSeries("Exit Short Spread", exitshortseries, Brushes.Orange); 

     } 
    } 
} 

我已附加上述我的代碼。 我無法刪除X軸刻度線。有人可以請指教?

+0

我不能複製圖像,以下是圖表的URL:http://www.quantcode.com/uploads/img4d49673d432fb.png – paseena 2011-02-03 21:18:56

+0

將有上圖表屬性 - 我不沒有將它安裝在此機器上,因此我無法檢查,但Intellisense應該會顯示您可以設置的所有屬性。 – ChrisF 2011-02-03 21:21:29

回答

1

您可以隱藏整個X軸是這樣的:

<charting:LineSeries.IndependentAxis> 
    <charting:CategoryAxis Orientation="X" Visibility="Collapsed"/> 
</charting:LineSeries.IndependentAxis> 

它添加到您的charting:LineSeries元素或代碼:

series.IndependentAxis = new CategoryAxis { Orientation = AxisOrientation.X, Visibility = Visibility.Collapsed }; 
0

所有系列都共享同一個X軸的對不對?所以你可以添加一個通用的X軸(如果你使用字符串獨立值處理,建議的類別更好),並設置AxisLabelStyle以顯示內容模板的內容樣式。我使用這個解決方案,系列添加的運行時將使用您添加的現有X軸。

HTH