2012-12-15 75 views
0

我在写,因为我的wpf及其图形有问题。 基本上,我想创建一个柱形图。我的问题是我无法设置列的宽度。在互联网上,我只看到固定宽度的列的例子。WPF:图中的宽度列

我的XAML代码是这样的:

<Grid Height="871" Width="572"> 
     <chartingToolkit:Chart Height="337" HorizontalAlignment="Left" Margin="65,0,0,496" Name="columnChart" Title="Column Series Demo" VerticalAlignment="Bottom" Width="440"> 
      <chartingToolkit:Chart.Axes> 
       <chartingToolkit:LinearAxis Title="Wireless Power" Orientation="Y" Interval="100" /> 
       <chartingToolkit:LinearAxis Title="Time" Orientation="X" Interval="100" /> 
      </chartingToolkit:Chart.Axes> 
      <chartingToolkit:ColumnSeries Name="myGraph" IndependentValuePath="Key" ItemsSource="{Binding}" AnimationSequence="FirstTo"/>    
     </chartingToolkit:Chart> 
</Grid> 

后面的代码是:

private void showColumnChart(){ 

    List<KeyValuePair <int, int>> valueList = new List<KeyValuePair<int, int>>(); 
    valueList.Add(new KeyValuePair<int, int>(12, 55)); 
    valueList.Add(new KeyValuePair<int, int>(15, 60)); 
    columnChart.DataContext = valueList; 
} 

现在,我的目的是在白天代表我的无线的强度。但是有时候你没有连接,那么电源就是没有,或者有时候,例如从晚上7点到8点,信号强度等于-78db。我以前收集在一个数据库中,现在我想代表它们。所以我的目标是,例如,考虑24小时的时间间隔,将条放置在图上,其中x轴是无线功率的检测时间,而y轴是功率。

我希望我解释得很好。

+0

为什么你不能设置列的宽度?你在谈论哪些专栏? – stukselbax

+0

我正在使用WPF ToolKit,我没有发现宽度的特性。有什么? –

+0

我认为你应该仔细研究这个问题。 – stukselbax

回答

0

事实上,与你分享我的Wpf-toolkit/charting实验:我希望我从未在我的磁盘上安装过这个实验。
这本来是更快地去:

  1. 的画布。 (甚至是一个很好的旧电网)。
  2. 对象的一个​​或多个DataTemplates。
  3. 处理缩放的控制器对象(如果需要的话)。
  4. 然后在Canvas中绑定到ObservableCollection的ItemControl。

毕竟,一个柱形图高于风格的矩形的集合而已......

我的建议是:避免WPF工具包,它没有记录。例如,无法获得清晰的想法,例如如何处理颜色。在检查对象时,论坛上的一些教程/答案根本无法适用:规格更改很多次。
因此,无论图表的预设值是否适合您,并为此努力,但如果您想自由设计您的组件,那么您自己或通过选择记录/工作库更好。

如果你去另一个lib中,我也帮不了你更多:谷歌是你的朋友,
,如果你想自己做,我这样做很快让你开始:

snapshot of the bar-graph example

<Window x:Class="MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:l="clr-namespace:WpfApplication1" 
     Title="MainWindow" 
     Width="525" 
     Height="350" 
     Loaded="Window_Loaded"> 
    <Window.Resources> 
     <DataTemplate DataType="{x:Type l:Datata}"> 
      <Rectangle Width="10" 
         Height="{Binding SomeValue}" 
         VerticalAlignment="Bottom" 
         Margin="10,0" 
         Fill="Black" /> 
     </DataTemplate> 

    </Window.Resources> 
    <Grid> 
     <Grid.ColumnDefinitions> 
      <ColumnDefinition Width="10" /> 
      <ColumnDefinition /> 
     </Grid.ColumnDefinitions> 
     <Grid.RowDefinitions> 
      <RowDefinition /> 
      <RowDefinition Height="10" /> 
     </Grid.RowDefinitions> 
     <!-- Vertical Axis --> 
     <Path Grid.Row="0" 
       Grid.RowSpan="2" 
       Grid.Column="0" 
       Stretch="Fill" 
       Stroke="Black" 
       StrokeThickness="2"> 
      <Path.Data> 
       <LineGeometry StartPoint="0,0" EndPoint="0,1" /> 
      </Path.Data> 
     </Path> 
     <!-- Horizontal axis --> 
     <Path Grid.Row="1" 
       Grid.Column="0" 
       Grid.ColumnSpan="2" 
       Stretch="Fill" 
       Stroke="Black" 
       StrokeThickness="2"> 
      <Path.Data> 
       <LineGeometry StartPoint="0,0" EndPoint="1,0" /> 
      </Path.Data> 
     </Path> 

     <StackPanel Orientation="Horizontal" Margin="0,5" > 
      </StackPanel> 
     <ItemsControl Grid.Row="0" Grid.Column="1" ItemsSource="{Binding AllValues}" VerticalAlignment="Bottom"> 
      <ItemsControl.ItemsPanel> 
       <ItemsPanelTemplate> 
        <StackPanel Orientation="Horizontal"/> 
       </ItemsPanelTemplate> 
      </ItemsControl.ItemsPanel> 
     </ItemsControl> 
    </Grid> 
</Window> 
+0

所以,你的建议是什么? –

+0

我编辑了我的帖子 – GameAlchemist

+0

我感谢你的工作:-)但是,你知道任何其他库吗?我问你,因为我必须通过代码来完成此图,我认为以xaml方式完成这项工作对我来说很困难。 –