2013-02-28 153 views
2

我想知道如何更改我的d3 chartplotter的日期時間軸的顏色。WPF C#DynamicDataDisplay - 更改DateTimeAxis顏色

enter image description here

,我想改變顏色爲褐色,兩杆之間的白色背景顏色。

如果我這樣做:

它只是改變了上述第一條褐色的東西。

enter image description here

是否有可能改變這兩個欄的顏色?

回答

1

奇怪的是,我碰巧試圖做同樣的事情。事實證明,這些顏色是​​(我注意到下面的評論中的行)中的硬編碼。如果您使用編譯的DLL,那麼無法更改這些值。就個人而言,D3非常不成熟,所以我保留自己的版本並進行更改以根據需要進行擴展(例如在這種情況下!)。

public override UIElement[] CreateLabels(ITicksInfo<DateTime> ticksInfo) 
{ 
    object info = ticksInfo.Info; 
    var ticks = ticksInfo.Ticks; 
    UIElement[] res = new UIElement[ticks.Length - 1]; 
    int labelsNum = 3; 

    if (info is DifferenceIn) 
    { 
     DifferenceIn diff = (DifferenceIn)info; 
     DateFormat = GetDateFormat(diff); 
    } 
    else if (info is MayorLabelsInfo) 
    { 
     MayorLabelsInfo mInfo = (MayorLabelsInfo)info; 
     DifferenceIn diff = (DifferenceIn)mInfo.Info; 
     DateFormat = GetDateFormat(diff); 
     labelsNum = mInfo.MayorLabelsCount + 1; 

     //DebugVerify.Is(labelsNum < 100); 
    } 

    DebugVerify.Is(ticks.Length < 10); 

    LabelTickInfo<DateTime> tickInfo = new LabelTickInfo<DateTime>(); 
    for (int i = 0; i < ticks.Length - 1; i++) 
    { 
     tickInfo.Info = info; 
     tickInfo.Tick = ticks[i]; 

     string tickText = GetString(tickInfo); 

     Grid grid = new Grid 
     { 
      Background = Brushes.Beige // **** HARD CODED HERE 
     }; 
     Rectangle rect = new Rectangle 
     { 
      Stroke = Brushes.Peru,  // **** AND HERE 
      StrokeThickness = 2 
     }; 
     Grid.SetColumn(rect, 0); 
     Grid.SetColumnSpan(rect, labelsNum); 

     for (int j = 0; j < labelsNum; j++) 
     { 
      grid.ColumnDefinitions.Add(new ColumnDefinition()); 
     } 

     grid.Children.Add(rect); 

     for (int j = 0; j < labelsNum; j++) 
     { 
      var tb = new TextBlock 
      { 
       Text = tickText, 
       HorizontalAlignment = HorizontalAlignment.Center, 
       Margin = new Thickness(0, 3, 0, 3) 
      }; 
      Grid.SetColumn(tb, j); 
      grid.Children.Add(tb); 
     } 

     ApplyCustomView(tickInfo, grid); 

     res[i] = grid; 
    } 

    return res; 
}