如何更新图形 oxyplot 更改数据时

Oxyplot 显示 13 来自的积分 6 用户输入文本字段。 文本字段中的值存储在打开类变量中。 MainWindow.xaml.cs. 当用户按下键时更新变量 enter 在文本字段中。 好像我这样做,以便更新按钮已更新图形。


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


我认为这将是如此


PlotModel.RefreshPlot//


方法,但我不确定如何因为文档错误而实现它 Oxyplot.
已邀请:

龙天

赞同来自:

我刚刚更新到新版本 OxyPlot 穿过 NuGet. 我用 OxyPlot.Wpf v20014.1.277.1, 我认为现在你需要打电话
InvalidatePlot/bool updateData/


PlotModel

反而 RefreshPlot /哪个不再可用/. 我在我的示例代码中检查了它,他按预期工作。

如果要更新计划



更新数据集合,您需要调用呼叫
true

:


PlotModel.InvalidatePlot/true/

喜特乐

赞同来自:


x:Name

到 OxyPlot 复制B. XAML:


<oxy:plot x:name="Plot1"></oxy:plot>


并在单击“处理程序”按钮时,更新此操作:


private void RefreshButton_Click/object sender, RoutedEventArgs e/
{
Plot1.RefreshPlot/true/;
}

卫东

赞同来自:

我发现的最干净的方式获得自动更新 "sort of", - 这是一个反应 CollectionChanged 在收藏中 LineSeries' ItemsSource.

在 ViewModel 年:


ObservableCollection<datapoint> Data { get; set; } 
= new ObservableCollection<datapoint>//;

public PlotModel PlotModel
{
get { return _plot_model; }
set
{
_plot_model = value;
RaisePropertyChanged/// =&gt; PlotModel/;
}
}
PlotModel _plot_model;

// Inside constructor:
Data.CollectionChanged += /a, b/ =&gt; PlotModel.InvalidatePlot/true/;


</datapoint></datapoint>

裸奔

赞同来自:

在我有同样问题的同一问题之后,似乎是唯一的工作解决方案 /至少在我的角度来看/ 在以下情况下 :


PlotView.InvalidatePlot/true/


在更新一个或多个之后完成此操作
Series

更新您的
PlotView

.

更新频率取决于您的系列在速度何时更新的频率。/S./.

这是代码的片段 /在 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.

我希望我能提供帮助。 我很长一段时间就有这个问题。
</plotview>

龙天

赞同来自:

在当前 OxyPlot.Wpf /1.0.0-unstable1983/ 你有两个选择:

领带物业
Series.ItemsSource

的 XAML 收集你的收藏 viewmodel 在需要更新时共享整个集合。 它还允许具有大数据集的同步异步更新。

领带物业
Plot.InvalidateFlag

类型
int

对你来说 viewmodel 每次需要更新时都会增加它。 但是,我没有检查这种方法。

以下代码说明了两个选项。 /选一个/. XAML:


<oxy:plot invalidateflag="{Binding InvalidateFlag}">
<oxy:plot.series>
<oxy:lineseries itemssource="{Binding DataSeries}"></oxy:lineseries>
</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++;
}


</datapoint>

冰洋

赞同来自:

有三个替代方案如何更新剧情 /的
http://docs.oxyplot.org/en/lat ... .html
/:

改变财产
Model

控制元素
PlotView


称呼
Invalidate

在控制面板上
PlotView


称呼
Invalidate

用电话
PlotModel

君笑尘

赞同来自:

两年后......这个决定为我工作,因为我没有模型 oxyplot, 我缺少上面的一些名字特征。

对于代码

:


public partial class LineChart : UserControl
{
public LineChart//
{
InitializeComponent//;

DataContext = this;
myChart.Title = "hier könnte Ihr Text stehen!";

this.Points = new List<datapoint>//;
randomPoints//;
}


public IList<datapoint> Points { get; private set; }

public void randomPoints//
{
Random rd = new Random//;
String myText = "";

int anz = rd.Next/30, 60/;

for /int i = 0; i &lt; anz; i++/
myText += i + "," + rd.Next/0, 99/ + ";";

myText = myText.Substring/0, myText.Length - 1/;
String[] splitText = myText.Split/';'/;

for /int i = 0; i &lt; splitText.Length; i++/
{
String[] tmp = splitText[i].Split/','/;
Points.Add/new DataPoint/Double.Parse/tmp[0].Trim///, Double.Parse/tmp[1].Trim/////;
}

while /Points.Count &gt; anz/
Points.RemoveAt/0/;

myChart.InvalidatePlot/true/;
}
}


更新数据

, 不要改变所有 IList, 并添加一些新的新 DataPoints 并删除旧位置 0.

XAML

:


<usercontrol d:designheight="300" d:designwidth="300" mc:ignorable="d" x:class="UxHMI.LineChart" xmlns="[url=http://schemas.microsoft.com/winfx/2006/xaml/presentation"]http://schemas.microsoft.com/w ... ot%3B[/url] xmlns:d="[url=http://schemas.microsoft.com/expression/blend/2008"]http://schemas.microsoft.com/e ... ot%3B[/url] xmlns:local="clr-namespace:UxHMI" xmlns:mc="[url=http://schemas.openxmlformats.org/markup-compatibility/2006"]http://schemas.openxmlformats. ... ot%3B[/url] xmlns:oxy="[url=http://oxyplot.org/wpf"]http://oxyplot.org/wpf"[/url] xmlns:x="[url=http://schemas.microsoft.com/winfx/2006/xaml">]http://schemas.microsoft.com/w ... gt%3B[/url]
<grid background="White" x:name="Container">
<oxy:plot background="AliceBlue" canvas.left="298" canvas.top="32" fontfamily="Bosch Sans Medium" fontsize="19" foreground="#FF0C6596" margin="0,0,10,0" title="{Binding Title}" x:name="myChart">
<oxy:plot.series>
<oxy:lineseries background="White" color="ForestGreen" itemssource="{Binding Points}" linestyle="Solid" markerfill="Black" markersize="5" markertype="None" x:name="ls">
</oxy:lineseries>
</oxy:plot.series>
</oxy:plot>
<button click="button_Click" content="Random" horizontalalignment="Left" margin="0,278,0,0" verticalalignment="Top" width="75" x:name="button"></button>
</grid>


重要的是

小点

捆绑 x:Name="myChart"

和 ItemsSource=" {

}"

我希望这对那里的人有用。
</usercontrol></datapoint></datapoint>

要回复问题请先登录注册