gpt4 book ai didi

wpf - 您可以使用 LiveCharts 显示带有 x 和 y 值对的线系列吗?

转载 作者:行者123 更新时间:2023-12-04 12:58:03 64 4
gpt4 key购买 nike

我试图通过提供由笛卡尔图显示的 x 和 y 值对来显示折线图。 LiveCharts 可以这样做吗?我在网上找不到这方面的例子。
我知道,您可以为 x 轴提供标签,但我在 x 轴上的值不是线性的,因此它们应该具有不同的间距。
到目前为止,这是我的 Xaml:

<liveCharts:CartesianChart Grid.Column="0"
Margin="5 0 5 0"
Series="{Binding TemperatureSeries}">
<liveCharts:CartesianChart.AxisX>
<liveCharts:Axis Title="Zeit"
FontSize="15"
FontWeight="Bold"
Labels="{Binding Labels}" />
</liveCharts:CartesianChart.AxisX>

<liveCharts:CartesianChart.AxisY>
<liveCharts:Axis Title="Temperature (°C)"
FontSize="15"
FontWeight="Bold"
LabelFormatter="{Binding DoubleToStingConverter}" />
</liveCharts:CartesianChart.AxisY>
</liveCharts:CartesianChart>
这就是 TemperatureSeries 属性的样子。
this.TemperatureSeries =
new SeriesCollection
{
new LineSeries
{
Values = new ChartValues<double>(),
Stroke = redStroke,
Fill = redFill
}
};

最佳答案

您需要使用 Mapper例如CartesianMapper<T> . Mapper将任意对象的数据映射到图表的轴(例如,在 CartesianMapper 的情况下为 x 和 y)。Mapper还允许定义有关数据值呈现的约束。例如,您可以定义超过特定阈值的值应涂成红色。
然后将此数据映射器分配给 LineSeries.Configuration属性(property)。
请注意 ChartValues是一种通用类型,允许将任何数据模型定义为图表值。 Mapper知道如何从这种模型类型中获取值。下面的例子使用了一个简单的 Point结构体作为数据模型:

private void InitializeData()
{
var values = new ChartValues<Point>();

// Create sine graph
for (double x = 0; x < 361; x++)
{
var point = new Point() {X = x, Y = Math.Sin(x * Math.PI / 180)};
values.Add(point);
}

this.TemperatureSeries = new SeriesCollection
{
new LineSeries
{
Configuration = new CartesianMapper<Point>()
.X(point => point.X) // Define a function that returns a value that should map to the x-axis
.Y(point => point.Y) // Define a function that returns a value that should map to the y-axis
.Stroke(point => point.Y > 0.3 ? Brushes.Red : Brushes.LightGreen) // Define a function that returns a Brush based on the current data item
.Fill(point => point.Y > 0.3 ? Brushes.Red : Brushes.LightGreen),
Title = "Series",
Values = values,
PointGeometry = null
}
};
}

关于wpf - 您可以使用 LiveCharts 显示带有 x 和 y 值对的线系列吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63755350/

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