实时图表 - 将数据添加到第二个 Y 轴

问题描述 投票:0回答:1

我的实时图表笛卡尔->折线图从文件/串行端口绘制 5 种不同类型的数据,但它们都在同一个系列上。

我显示了 2 个 Y 轴,但无法动态向每个 Y 轴添加数据。实时图表文档非常糟糕。

我创建了 2 个系列,但数据似乎没有绘制。

<lvc:CartesianChart.AxisX >
     <lvc:Axis Title="DATA POINTS" FontSize="18" MinValue="0" MaxValue="512" Labels="{Binding Labels}"></lvc:Axis>
</lvc:CartesianChart.AxisX>

<lvc:CartesianChart.AxisY>
     <lvc:Axis Title="MOTOR VOLTAGE (mV)" FontSize="18" MinValue="0" MaxValue="8000" ></lvc:Axis>
     <lvc:Axis Title="MOTOR CURRENT (mA)" FontSize="18" MinValue="0" MaxValue="800" Position="RightTop" ></lvc:Axis>
</lvc:CartesianChart.AxisY>

     <lvc:CartesianChart.Series>
          <lvc:LineSeries Name="Chart1" Values="{Binding ChartValues}"/>
          <lvc:LineSeries Name="Chart2" Values="{Binding ChartValues2}"/>
     </lvc:CartesianChart.Series>
</lvc:CartesianChart>

// Setup chart
ChartSeries = new SeriesCollection
{
    new LineSeries
    {
           Title = "Motor Current",
           Values = new ChartValues<Int16> {0},
           PointForeground = Brushes.Red,
           PointGeometry = null
    },
    new LineSeries
    {
           Title = "Voltage",
           Values = new ChartValues<Int16> {0},
           PointForeground = Brushes.Blue,
           PointGeometry = null
    }
};

// Setup chart series
ChartSeries2 = new SeriesCollection
{
    new LineSeries
    {
           Title = "Motor Speed",
           Values = new ChartValues<Int16> {0},
           PointForeground = Brushes.Green,
           PointGeometry = null
    },
    new LineSeries
    {
           Title = "Force",
           Values = new ChartValues<Int16> {0},
           PointForeground = Brushes.Blue,
           PointGeometry = null
    }
};

YFormatter = value => value.ToString("F");

lc_MainChart.LegendLocation = LegendLocation.Right;

ChartSeries[0].Values.Add(MotorCurrent[i]);
ChartSeries[1].Values.Add(VBat[i]);

ChartSeries2[0].Values.Add(MotorSpeed[i]);
ChartSeries2[1].Values.Add(Force[i]);

DataContext = this;
c# wpf livecharts
1个回答
0
投票

解决方案如下:

<lvc:CartesianChart.Series>
      <lvc:LineSeries Name="Chart1" Values="{Binding ChartValues}" ScalesYAt="1"/>
      <lvc:LineSeries Name="Chart2" Values="{Binding ChartValues2}" ScalesYAt="0"/>
 </lvc:CartesianChart.Series>

只需将 ScalesYAt="[轴索引]" 属性添加到 LineSerie, 希望节省您的时间。

© www.soinside.com 2019 - 2024. All rights reserved.