从DB数据填充WPF图表失败

时间:2014-08-05 04:52:45

标签: c# wpf charts

我想创建一个条形图,我正在按照教程

http://www.c-sharpcorner.com/uploadfile/mahesh/bar-chart-in-wpf/

但条形图无法填充数据库数据。 这是我的代码

  

chart.xaml

<Grid>
<Grid.Resources>
        <local:FreqChart x:Key="frequency" />
    </Grid.Resources>

        <DVC:Chart Name="fChart" Width="400" Height="250" Background="LightSteelBlue">
            <DVC:Chart.Series>
                <DVC:PieSeries Title="Frequency Chart" ItemsSource="{StaticResource frequency}"
                     IndependentValueBinding="{Binding Path=name}" DependentValueBinding="{Binding Path=occurence}">
                </DVC:PieSeries>
            </DVC:Chart.Series>
        </DVC:Chart>
    </Grid>

填充图表的C#集合

class category
{
    public string name;
    public int occurence;
}

class FreqChart : System.Collections.ObjectModel.Collection<category> 
{
    public FreqChart()
    {
        DataTable dt= DB.FrequencyRecordSet(); // this DataTable is populated from database
        foreach (DataRow row in dt.Rows)
        {
            Add(new category { name = row[0].ToString(), occurence = int.Parse(row[1].ToString()) });
        }
    }


}

0 个答案:

没有答案