0

C# WPF アプリケーション内で折れ線グラフを作成しようとしています。私は自分の質問に対する答えを広く探しました。私はこれがロングショットであることを知っていますが、私は絶望的です. SQL クエリは次のとおりです。

SELECT stock_symbol, stock_date, stock_price_adj_close 
FROM MoneyBMine.dbo.NYSE 
WHERE stock_symbol IN ('AA', 'AIT') 
AND stock_date BETWEEN '2000-01-03' AND '2000-02-04'

また:

SELECT stock_symbol, stock_date, stock_price_adj_close 
FROM MoneyBMine.dbo.NYSE 
WHERE stock_symbol = 'AA' 
AND stock_date BETWEEN '2000-01-03' AND '2000-02-04'

アプリケーション内のグラフに表示される値を取得しようとしています。また、ReportViewer を試し、「Microsoft SQL Server Report Builder」でレポートを作成しましたが、これらのレポートを C# WPF アプリケーションに取り込もうとしても何も機能しません。だから私が求めているのは、C# WPF アプリケーションである種のチャート/レポートで SQL データを視覚化する方法です。

4

1 に答える 1

0

I'm using OxyPlot, you can get it here ... It's much nicer and easier to work with than WPF own solution (the charting dll they supply has NO documentation).

once you have it, in your code you can do:

// 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);

I would have this plot as a property, and then simply bind to it from the XAML like this:

<oxy:Plot Model="{Binding OutputChart}" />

(make sure you have this on top of your xaml:

 xmlns:oxy="clr-namespace:OxyPlot.Wpf;assembly=OxyPlot.Wpf"

You can also have your points exposed as a property and do all from the binding on the xaml. Your choice.

Adding axis and legends is simple as, just have a quick look at their documentation / forum.

Edit:
I've used something like this in an application I wrote:

// 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
    });
}

Don't let ExercisePoint scare you, here's the implementation of it:

/// <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; }
}

So this is how you can bind custom fields to points for example.

于 2013-10-23T12:42:12.100 に答える