I'm trying to figure out how to get c# to put in more than one boxplot in a chart. There's not much help in the internet as soon as it comes to c# instead of R or python. So I'm asking: What did I do wrong or miss in this code?

   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;

    }

enter image description here

Above is the outcome but I'd like 22 of those. Anyone happen to have any kind of idea how to solve this?

有帮助吗?

解决方案

You can create multiple boxplots as

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

其他提示

One might be interested in what I did:

        List<String> Series = new List<String>();
        for (Int32 i = 0; i < 22; i++)
        {
            Series.Add(xValue[i]);
        }
        String Helper = String.Join("; ", Series);

        Chart.chart_main.Series["BoxPlotSeries"]["BoxPlotSeries"] = Helper;

And the outcome:

enter image description here

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top