C# で WPF アプリケーションを作成しています。このアプリケーションは、MVVM を使用して設計されています。
現在、いくつかのチェックボックスを備えた親ウィンドウがあります。ユーザーは、必要なボックスにチェックを入れてから、「プロット」をクリックできますButton
。「プロット」をクリックすると、新しい子ウィンドウが表示され、単一のグラフにデータが表示されます。
したがって、チェック ボックスを 1 つだけオンにして [プロット] をクリックすると、1 本の線が表示されたグラフが表示されます。2 つのチェック ボックスをオンにして [プロット] をクリックすると、同じ 1 つのグラフが表示されますが、2 本の線が表示されます。
私の現在の実装:
現在、私はと呼ばれる「ビュー」クラスを持っていますGraphWindowView
。ビューは明らかに、どのデータを表示するかを知る必要があります。そのために、私は依存関係プロパティを持っておりGraphWindowView.Dates
、どの究極が(y 軸) 対(x 軸)GraphWindowView.Data
のグラフを生成します。Data
Dates
質問:のこの現在の実装は明らかに 1 セットのデータ (対)GraphWindowView
をグラフ化できるように制限されています。これを (かなり) 拡張可能にして、チェック ボックスがどれだけチェックされているかに応じて、任意の数のプロットを利用できるようにしたいと考えています。どうすればこれを行うことができますか?依存関係プロパティの使用を再考する必要があると思います...Data
Dates
>>> 更新
そこでGraphLine
、グラフ上の線を表すクラスを作成しました。「グラフ」は実際にはクラスのChartPlotter
要素です。また、オブジェクトにGraphWindowPresenter.xaml
a を指定しDataType
ましたが、それは私が理解しているすべてです。GraphLine
これに対する次のステップは何ですか?実際にデータをグラフに追加するにはどうすればよいですか? GraphLine
そして、要素を設定するためにどのように/どこでインスタンスを作成しますChartPlotter
か? 申し訳ありませんが、かなりの数のチュートリアルを読んだ後でも、これについてはかなり迷っています。これまでご協力いただきありがとうございました。本当に感謝しています。
GraphWindowView.xaml
<Window x:Class="BMSVM_Simulator.View.GraphWindowView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ViewModel="clr-namespace:BMSVM_Simulator.ViewModel"
xmlns:d3="http://research.microsoft.com/DynamicDataDisplay/1.0"
x:Name="ThisGraphWindowInstance"
Title="Plot" Height="500" Width="750"
Icon="../res/qualcomm_q_icon.ico.ico"
MinWidth="400" MinHeight="300">
<Window.DataContext>
<ViewModel:GraphWindowPresenter/>
</Window.DataContext>
<d3:ChartPlotter Name="plotter" Margin="10,10,20,10">
<d3:ChartPlotter.HorizontalAxis>
<d3:HorizontalIntegerAxis Name="dateAxis"/>
</d3:ChartPlotter.HorizontalAxis>
<d3:ChartPlotter.VerticalAxis>
<d3:VerticalIntegerAxis Name="countAxis"/>
</d3:ChartPlotter.VerticalAxis>
<d3:Header FontFamily="Arial" Content="{Binding ElementName=ThisGraphWindowInstance, Path=title}"/>
<d3:VerticalAxisTitle FontFamily="Arial" Content="{Binding ElementName=ThisGraphWindowInstance, Path=yAxis}"/>
<d3:HorizontalAxisTitle FontFamily="Arial" Content="{Binding ElementName=ThisGraphWindowInstance, Path=xAxis}"/>
</d3:ChartPlotter>
<Window.Resources>
<DataTemplate DataType="{x:Type ViewModel:GraphLine}">
<!--WHAT GOES HERE-->
</DataTemplate>
</Window.Resources>
</Window>
GraphLine.cs
namespace BMSVM_Simulator.ViewModel
{
class GraphLine
{
public string xAxis { get; private set; }
public string yAxis { get; private set; }
public string title { get; private set; }
public string legend { get; private set; }
public EnumerableDataSource<int> data { get; private set; }
public EnumerableDataSource<int> dates { get; private set; }
}
}