How do I correctly update my chart values? (In real time)

前端 未结 3 1308
猫巷女王i
猫巷女王i 2021-01-18 11:15

I recently encountered a tool called LiveChart and decided to test it out.

Unfortunately I\'ve been having some problems figuring out how to update the chart values

3条回答
  •  执念已碎
    2021-01-18 11:26

    Live-Charts tries to keep it simple. The logic is to use a generic collection with the type you need to plot, and then as easy as adding/removing or updating any element in this collection then your chart will be updated.

    To answer your question, you normally need to:

    public partial class Form1 : Form
    {
        private ObservableValue value1;
    
        public Form1()
        {
            InitializeComponent();
    
            //int val1 = int.Parse(Settings.Default.Value1);
    
            value1 = new ObservableValue(3);
            //...
    
            cartesianChart1.Series.Add(new LineSeries 
            {
                Values = new ChartValues { value1, ... },
            });
        }
    
        private void changeValue1ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            value1.Value = 10;
            Settings.Default.Value1 = "10";
            Settings.Default.Save();
            this.Text = Settings.Default.Value1;
    
        }
    }
    

    Then the library will handle animations and the update

提交回复
热议问题