1

我现在严重卡住了。

我有从数据库中读取每小时呼叫量的代码,但是当将它们映射到图表时,什么都没有显示......

我如何使用以下命令映射它:ls.ItemsSource = Enumerable.Range(0, counter).Select(k => new KeyValuePair<int, int>(callHour[k], callCounter[k])).ToArray();

这是我的所有代码:

XAML:

    <DVC:Chart Name="Chart"
               Background="#463F3F">                
        <DVC:Chart.PlotAreaStyle>
            <Style TargetType="Grid">
                <Setter Property="Background" Value="Transparent" />
            </Style>
        </DVC:Chart.PlotAreaStyle>
    </DVC:Chart>

C#:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Data;
using System.Windows.Controls.DataVisualization.Charting;

namespace WpfApplication1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
        AllAgentHourData();
    }

    private void AllAgentHourData()
    {
        string[] qId = new string[100];
        int[] callHour = new int[100];
        int[] callCounter = new int[100];
        int qCounter = 0;
        //int counter = 0;

        SqlConnection sqlConnection1 = new SqlConnection("Server=nl-reportserver;Database=RC_Dailer_WH;User Id=sa;Password=<password>");
        SqlCommand cmd = new SqlCommand();
        SqlDataReader reader;
        sqlConnection1.Open();
        //cmd.CommandText = "Select distinct queueid from RC_call_logs order by queueid";
        cmd.CommandText = "Select CONVERT(date, starttime, 120) AS callDate, queueid, datepart(hour,convert(datetime,starttime,111)) AS cHour, count(id) as numberOfCalls from RC_call_logs where convert(date,starttime,120) = convert(date,getdate(),120) and queueid = 17000 group by CONVERT(date, starttime, 120), datepart(hour,convert(datetime,starttime,111)), queueid order by callDate, queueid, cHour";
        cmd.CommandType = CommandType.Text;
        cmd.Connection = sqlConnection1;



        reader = cmd.ExecuteReader();
        if (reader.HasRows)
        {
            while (reader.Read())
            {
                callHour[qCounter] = reader.GetInt32(2);
                callCounter[qCounter] = reader.GetInt32(3);
                qCounter++;
            }
        }
        else
        {
            MessageBox.Show("No Error message");
        }
        reader.Close();
        sqlConnection1.Close();

        LineSeries ls = new LineSeries();

        ls.Title = "17000";
        ls.IndependentValueBinding = new Binding("Key");
        ls.DependentValueBinding = new Binding("Value");

        ls.ItemsSource = Enumerable.Range(0, qCounter).Select(i=> new KeyValuePair<int, int>(callHour[i], callCounter[i])).ToArray();

    }

}
}
4

1 回答 1

3

您需要将线系列添加到图表

Chart.Series.Add(ls);
于 2013-05-06T09:06:01.523 回答