wpf图表列系列数据绑定问题
我正在尝试使用 wpf 工具包中的 ColumnSeries 构建图表,但数据绑定似乎遇到问题。这是 xaml:
<Grid>
<chartingToolkit:ColumnSeries Height="18" HorizontalAlignment="Left" Margin="188,169,0,0" Name="columnSeries1" VerticalAlignment="Top" Width="18" IndependentValueBinding="{Binding Path=Date}" DependentValueBinding="{Binding Path=Value}" />
</Grid>
在后面的代码中,我调用一个存储过程并将结果放入 DataTable
中,如下所示:
string connString = ConfigurationManager.ConnectionStrings["string"].ConnectionString;
using (SqlConnection cn = new SqlConnection(connString))
{
DataTable dt = new DataTable("T1");
cn.Open();
SqlCommand cmd = new SqlCommand("T1_sp", cn);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
columnSeries1.ItemsSource = dt.DefaultView;
cn.Close();
}
没有生成错误,但我也没有得到柱形图。如果我采用相同的命令并将其放入 DataGrid
中,它就可以正常工作。我需要做什么才能将其添加到我的柱形图中?
如果有帮助,数据表中返回的数据如下所示:
Date, type, Value
2009-10-09, abc, 12.23
2009-10-10, def, 13.35
日期应该是独立值绑定,值应该是从属值绑定。
I'm trying to build a chart using the ColumnSeries
from the wpf toolkit and I appear to be having trouble with the data binding. Here is the xaml:
<Grid>
<chartingToolkit:ColumnSeries Height="18" HorizontalAlignment="Left" Margin="188,169,0,0" Name="columnSeries1" VerticalAlignment="Top" Width="18" IndependentValueBinding="{Binding Path=Date}" DependentValueBinding="{Binding Path=Value}" />
</Grid>
In the code behind, I'm calling a stored procedure and putting the result in a DataTable
like this:
string connString = ConfigurationManager.ConnectionStrings["string"].ConnectionString;
using (SqlConnection cn = new SqlConnection(connString))
{
DataTable dt = new DataTable("T1");
cn.Open();
SqlCommand cmd = new SqlCommand("T1_sp", cn);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
columnSeries1.ItemsSource = dt.DefaultView;
cn.Close();
}
No error is being generated but I'm not getting a column chart either. If I take the same command and put it into a DataGrid
, it works fine. What do I need to do to get this into my column chart?
If it helps, the data comming back in the data tables looks like this:
Date, type, Value
2009-10-09, abc, 12.23
2009-10-10, def, 13.35
The date should be the independent value binding and the value should be the dependent value binding.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是我的工作代码,为了清晰起见,做了一些清理。也许这会有所帮助。
xaml
代码背后
希望有帮助!
Here is my working code, cleaned up a little for clarity. Maybe this will help.
xaml
code behind
Hope that helps!
我遇到了一个非常相似的问题,我有一个解决方案,它可能对你有用。
WPF 工具包图表和 IndependentValueBinding、IndependentValuePath
I'm having a very similiar problem, I have a bit of a solution, it would probably work for you.
WPF Toolkit Charting and IndependentValueBinding, IndependentValuePath