Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 能否使用LiveCharts显示具有x和y值对的直线序列?_Wpf_Livecharts - Fatal编程技术网

Wpf 能否使用LiveCharts显示具有x和y值对的直线序列?

Wpf 能否使用LiveCharts显示具有x和y值对的直线序列?,wpf,livecharts,Wpf,Livecharts,我试图通过提供由笛卡尔图显示的x和y值对来显示折线图。这有可能与LiveCharts一起使用吗?我在网上找不到这方面的例子 我知道,您可以为x轴提供标签,但我在x轴上的值不是线性的,因此它们应该具有不同的间距 这是到目前为止我的Xaml: <liveCharts:CartesianChart Grid.Column="0" Margin="5 0 5 0"

我试图通过提供由笛卡尔图显示的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
        }
    };
this.TemperatureSeries=
新系列丛书
{
新系列
{
值=新图表值(),
笔划=红色笔划,
填充=红色填充
}
};

您需要使用
映射器
例如
CartesianMapper
Mapper
将任意对象的数据映射到图表的轴上(例如,如果是
CartesianMapper
),则为x和y轴。
Mapper
还允许定义有关数据值表示的约束。例如,您可以定义超过某个阈值的值应涂成红色。
然后将此数据映射器分配给
LineSeries.Configuration
属性

请注意,
ChartValues
是一种通用类型,允许将任何数据模型定义为图表值。
Mapper
知道如何从该模型类型中获取值。以下示例使用简单的
结构作为数据模型:

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
    }
  };
}
private void InitializeData()
{
var值=新的ChartValues();
//创建正弦图
用于(双x=0;x<361;x++)
{
var point=new point(){X=X,Y=Math.Sin(X*Math.PI/180)};
值。添加(点);
}
this.TemperatureSeries=新系列集合
{
新系列
{
配置=新的CartesianMapper()
.X(point=>point.X)//定义一个函数,该函数返回一个应映射到X轴的值
.Y(point=>point.Y)//定义一个函数,该函数返回一个应映射到Y轴的值
.Stroke(point=>point.Y>0.3?brushs.Red:brushs.LightGreen)//定义一个函数,该函数基于当前数据项返回画笔
.填充(点=>点.Y>0.3?画笔。红色:画笔。浅绿色),
Title=“系列”,
值=值,
PointGeometry=null
}
};
}

您需要使用
映射器
例如
CartesianMapper
Mapper
将任意对象的数据映射到图表的轴上(例如,如果是
CartesianMapper
),则为x和y轴。
Mapper
还允许定义有关数据值表示的约束。例如,您可以定义超过某个阈值的值应涂成红色。
然后将此数据映射器分配给
LineSeries.Configuration
属性

请注意,
ChartValues
是一种通用类型,允许将任何数据模型定义为图表值。
Mapper
知道如何从该模型类型中获取值。以下示例使用简单的
结构作为数据模型:

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
    }
  };
}
private void InitializeData()
{
var值=新的ChartValues();
//创建正弦图
用于(双x=0;x<361;x++)
{
var point=new point(){X=X,Y=Math.Sin(X*Math.PI/180)};
值。添加(点);
}
this.TemperatureSeries=新系列集合
{
新系列
{
配置=新的CartesianMapper()
.X(point=>point.X)//定义一个函数,该函数返回一个应映射到X轴的值
.Y(point=>point.Y)//定义一个函数,该函数返回一个应映射到Y轴的值
.Stroke(point=>point.Y>0.3?brushs.Red:brushs.LightGreen)//定义一个函数,该函数基于当前数据项返回画笔
.填充(点=>点.Y>0.3?画笔。红色:画笔。浅绿色),
Title=“系列”,
值=值,
PointGeometry=null
}
};
}