Ejemplo n.º 1
0
    /**/
    /// <summary>
    /// 画图
    /// </summary>
    /// <param name="webObject"></param>
    /// <param name="g"></param>
    /// <param name="pane"></param>
    private void zedGraphControl_RenderGraph(ZedGraph.Web.ZedGraphWeb webObject, System.Drawing.Graphics g, ZedGraph.MasterPane pane)
    {
        InitProperty();

        GraphPane myPane = pane[0];

        if (Title != string.Empty)
        {
            myPane.Title.Text = Title;
        }
        myPane.XAxis.Title.Text = XAxisTitle;
        myPane.YAxis.Title.Text = YAxisTitle;
        //myPane.Border.Style = System.Drawing.Drawing2D.DashStyle.Dot;
        myPane.Border.Color = Color.White;

        switch (Type)
        {
        case AnalyticsType.Line:
            DrawLine(myPane);
            break;

        case AnalyticsType.Bar:
            DrawBar(myPane);
            break;

        case AnalyticsType.Pie:
            DrawPie(myPane);
            break;

        default:
            break;
        }
        pane.AxisChange(g);
    }

    #region Draw
    /// <summary>
    /// 为柱状图添加标签
    /// </summary>
    /// <param name="graphPane"></param>
    /// <param name="valueFormat"></param>
    /// <param name="valueDouble"></param>
    private void CreateBarLabels(GraphPane graphPane, string valueFormat, List <double> valueDouble)
    {
        for (int j = 0; j < valueDouble.Count; j++)
        {
            PointPair pt   = new PointPair(j + 1, valueDouble[j]);
            TextObj   text = new TextObj(pt.Y.ToString(valueFormat), pt.X, pt.Y > (double)10 ? pt.Y - 10 : pt.Y, CoordType.AxisXYScale, AlignH.Left, AlignV.Center);
            //text.ZOrder = ZOrder.A_InFront;
            //text.FontSpec.Border.IsVisible = false;
            //text.FontSpec.Fill.IsVisible = false;
            //text.FontSpec.Angle = 1; //数值字体倾斜度
            //text.FontSpec.Size = 12;
            //text.FontSpec.FontColor = Color.Black;
            ////text.FontSpec.IsBold = true;
            text.Location.CoordinateFrame = CoordType.AxisXY2Scale;
            text.Location.AlignH          = AlignH.Center;
            text.Location.AlignV          = AlignV.Center;
            graphPane.GraphObjList.Add(text);
        }
    }

    /**/
    /// <summary>
    /// 画折线图
    /// </summary>
    /// <param name="graphPane"></param>
    private void DrawLine(GraphPane graphPane)
    {
        for (int i = 0; i < Count; i++)
        {
            LineItem myCurve = graphPane.AddCurve(CurveNameList[i], DataSource[i], Colors[i], SymbolType.Circle);
            myCurve.Line.Fill = new Fill(Colors[i], Color.Transparent, -45F);  //显示区域颜色,可去掉
        }

        graphPane.XAxis.MajorTic.IsBetweenLabels = true;
        string[] labels = NameList.ToArray();
        graphPane.XAxis.Scale.TextLabels = labels;
        graphPane.XAxis.Type             = AxisType.Text;
        graphPane.Fill = new Fill(Color.White, Color.White, 45.0f);
    }