zoukankan      html  css  js  c++  java
  • WinForm"ZedGraph柱状图"控件使用经验分享 之配餐系统的开发

          此文主要是和大家分享下在做配餐系统的新模块开发中,对"ZedGraph柱状图"控件的使用,先看看我在项目所应用的效果:

         如上图所示,此柱状图只有Y轴,且每个柱的颜色都不同  ——没有X轴,却需要显示每种体质的名称和分数,这就需要在常规的(网上的示例)基础上做修改。

    关键代码如下:

    void ShowBar(double[] tzZhfArr)
    {
    string[] tzTypeArr = ComHelper.GetTzTypeArray();
    Dictionary
    <int, double[]> dict = new Dictionary<int, double[]>();
    Color[] colorArr
    ={ Color.Orange,Color.PaleGreen,Color.SlateBlue,
    Color.Pink,Color.Green,Color.LightSkyBlue,
    Color.Gray,Color.GreenYellow,Color.RosyBrown};

    this.zedGraphControl_res.SuspendLayout();

    this.zedGraphControl_res.Controls.Clear();
    ZedGraph.GraphPane myPane
    = this.zedGraphControl_res.GraphPane;

    myPane.Title.Text
    = "体质测试结果柱状图";
    myPane.XAxis.Title.Text
    = "";
    myPane.YAxis.Title.Text
    = "";

    int start_x = 5;
    double tzZhz = 0;
    for (int i = 0; i < tzTypeArr.Length; i++)
    {
    tzZhz
    = tzZhfArr[i] < 0 ? 0 : tzZhfArr[i];
    ZedGraph.BarItem bar
    = myPane.AddBar("", new double[] { start_x }, new double[] { tzZhz }, colorArr[i]);
    bar.Bar.Fill
    = new ZedGraph.Fill(colorArr[i], Color.White, colorArr[i]);

    ZedGraph.TextObj myText
    = new ZedGraph.TextObj(string.Format("{0},{1}", tzTypeArr[i], tzZhz), start_x, tzZhz + 3);
    myText.Location.CoordinateFrame
    = ZedGraph.CoordType.AxisXYScale;
    myText.Location.AlignH
    = ZedGraph.AlignH.Center;
    myText.Location.AlignV
    = ZedGraph.AlignV.Center;
    myText.FontSpec.Family
    = "宋体";
    myText.FontSpec.Size
    = 16f;
    myText.FontSpec.Fill.IsVisible
    = false;
    myText.FontSpec.Border.IsVisible
    = false;
    //myText.FontSpec.Angle = 35;//控制 文字 倾斜度
    myPane.GraphObjList.Add(myText);
    start_x
    += 15;
    }

    myPane.Fill
    = new ZedGraph.Fill(Color.WhiteSmoke, Color.Lavender, 0F);
    myPane.Chart.Fill
    = new ZedGraph.Fill(Color.FromArgb(255, 255, 245),
    Color.FromArgb(
    255, 255, 190), 90F);
    //设置 柱体的宽度
    myPane.BarSettings.ClusterScaleWidth = 30;
    // Bars are stacked
    myPane.BarSettings.Type = ZedGraph.BarType.Cluster;

    myPane.XAxis.IsVisible
    = false;

    // Enable the X and Y axis grids
    myPane.XAxis.MajorGrid.IsVisible = false;
    myPane.YAxis.MajorGrid.IsVisible
    = true;


    myPane.XAxis.Scale.Min
    = -10;
    this.zedGraphControl_res.ResumeLayout();
    this.zedGraphControl_res.AxisChange();
    }

      其中,有几个重要的属性,需要特殊说明下:

    1.         //设置 柱体的宽度
                myPane.BarSettings.ClusterScaleWidth = 30;
                // Bars are stacked
                myPane.BarSettings.Type = ZedGraph.BarType.Cluster;

               设置 柱体的宽度 只在 myPane.BarSettings.Type(柱体布局设置或类型)中的某些值时有效。

    2.      myText.FontSpec.Angle = 35;//控制 文字 倾斜度

    3.      当myPane.XAxis.IsVisible = false时,X轴下方(一般为-y的值)的文本等将无法显示。

     ——ZedGraph是国外的控件,功能貌似很强大,我实现效果可能还有更方便或合适的方法,对其也算是有个大概的了解,希望路过的朋友能分享下你的使用经验!

  • 相关阅读:
    codeforces 587B
    codeforces 552E
    算法竞赛模板 字典树
    算法竞赛模板 二叉树
    算法竞赛模板 图形面积计算
    TZOJ 1545 Hurdles of 110m(动态规划)
    算法竞赛模板 判断线段相交
    算法竞赛模板 折线分割平面
    TZOJ 3005 Triangle(判断点是否在三角形内+卡精度)
    算法竞赛模板 KMP
  • 原文地址:https://www.cnblogs.com/know/p/2008096.html
Copyright © 2011-2022 走看看