tags:

views:

494

answers:

3

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.

A: 

i have the same problem please help

Smitha
A: 

Here is my working code, cleaned up a little for clarity. Maybe this will help.

xaml

<charting:Chart Grid.Column="1" Grid.Row="1" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"  Background="Transparent" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
        <charting:Chart.Series>
            <charting:ColumnSeries x:Name="TrendChart" ItemsSource="{Binding Trend1}" IndependentValueBinding="{Binding Date}" DependentValueBinding="{Binding Spread}">
            </charting:ColumnSeries>
        </charting:Chart.Series>            
    </charting:Chart>

code behind

string connString = ConfigurationManager.ConnectionStrings["string"].ConnectionString;
                using (SqlConnection cn = new SqlConnection(connString))
                {
                    DataTable dt = new DataTable("Trend1");
                    cn.Open();
                    SqlCommand cmd = new SqlCommand("Trend1_sp", cn);                        cmd.CommandType = CommandType.StoredProcedure;
                    SqlDataAdapter da = new SqlDataAdapter(cmd);
                    da.Fill(dt);
                    TrendChart.ItemsSource = dt.DefaultView;
                    cn.Close();
                }

Hope that helps!

nelsonwebs
A: 

I'm having a very similiar problem, I have a bit of a solution, it would probably work for you.

http://stackoverflow.com/questions/2960740/wpf-toolkit-charting-and-independentvaluebinding-independentvaluepath

Joel Barsotti