gpt4 book ai didi

c# - 在 c# xaml 中创建一个数学图

转载 作者:行者123 更新时间:2023-11-30 20:21:33 25 4
gpt4 key购买 nike

我有一个 c# xaml 项目,我想创建一个实时描绘函数输出变量的绘图。事实上,我想每次绘制变量的新值并在 xaml 图表中对其进行演示。我该怎么做?我正在使用 .NET 4.5。我试着按照下面的答案。我创建了以下代码:

 private void AddChart(List<float> scores)
{
// Draw sine chart:
polyline = new Polyline { Stroke = Brushes.Black };

for (int i = 0; i < scores.Count; i++)
{
var y = scores[i];
polyline.Points.Add(CorrespondingPoint(new Point(i, y)));
}
canvas.Children.Add(polyline);

}
private Point CorrespondingPoint(Point pt)
{
var result = new Point
{
X = (pt.X - xmin) * canvas.Width / (xmax - xmin),
Y = canvas.Height - (pt.Y - ymin) * canvas.Height
/ (ymax - ymin)
};
return result;
}

AddChart 将得分列表作为输入,每次调用该函数时都会更新并绘制它。但是它似乎不是这样工作的。有人可以帮忙吗?如何在图中添加轴?

最佳答案

我尝试了很多开源替代品,但实际上它们不是我需要的,这就是我制作这个 https://github.com/beto-rodriguez/Live-Charts 的原因当您克隆 repo 时,它有一个很好的文档和示例。

XAML

<charts:LineChart Height="300" x:Name="LineChart" 
Background="#FBFBFB" BorderBrush="LightGray" BorderThickness="1"
Zooming="True"></charts:LineChart>

C#

        LineChart.Series = new ObservableCollection<Serie>
{
new LineSerie
{
PrimaryValues = new ObservableCollection<double>
{
-10, 5, 9, 28, -3, 2, 0, 5, 10, 1, 7, 2
}
}
};

关于c# - 在 c# xaml 中创建一个数学图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33756255/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com