Zedgraph具有不同条形颜色的水平条形图C#

Zedgraph具有不同条形颜色的水平条形图C#,c#,colors,zedgraph,C#,Colors,Zedgraph,我正在研究zedgraph并生成一个水平条形图。我只想知道是否有任何方法可以使每一个单条都有不同的颜色。代码的输出是可以接受的,我只打算更改正在生成的条的颜色。任何帮助都将不胜感激。谢谢 myPane.YAxis.Title.Text = "Nominees"; myPane.XAxis.Title.Text = "Votes"; // Make up some random data points string[] label

我正在研究zedgraph并生成一个水平条形图。我只想知道是否有任何方法可以使每一个单条都有不同的颜色。代码的输出是可以接受的,我只打算更改正在生成的条的颜色。任何帮助都将不胜感激。谢谢

        myPane.YAxis.Title.Text = "Nominees";
        myPane.XAxis.Title.Text = "Votes";

        // Make up some random data points

        string[] labels= new string[count];

        for (int i = count-1; i >= 0; i--)
        {
            labels[counter] = voternames[i];
            counter++;
        }



        for (int i = count1-1; i >= 0; i--)
        {
            y0[counter1] = Convert.ToDouble(votes[i]);
            counter1++;
        }


        // Generate a red bar with "Curve 1" in the legend
        BarItem myBar = myPane.AddBar("", y0, null, Color.Green);


        // Draw the X tics between the labels instead of 
        // at the labels
        myPane.YAxis.MajorTic.IsBetweenLabels = false;
        // Set the XAxis labels
        myPane.YAxis.Scale.TextLabels = labels;
        // Set the XAxis to Text type
        myPane.YAxis.Type = AxisType.Text;

        myPane.BarSettings.Base = BarBase.Y;

        // Fill the Axis and Pane backgrounds
        myPane.Fill = new Fill(Color.FromArgb(250, 250, 255));

        // Tell ZedGraph to refigure the
        // axes since the data have changed

        zgc.AxisChange();
        zgc.Refresh();

找到我要查找的内容,原始源链接为: . 主要的修改是创建点对列表,而不是发送双数组来创建条形图,提供对颜色数组的引用并设置填充的最小和最大范围。修改后的代码如下:

        myPane.YAxis.Title.Text = "Nominees";
        myPane.XAxis.Title.Text = "Votes";

        // Make up some random data points

        string[] labels= new string[count];
        //string[] labelx = new string[count];
        for (int i = count-1; i >= 0; i--)
        {
            labels[counter] = voternames[i];
            counter++;
        }



        for (int i = count1-1; i >= 0; i--)
        {
            y0[counter1] = Convert.ToDouble(votes[i]);
            counter1++;
        }

        for (int i = 0; i < y0.Length; i++)
        {
    //Adding the x axis data and using y axis as a source to color a single bar
            list.Add(y0[i], i / 2.0);
        }


        Color[] colors = new Color[] {Color.Red, Color.Yellow, Color.Green, Color.Blue, Color.Purple};

    // Generate a bar with point pair list in the legend
        BarItem myBar = myPane.AddBar("", list, Color.Green);

    // Giving ref of color array
    myBar.Bar.Fill = new Fill(colors);

    //Setting to fill with using point values of y axis
        myBar.Bar.Fill.Type = FillType.GradientByY;

    //Setting min and max range is important
        myBar.Bar.Fill.RangeMin = 0;
        myBar.Bar.Fill.RangeMax = Convert.ToInt32(y0[0]);

        // Draw the X tics between the labels instead of 
        // at the labels
        myPane.YAxis.MajorTic.IsBetweenLabels = false;
        // Set the XAxis labels
        myPane.YAxis.Scale.TextLabels = labels;
        // Set the XAxis to Text type
        myPane.YAxis.Type = AxisType.Text;

        myPane.BarSettings.Base = BarBase.Y;

        // Fill the Axis and Pane backgrounds
        //myPane.Chart.Fill = new Fill(Color.White,Color.FromArgb(255, 255, 166), 90F);
        myPane.Fill = new Fill(Color.FromArgb(250, 250, 255));

        // Tell ZedGraph to refigure the
        // axes since the data have changed

        zgc.AxisChange();
        zgc.Refresh();
myPane.YAxis.Title.Text=“代名人”;
myPane.XAxis.Title.Text=“投票”;
//编一些随机的数据点
字符串[]标签=新字符串[计数];
//字符串[]labelx=新字符串[计数];
对于(int i=count-1;i>=0;i--)
{
标签[计数器]=voternames[i];
计数器++;
}
对于(int i=count1-1;i>=0;i--)
{
y0[counter1]=转换为双票(票数[i]);
计数器1++;
}
for(int i=0;i