繁体   English   中英

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

[英]Zedgraph Horizontal Bar graph with different bar colors C#

我正在研究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();

找到我要找的东西,原始的链接是: http : //www.ironpython.info/index.php?title=Multi-colored_Bar_Chart_with_ZedGraph 主要修改是制作一个点对列表,而不是发送用于创建条形的双精度数组,而是引用颜色数组并设置填充的最小和最大范围。 修改后的代码如下:

        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();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM