最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - LiveCharts V2 WPF gauge does not update - Stack Overflow

programmeradmin4浏览0评论

I am currently rewriting my program, updating it to LiveCharts V2 and ran into the problem that I can't get my gauges to update. I am using an ObservableCollection, as advised in the documentation and every other object (PieChart and CartesianChart) work perfectly fine with public static ObservableCollection<long> value = new ObservableCollection<long> { 0 }; and later changing it with value[0] = Convert.ToInt64(funnyNumber);.

When trying with the gauge, it takes the value from the declaration but after that nothing changes no matter what I do.

Edit, a small example:

Main Window Constructor:

namespace RecPlot
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            DataContext = new ViewModel();
            InitializeComponent();

            Control.Run();
        }
    }
}

Main Logic:

namespace RecPlot
{
    public class Control
    {
        public static ObservableCollection<float> pieChartValue = new ObservableCollection<float> { 69 };
        public static ObservableCollection<float> gaugeValue = new ObservableCollection<float> { 69 };

        public static async Task Run() //gets run by MainWindow constructor
        {
            pieChartValue[0] = 420; //value changes to 420
            gaugeValue[0] = 420; //value remains at 69
        }
    }
}

View Modlel:

namespace RecPlot
{
    public partial class ViewModel
    {
        public static ISeries[] PieSeriesCollection { get; set; } =
        [
            new PieSeries<float>
            {
                Name = "PieValue",
                Values = Control.pieChartValue
            }
        ]
    
        public static IEnumerable<ISeries> GaugeSeriesCollection { get; set; } =
        GaugeGenerator.BuildSolidGauge(
            new GaugeItem(Control.gaugeValue[0], series => {}),
            new GaugeItem(GaugeItem.Background, series => {}));
    }
}

And xaml:

<lvc:PieChart x:Name="gauge" Series="{Binding GaugeSeriesCollection}" InitialRotation="-225" MaxAngle="270" MinValue="0" MaxValue="1000"/>

<lvc:PieChart x:Name="pieChart" Series="{Binding PieSeriesCollection}"/>

I am going completely insane here so any help is appreciated. Thanks in advance.

发布评论

评论列表(0)

  1. 暂无评论