我试图弄清楚如何让C#在图表中放入多个箱形图。关于C#而不是R或python,互联网上的帮助不多。所以我问:这段代码我做错了什么或错过了什么?

   private void on_boxplot(object sender, EventArgs e)
    {
        List<String> xValue = new List<String> { "Ala (A)", "Arg (R)", "Asn (N)", "Asp (D)", "Cys (C)", "Gln (Q)", "Glu (E)", "Gly (G)", "His (H)", "Ile (I)", "Leu (L)", "Lys (K)", "Met (M)", "Phe (F)", "Pro (P)", "Ser (S)", "Thr (T)", "Trp (W)", "Tyr (Y)", "Val (V)", "Pyl (O)", "Sec (U)" };
        Chart Chart = new Chart();
        Chart.chart_main.Series.Clear();
        Chart.chart_main.Series.Add("BoxPlotSeries");
        for (Int32 i = 0; i < xValue.Count; i++)
        {
            Chart.chart_main.Series.Add(xValue[i]);
        }

        for (Int32 i = 0; i < DYL; i++)
        {
            if (Data[i, 0] == null) break;
            Chart.chart_main.Series[xValue[0]].Points.AddY(boxplot_helper(i, Dataslots[0]));
            Chart.chart_main.Series[xValue[1]].Points.AddY(boxplot_helper(i, Dataslots[1]));
            Chart.chart_main.Series[xValue[2]].Points.AddY(boxplot_helper(i, Dataslots[2]));
            Chart.chart_main.Series[xValue[3]].Points.AddY(boxplot_helper(i, Dataslots[3]));
            Chart.chart_main.Series[xValue[4]].Points.AddY(boxplot_helper(i, Dataslots[4]));
            Chart.chart_main.Series[xValue[5]].Points.AddY(boxplot_helper(i, Dataslots[5]));
            Chart.chart_main.Series[xValue[6]].Points.AddY(boxplot_helper(i, Dataslots[6]));
            Chart.chart_main.Series[xValue[7]].Points.AddY(boxplot_helper(i, Dataslots[7]));
            Chart.chart_main.Series[xValue[8]].Points.AddY(boxplot_helper(i, Dataslots[8]));
            Chart.chart_main.Series[xValue[9]].Points.AddY(boxplot_helper(i, Dataslots[9]));
            Chart.chart_main.Series[xValue[10]].Points.AddY(boxplot_helper(i, Dataslots[10]));
            Chart.chart_main.Series[xValue[11]].Points.AddY(boxplot_helper(i, Dataslots[11]));
            Chart.chart_main.Series[xValue[12]].Points.AddY(boxplot_helper(i, Dataslots[12]));
            Chart.chart_main.Series[xValue[13]].Points.AddY(boxplot_helper(i, Dataslots[13]));
            Chart.chart_main.Series[xValue[14]].Points.AddY(boxplot_helper(i, Dataslots[14]));
            Chart.chart_main.Series[xValue[15]].Points.AddY(boxplot_helper(i, Dataslots[15]));
            Chart.chart_main.Series[xValue[16]].Points.AddY(boxplot_helper(i, Dataslots[16]));
            Chart.chart_main.Series[xValue[17]].Points.AddY(boxplot_helper(i, Dataslots[17]));
            Chart.chart_main.Series[xValue[18]].Points.AddY(boxplot_helper(i, Dataslots[18]));
            Chart.chart_main.Series[xValue[19]].Points.AddY(boxplot_helper(i, Dataslots[19]));
            Chart.chart_main.Series[xValue[20]].Points.AddY(boxplot_helper(i, Dataslots[20]));
            Chart.chart_main.Series[xValue[21]].Points.AddY(boxplot_helper(i, Dataslots[21]));
        }

        Chart.chart_main.Series["BoxPlotSeries"].ChartType = SeriesChartType.BoxPlot;
        Chart.chart_main.Series["BoxPlotSeries"]["BoxPlotSeries"] = xValue[0];

        Chart.chart_main.ChartAreas.Add("BoxPlot");
        Chart.chart_main.Series["BoxPlotSeries"].ChartArea = "BoxPlot";

        Chart.chart_main.Series["BoxPlotSeries"]["BoxPlotWhiskerPercentile"] = "0";
        Chart.chart_main.Series["BoxPlotSeries"]["BoxPlotPercentile"] = "25";
        Chart.chart_main.Series["BoxPlotSeries"]["BoxPlotShowAverage"] = "true";
        Chart.chart_main.Series["BoxPlotSeries"]["BoxPlotShowMedian"] = "true";
        Chart.chart_main.Series["BoxPlotSeries"]["BoxPlotShowUnusualValues"] = "true";
        Chart.chart_main.Series["BoxPlotSeries"]["MaxPixelPointWidth"] = "15";
        Chart.chart_main.Series["BoxPlotSeries"].BorderWidth = 2;
        Chart.Show();

    }

    private Double boxplot_helper(Int32 i, Int32 slot)
    {
        String Santas = Data[i, slot].Replace('.', ',').TrimEnd('%').Trim();
        Double LittleHelper = Convert.ToDouble(Santas);
        return LittleHelper;

    }




以上是结果,但我要其中22个。任何人碰巧有任何解决办法吗?

最佳答案

您可以创建多个箱形图

Chart.chart_main.Series["BoxPlotSeries"]["BoxPlotSeries"] = string.Join(";", xValue);

09-28 01:01