【问题标题】:Zedgraph Horizontal Bar graph with different bar colors C#具有不同条形颜色的 Zedgraph 水平条形图 C#
【发布时间】:2015-05-20 08:40:04
【问题描述】:

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

【问题讨论】:

标签: c# colors zedgraph


【解决方案1】:

找到了我要找的东西,原文链接是: 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();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-04
    • 1970-01-01
    • 2023-03-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多