2010-12-06 62 views
2

我使用Silverlight Toolkit的標準Silverlight圖表在圖表上顯示了一些數據,但是所有數據都不會顯示在一個圖表上,並且似乎會出現大量的間距每一組柱子導致數據的右側列被「切斷」。Silverlight Column Series圖表寬度問題

有誰知道我可以如何減少這個間距和/或告訴圖形有一個固定的寬度,以便它適合所有列。

下面是一個圖像來直觀地展示問題。 alt text

LordCover編輯:我上,我想直接的方式來設置固定寬度爲每個的ColumnSeries原來的問題補充。我試過用

<Style x:Key="DataPointStyle1" TargetType="charting:ColumnDataPoint"> 
    <Setter Property="Width" Value="5px" /> 
</Style> 

,然後在的ColumnSeries標記:

<charting:ColumnSeries 
    IndependentValueBinding="{Binding Path=Key}" 
    DependentValueBinding="{Binding Path=Value}" 
    DataPointStyle="{StaticResource DataPointStyle1}" 
    Title="Sales Amount"/> 

,但它只是變得相對寬度以圖表的寬度和一系列-ES的#。

+0

包括圖表xaml和您正在應用的任何自定義樣式。 – AnthonyWJones 2010-12-06 16:31:22

+0

我不知道你是否還有興趣,但也許我們現在得到一個答案:) – 2011-02-08 11:47:24

回答

4

凱文

由於凱文最初提出這樣的問題,我只說一說第一:這是奇怪的。該列系列的表示與它應該具有的左側原點相偏離。正如我在許多月前的評論中所暗示的那樣,我需要更多的細節來嘗試辨別這個奇怪的原因。

對於LordCover

要回答LordCover,我不認爲是真正相關的補充。

答案真的取決於你的意圖是設置寬度。我會基於你只想要更薄的列(列之間的間隙更大)來回答。我選擇了這個基礎,因爲我想不出有任何其他的理由。

ColumnSeries中的代碼專門分配每個數據點的Width,從而將您可能在樣式中設置的任何值作爲首選。所以只需在數據點樣式中設置寬度不會起作用。另外,如果你有多個系列,那麼你將失去默認的調色板,你也必須自己做所有的工作。

你可以做的是創建一個派生的ColumnSeries。喜歡的東西: -

public class FixedWidthColumnSeries : ColumnSeries 
{ 
    #region public double ColumnWidth 
    public double ColumnWidth 
    { 
     get { return (double)GetValue(ColumnWidthProperty); } 
     set { SetValue(ColumnWidthProperty, value); } 
    } 


    public static readonly DependencyProperty ColumnWidthProperty = 
     DependencyProperty.Register(
      "ColumnWidth", 
      typeof(double), 
      typeof(FixedWidthColumnSeries), 
      new PropertyMetadata(5.0)); 

    #endregion public double ColumnWidth 

    protected override void UpdateDataPoint(DataPoint dataPoint) 
    { 
     base.UpdateDataPoint(dataPoint); 
     double originalWidth = dataPoint.Width; 
     double newWidth = ColumnWidth; 
     dataPoint.Width = newWidth; 
     Canvas.SetLeft(dataPoint, Canvas.GetLeft(dataPoint) + (originalWidth - newWidth)/2); 
    } 
} 

此類允許原ColumnSeries做所有繁重然後調整寬度和之後的數據點的左位置。