我有以下UI,其中Radar Chart中的值是通过某些TrackBar值的算术平均值计算得出的。 “ Player”对象获取这些值,计算平均值并将其返回到Radar Chart数据系列。

我想做的是,当我在TrackBar中更改值时,Chart实时更改其值。当我更改值时,它会重新计算平均值,然后更改图表形状。

c# - 在WinForms中更新雷达图-LMLPHP

这是我的代码:

public AddPlayerForm()
    {
        InitializeComponent();
        Load += this.AddPlayerForm_Load;//reloads the chart component every continuously
        LoadComboBoxes();
        MetroFramework.Controls.MetroTrackBar[] trackBars = new MetroFramework.Controls.MetroTrackBar[20];
    }

    //loads the Chart Content
    private void AddPlayerForm_Load(object sender, EventArgs e)
    {
        /*I tried to clear the current chart to recalculate and redraw the chart in every cycle
        but its not working this way*/
        chart1.Series.Clear();//clear the current chart
        new_player.SetPlayerStats(  //get values from TrackBars
         mtTrackBarAttack.Value,
         mtTrackBarBallControl.Value,
         .
         .//all trackBar.Values
         .
         mtInjuryResistenceTB.Value,
         1,
         "Messi");

        //recalculate the arithimetic mean and returns as a tag to the chart
        //Ex: {"Agility",60.4}
        Dictionary<string, float> tags = new_player.MeanStats();//Player method that calculates the mean and returns a dictionary <String, float>
        //creates a new series of data
        chart1.Series.Add("s1");
        chart1.Series["s1"].ChartType = SeriesChartType.Radar;


        foreach (string tagname in tags.Keys)
        {
            //for each set of data, plots the name and its value in the Chart
            chart1.Series["s1"].Points.AddXY(tagname, tags[tagname]);

        }


    }


我正在尝试清除旧图表并重绘新图表,但这种方式无法正常工作。

最佳答案

我从未使用过Winforms-Charttool,但您是否已经尝试过仅调用chart1-Object的刷新?
https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.datavisualization.charting.chart.refresh?view=netframework-4.7.2

09-25 21:19