WPF c1:FlexChart 如何添加不同 ItemsSource 的 Series, 通过MVVM绑定
本帖最后由 Ellia.Duan 于 2023-8-21 16:49 编辑当需要作图多个Series时, 在c1:Series 一级绑定 ItemsSource 会一直报Exception:
System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=RsPointsRawData; DataItem=null; target element is 'Series' (HashCode=3567764); target property is 'ItemsSource' (type 'Object')
xaml 代码为:
<c1:FlexChart Width="700" Height="420" Canvas.Left="80" Canvas.Top="330" Background="White"
ItemsSource="{Binding RsTemperatureData}" BindingX="Temperature" LegendPosition="Right">
<!--<c1:FlexChart.Behaviors>
<c1:ZoomBehavior/>
<c1:TranslateBehavior/>
</c1:FlexChart.Behaviors>
<c1:FlexChart.PlotStyle>
<c1:ChartStyle Fill="Ivory" Stroke="OrangeRed" StrokeThickness="0.5" LinePattern="None" />
</c1:FlexChart.PlotStyle>
<c1:FlexChart.AxisX>
<c1:Axis MajorGrid="True" AxisLine="False" PlotAreaName="PlotArea1" MajorUnit="1"/>
</c1:FlexChart.AxisX>
<c1:FlexChart.PlotAreas>
<c1:PlotArea PlotAreaName="PlotArea1"></c1:PlotArea>
</c1:FlexChart.PlotAreas>-->
<c1:FlexChart.AxisY>
<c1:Axis MajorGrid="True" AxisLine="True"/>
</c1:FlexChart.AxisY>
<!--<c1:FlexChart.Series>
<c1:SeriesSeriesName="RsRawTemperature" ChartType="Scatter"Binding="RsValue" />
<c1:TrendLine SeriesName="Trend Line"Binding="RsValue" FitType="Linear"/>
</c1:FlexChart.Series>-->
<c1:SeriesSeriesName="RsRawTemperature" ChartType="Scatter"Binding="RsValue" />
<c1:TrendLine SeriesName="Trend Line"Binding="RsValue" FitType="Linear"/>
<c1:Series ItemsSource="{Binding RsPointsRawData}" BindingX="Temperature" ChartType="Scatter"Binding="RsValue" />
</c1:FlexChart>
我试过很多次, 似乎只要在c1:Series 一级绑定 ItemsSource 就会一直报这个错。 这个 FlexChart 到底是应该怎么用的, 动不动就报各种错, 然后它依然可以跑起来!
正常的一个用法应该是给flexchart的itemssource绑定一个数据源,不用给series绑定
简单的来说多个series只是Y轴的值不同(在series中设置Binding),但是X轴的值是相同的(在flexchart中设置BindingX)
我看到你现在给series绑定了另一个数据源RsPointsRawData,可能是这个原因引起的错误
具体的问题,你得发一个重现问题的demo上来,我们才能分析
帖子我移动到C1 XAML板块了
是这样的: 我们有这个需求, 做曲线拟合时点坐标的Y轴的值是多次测量的值的平均值,但是我们也把多次测量的值也显示出来。如下图:
绿色的点为5次测量的结果,蓝色的为5次测量的平均值,然后用这平均值去做Trend Line拟合。 现在用上面的xaml 去写是可以显示出来的,但是在Visual Studio 2022上面的output 窗口会报错:
System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=RsPointsRawData; DataItem=null; target element is 'Series' (HashCode=55610924); target property is 'ItemsSource' (type 'Object')
Exception thrown: 'System.Resources.MissingManifestResourceException' in System.Private.CoreLib.dll
Exception thrown: 'System.Exception' in C1.WPF.Chart.dll
Exception thrown: 'System.Resources.MissingManifestResourceException' in System.Private.CoreLib.dll
Exception thrown: 'System.Exception' in C1.WPF.Chart.dll
Exception thrown: 'System.Resources.MissingManifestResourceException' in System.Private.CoreLib.dll
Exception thrown: 'System.Exception' in C1.WPF.Chart.dll
Exception thrown: 'System.Resources.MissingManifestResourceException' in System.Private.CoreLib.dll
Exception thrown: 'System.Exception' in C1.WPF.Chart.dll
Exception thrown: 'System.Resources.MissingManifestResourceException' in System.Private.CoreLib.dll
Exception thrown: 'System.Exception' in C1.WPF.Chart.dll
麻烦提供一个demo上来,我们验证看看
页:
[1]