23

プログラムの GUI

Oxyplot は、6 つのユーザー入力テキスト ボックスから得られる 13 点をグラフ化します。テキスト ボックスの値は、MainWindow.xaml.cs クラスのパブリック変数に保持されます。ユーザーがテキスト ボックスで Enter キーを押すと、変数が更新されます。更新ボタンでグラフを更新するにはどうすればよいですか。

private void RefreshButton_Click(object sender, RoutedEventArgs e)
        {
            //Refresh The Graph
        }

これは、

PlotModel.RefreshPlot() 

メソッドですが、Oxyplot のドキュメントが不十分なため、実装方法がわかりません。

4

7 に答える 7

39

NuGet 経由で OxyPlot の新しいバージョンに更新しました。私は OxyPlot.Wpf v20014.1.277.1 を使用していますが、RefreshPlotInvalidatePlot(bool updateData)PlotModel代わりに呼び出す必要があると思います (これは利用できなくなりました)。サンプル コードでこれをテストしたところ、期待どおりに動作しました。

プロット更新してデータ コレクションを更新する場合trueは、呼び出しに渡す必要があります。

PlotModel.InvalidatePlot(true)
于 2014-04-10T13:50:55.120 に答える
5

現在の OxyPlot.Wpf (1.0.0-unstable1983) には、次の 2 つのオプションがあります。

  1. Series.ItemsSource更新が必要な場合は、プロパティを XAML からビューモデルのコレクションにバインドし、コレクション全体を交換します。これにより、より大きなデータ セットを使用した同時非同期更新も可能になります。
  2. Plot.InvalidateFlagtype のプロパティをビューモデルにバインドしint、更新が必要なときにインクリメントします。ただし、このアプローチはテストしていません。

次のコードは、両方のオプションを示しています (いずれかを選択してください)。XAML:

<oxy:Plot InvalidateFlag="{Binding InvalidateFlag}">
    <oxy:Plot.Series>
        <oxy:LineSeries ItemsSource="{Binding DataSeries}" />
      </oxy:Plot.Series>
 </oxy:Plot>

ViewModel の更新:

private async Task UpdateAsync()
{
    // TODO do some heavy computation here
    List<DataPoint> data = await ...

    // option 1: Trigger INotifyPropertyChanged on the ItemsSource.
    //           Concurrent access is ok here.
    this.DataSeries = data; // switch data sets

    // option 2: Update the data in place and trigger via flag
    //           Only one update at a time.
    this.DataSeries.Clear();
    data.ForEach(this.DataSeries.Add);
    this.InvalidateFlag++;
}
于 2016-02-24T08:06:07.283 に答える
4

同じ問題で同じ質問をした後、唯一の有効な解決策 (少なくとも私の観点では) は次のようになります。

PlotView.InvalidatePlot(true)

そうすることで、1つまたは複数を更新した後SeriesPlotView.

リフレッシュレートは、シリーズが更新される頻度またはレートによって異なります。

コード スニペットを次に示します (Xamarin Android でも動作するはずです)。

PlotView resultsChart = FindViewById<PlotView>(Resource.Id.resultsChart);
PlotModel plotModel = new PlotModel
{
    // set here main properties such as the legend, the title, etc. example :
    Title = "My Awesome Real-Time Updated Chart",
    TitleHorizontalAlignment = TitleHorizontalAlignment.CenteredWithinPlotArea,
    LegendTitle = "I am a Legend",
    LegendOrientation = LegendOrientation.Horizontal,
    LegendPlacement = LegendPlacement.Inside,
    LegendPosition = LegendPosition.TopRight
    // there are many other properties you can set here
}

// now let's define X and Y axis for the plot model

LinearAxis xAxis = new LinearAxis();
xAxis.Position = AxisPosition.Bottom;
xAxis.Title = "Time (hours)";

LinearAxis yAxis = new LinearAxis();
yAxis.Position = AxisPosition.Left;
yAxis.Title = "Values";

plotModel.Axes.Add(xAxis);
plotModel.Axes.Add(yAxis);

// Finally let's define a LineSerie

LineSeries lineSerie = new LineSeries
 {
    StrokeThickness = 2,
    CanTrackerInterpolatePoints = false,
    Title =  "Value",
    Smooth = false
  };
plotModel.Series.Add(lineSerie);
resultsChart.Model = plotModel;

DataPointsに追加し、それに応じLineSerieて自動的に更新する必要があるときはいつでも、次のようにしてください。PlotView

resultsChart.InvalidatePlot(true);

そうすることで、自動的に更新されますPlotView

ちなみに、 はPlotView、タッチ、ピンチによるズーム、またはあらゆる種類の UI 関連イベントなどのイベントが発生したときにも更新されます。

お役に立てれば幸いです。私はこれに非常に長い間悩まされていました。

于 2014-11-10T16:08:28.847 に答える
3

プロットを更新する方法が 3 つあります ( OxyPlot のドキュメントから)。

  • コントロールのModelプロパティを変更するPlotView
  • コントロールInvalidateを呼び出すPlotView
  • に電話InvalidateするPlotModel
于 2016-10-25T10:02:39.987 に答える