C# 使用SQL查询绘制图表

C# 使用SQL查询绘制图表,c#,sql,wpf,reporting-services,charts,C#,Sql,Wpf,Reporting Services,Charts,我试图在C WPF应用程序中创建一个折线图。 我到处寻找我问题的答案。我知道这很难,但是 我绝望了。SQL查询如下所示: 选择股票符号、股票日期、股票价格调整关闭 来自MoneyBMine.dbo.NYSE 在“AA”、“AIT”中的股票符号 股票发行日期介于“2000-01-03”和“2000-02-04”之间 或: 选择股票符号、股票日期、股票价格调整关闭 来自MoneyBMine.dbo.NYSE 其中,股票_符号='AA' 股票发行日期介于“2000-01-03”和“2000-02-04

我试图在C WPF应用程序中创建一个折线图。 我到处寻找我问题的答案。我知道这很难,但是 我绝望了。SQL查询如下所示:

选择股票符号、股票日期、股票价格调整关闭 来自MoneyBMine.dbo.NYSE 在“AA”、“AIT”中的股票符号 股票发行日期介于“2000-01-03”和“2000-02-04”之间 或:

选择股票符号、股票日期、股票价格调整关闭 来自MoneyBMine.dbo.NYSE 其中,股票_符号='AA' 股票发行日期介于“2000-01-03”和“2000-02-04”之间 我只是想让我的任何值显示在应用程序中的图表上。
我还尝试了ReportViewer,并在MicrosoftSQLServerReportBuilder中生成报告,但再次尝试将这些报告引入到我的C WPF应用程序中,但没有任何效果。因此,我要问的是一种在C WPF应用程序中,在某种图表/报表上可视化SQL数据的方法。

我使用的是OxyPlot,您可以得到它。。。它比WPF自己的解决方案更好、更容易使用,因为它们提供的图表dll没有文档

一旦有了它,您可以在代码中执行以下操作:

// Create plot
var plot_model = new PlotModel()  { Title = title};

// Create points
var points = from_a_method_linq_Sql_whatever();
var line_series = new LineSeries();

// Add plot to serie
foreach (var point in points)
    line_series.Points.Add(point);

// Add them to the plot
plot_model.Series.Add(line_series);
我将此绘图作为属性,然后简单地从XAML绑定到它,如下所示:

<oxy:Plot Model="{Binding OutputChart}" />
您还可以将点作为属性公开,并通过xaml上的绑定完成所有操作。你的选择

添加axis和legends很简单,只需快速查看他们的文档/论坛

编辑: 我在自己编写的一个应用程序中使用了类似的内容:

// Running on a collection of objects that have dates and levels, and other things
foreach (var obj in lvl_reps)
{
    points.Add(new ExercisePoint
    {
        DateTime = exercise.Date,
        Lvl = obj.Level,
        X = DateTimeAxis.ToDouble(exercise.Date.AddHours(-12)),
        Y = obj.Reps.Sum(),
        Exercise = exercise.Exercise
    });
}
不要让ExercisePoint吓到你,下面是它的实现:

/// <summary>
/// Extends the normal point used by OxyPlot to include the level and the date.
/// The Idea is to use them on the tool tip of the exercise
/// </summary>
class ExercisePoint : IDataPoint
{
    public double X { get; set; }
    public double Y { get; set; }
    public int Lvl { get; set; }
    public DateTime DateTime { get; set; }
    public string Exercise { get; set; }
}

例如,这就是如何将自定义字段绑定到点。

一旦获得C语言中的值,我想您可以通过手动将其绘制到WPF画布来绘制线图。我是否正确理解了您的问题?如果使用外部库对您来说没有问题,请查看我编辑了您的标题的链接。请看,如果共识是否定的,他们就不应该这样做。谢谢你的回复,我还没有在我的研究中使用Linq到SQL。你能帮我写代码吗?很多人不知道你想做什么,也不知道你的疑问是什么。您最初的问题是如何在图表上显示您的数据。这是我使用的Linq代码:var points=纽约证券交易所的n,其中n.stock\u symbol==AA&&n.stock\u symbol==AIT选择新{n.stock\u symbol,n.stock\u date,n.stock\u price\u adj\u close};好的,这将为您提供一个对象集合。问题是什么?我需要x轴上的n.股票日期和n.股票价格调整结束。不太确定我错过了什么。谢谢
/// <summary>
/// Extends the normal point used by OxyPlot to include the level and the date.
/// The Idea is to use them on the tool tip of the exercise
/// </summary>
class ExercisePoint : IDataPoint
{
    public double X { get; set; }
    public double Y { get; set; }
    public int Lvl { get; set; }
    public DateTime DateTime { get; set; }
    public string Exercise { get; set; }
}