C#Live Charts图表未从存储过程加载

时间:2019-02-20 10:21:32

标签: c# livecharts

我创建了一个存储过程,该存储过程在名称上添加了一些总计和组,并且我想在WPF应用程序的图表中显示此数据。我想使用实时图表对此数据​​进行可视化。

这是存储过程及其结果:

SELECT TOP 10 
[nWordNr] as W, 
[nBitNr] as B, 
sum([tmTotals]) as total,
convert(varchar, [nWordNr]) + '.' + CONVERT(varchar, [nBitNr]) as adres

FROM Messages_History
GROUP BY nWordNr, nBitNr
ORDER BY total desc

W   B   total   adres
-----------------------
2   3   3578775 2.3
3   3   3557975 3.3
5   4   2305229 5.4
5   3   2183050 5.3
5   12  2022401 5.12
5   14  1673295 5.14
48  12  1658862 48.12
4   3   1606454 4.3
48  13  1541729 48.13
5   9   1463256 5.9

我找到了一些示例代码, 这是xaml和后面的代码:

private void Top10_Loaded(object sender, RoutedEventArgs e)
    {
        using (SchiDataSet db = new SchiDataSet())
        {
            //Retrieve data from stored procedure
            var data = db.spMessages_GetTotalTimePerID;
            //Create columns chart
            ColumnSeries col = new ColumnSeries() { DataLabels = true, Values = new ChartValues<int>(), LabelPoint = point => point.Y.ToString() };
            Axis ax = new Axis() { Separator = new LiveCharts.Wpf.Separator() { Step = 1, IsEnabled = false } };
            ax.Labels = new List<string>();
            //Add data to your chart
            foreach (var x in data)
            {
                col.Values.Add(x.total.ToString());
                ax.Labels.Add(x.adres.ToString());
            }
            Top10.Series.Add(col);
            Top10.AxisX.Add(ax);
            Top10.AxisY.Add(new Axis
            {
                LabelFormatter = value => value.ToString(),
                Separator = new LiveCharts.Wpf.Separator()
            });
        }

    }

<lvc:CartesianChart x:Name="Top10" Grid.Row="1" Margin=" 8 0 8 8" Loaded="Top10_Loaded"> </lvc:CartesianChart>

现在,当我启动应用程序时,图表将无法加载,并且我不知道如何加载图表。

0 个答案:

没有答案