コード例 #1
0
        private void DrawBookGraph()
        {
            int book     = flow.List();
            int bookRent = flow.GetRented();

            GraphPane pane = zgc.GraphPane;

            zgc.IsEnableWheelZoom = true;
            pane.Title.Text       = "Book Graph";

            string[] row     = { "Rent Books", "Rent Ready Books", "All Books" };
            double[] bookNum = { bookRent, book - bookRent, book };

            pane.AddPieSlices(bookNum, new[] { "Rent Books", "Rent Ready Books", null });
            pane.Legend.IsVisible = true;

            LineItem line = pane.AddCurve(null, null, bookNum, Color.Purple);

            line.Line.Fill = new Fill(Color.Red, Color.White, Color.Blue);

            pane.XAxis.Scale.TextLabels = row;
            pane.XAxis.Type             = AxisType.Text;

            pane.Chart.Fill       = new Fill(Color.White, Color.FromArgb(242, 242, 242), 90f);
            pane.Fill             = new Fill(Color.FromArgb(245, 245, 245));
            pane.Border.IsVisible = false;
            zgc.AxisChange();
        }
コード例 #2
0
        private void kitap_grafik_Load(object sender, EventArgs e)
        {
            //zedgraph yardımıyla tüm kitaplardan verilen kitap sayısını çıkarıp tablo üzerinde "verilmeye hazır kitap sayısı" , "tüm kitap sayısı" ve "Verilen kitap sayısı"'nı
            //grafik üzerinde gösteriyoruz.
            int ktp         = zedgraph.listele();
            int verilen_ktp = zedgraph.alma();

            GraphPane myPane = zedGraphControl1.GraphPane;

            //kitap sayıları ile ilgili satırlar tanımlanır ve kitap sayıları için işlemler yapılır.
            string[] satir      = { "Verilen Kitaplar", "Verilmeye Hazır Kitaplar", "Tüm Kitaplar" };
            double[] kitap_sayi = { verilen_ktp, ktp - verilen_ktp, ktp };

            //verilen kitap ve tüm kitaplar tablo üzerinde kutu yanında gösterilir.
            myPane.AddPieSlices(kitap_sayi, new[] { "Verilen Kitaplar", "Verilmeye Hazır Kitaplar", null });
            myPane.Legend.IsVisible = true;
            LineItem myLine = myPane.AddCurve(null, null, kitap_sayi, Color.Red);

            //tablo renk dönüşümü
            myLine.Line.Fill = new Fill(Color.Red, Color.White, Color.Blue);

            myPane.XAxis.Scale.TextLabels = satir;
            myPane.XAxis.Type             = AxisType.Text;

            //tablo renk ve yön fonksiyonu.
            myPane.Chart.Fill = new Fill(Color.White, Color.FromArgb(255, 255, 166), 90F);
            myPane.Fill       = new Fill(Color.FromArgb(250, 250, 255));
            zedGraphControl1.AxisChange();
        }
コード例 #3
0
        private void Representacion(ZedGraphControl zedControl, int incompleto, int proceso, int procedente, int improcedente, int totales)
        {
            GraphPane grafico = zedGrafico.GraphPane;

            double[] values = { incompleto, proceso, procedente, improcedente };
            string[] labels = { "Incompleto", "En proceso", "Procedente", "No procedente" };
            Color[]  colors = { Color.Orange, Color.Yellow, Color.Green, Color.Red };

            grafico.Title.Text = "Expedientes recibidos";

            grafico.Fill            = new Fill(Color.White, Color.Gray, 45.0f);
            grafico.Chart.Fill.Type = FillType.None;

            grafico.Legend.Position      = LegendPos.Float;
            grafico.Legend.Location      = new Location(0.95f, 0.15f, CoordType.PaneFraction, AlignH.Right, AlignV.Top);
            grafico.Legend.FontSpec.Size = 10f;
            grafico.Legend.IsHStack      = false;
            grafico.Legend.IsVisible     = false;

            PieItem[] slices = new PieItem[values.Length];
            slices = grafico.AddPieSlices(values, labels);

            ((PieItem)slices[0]).Fill.Color = Color.Orange;
            ((PieItem)slices[1]).Fill.Color = Color.Yellow;
            ((PieItem)slices[2]).Fill.Color = Color.Green;
            ((PieItem)slices[3]).Fill.Color = Color.DarkRed;


            ((PieItem)slices[0]).LabelType = PieLabelType.Name_Value_Percent;
            ((PieItem)slices[1]).LabelType = PieLabelType.Name_Value_Percent;
            ((PieItem)slices[2]).LabelType = PieLabelType.Name_Value_Percent;
            ((PieItem)slices[3]).LabelType = PieLabelType.Name_Value_Percent;

            CurveList curves = grafico.CurveList;
            double    total  = 0;

            for (int x = 0; x < curves.Count; x++)
            {
                total += ((PieItem)curves[x]).Value;
            }

            TextObj text = new TextObj("Expedientes totales: " + total.ToString(), 0.12f, 0.95f, CoordType.XChartFractionYPaneFraction);

            text.Location.AlignH           = AlignH.Center;
            text.Location.AlignV           = AlignV.Bottom;
            text.FontSpec.Border.IsVisible = false;
            text.FontSpec.Fill             = new Fill(Color.White, Color.Gray, 75.0f);
            grafico.GraphObjList.Add(text);

            zedGrafico.AxisChange();
            zedGrafico.Invalidate();
        }
コード例 #4
0
        private void drawProblems(Dictionary <Problems, double> data)
        {
            pieChartProblems.GraphPane.CurveList.Clear();
            pieChartProblems.GraphPane.GraphObjList.Clear();
            piePaneProblems            = pieChartProblems.GraphPane;
            piePaneProblems.Title.Text = "Ratio of finded problems";
            var labels = new List <string>();
            var values = new List <double>();

            foreach (var key in data.Keys)
            {
                values.Add(data[key]);
                labels.Add(key.ToString());
            }
            piePaneProblems.AddPieSlices(values.ToArray(), labels.ToArray());
            pieChartProblems.AxisChange();
            pieChartProblems.Invalidate();
        }
コード例 #5
0
        private void frmKutuphaneDurumRapor_Load(object sender, EventArgs e)
        {
            VeriYenile();
            GraphPane myPane = zedGraphControl1.GraphPane;

            string[] labels = { "Emanette", "Verilmeye Hazır", "Tüm Kitaplar" };
            double[] y      = { dataG_Emanet.Rows.Count - 1, dataGVeri.Rows.Count - 1, dataG_Tum.Rows.Count - 1 };
            myPane.AddPieSlices(y, new[] { "Emanette", "Verilmeye Hazır", null });
            myPane.Legend.IsVisible = true;
            LineItem myLine = myPane.AddCurve(null, null, y, Color.Red);

            myLine.Line.Fill = new Fill(Color.Red, Color.White, Color.Blue);

            myPane.XAxis.Scale.TextLabels = labels;
            myPane.XAxis.Type             = AxisType.Text;

            myPane.Chart.Fill = new Fill(Color.White, Color.FromArgb(255, 255, 166), 90F);
            myPane.Fill       = new Fill(Color.FromArgb(250, 250, 255));
            zedGraphControl1.AxisChange();
        }
コード例 #6
0
        public Bitmap RealtimeBackInfoStat_TeacherGraphPrint(string getDept, PanelControl pControl)
        {
            using (RealtimeInfo_TeacherDataAccess realTimeInfo_TeacherDataAccess = new RealtimeInfo_TeacherDataAccess())
            {
                try
                {
                    DataSet dsDutyID = realTimeInfo_TeacherDataAccess.GetDutyID(DateTime.Now.ToString("HH:mm:ss"));
                    int     teaAttOnTimeNumbersInDuty      = 0;
                    int     teaAttNotOnTimeNumbersInDuty   = 0;
                    int     teaLeaveOnTimeNumbersInDuty    = 0;
                    int     teaLeaveNotOnTimeNumbersInDuty = 0;
                    int     teaShouldLeaveInDuty           = 0;

                    if (dsDutyID.Tables[0].Rows.Count > 0)
                    {
                        foreach (DataRow dutyRow in dsDutyID.Tables[0].Rows)
                        {
                            //teaAttNumbersInDuty += realTimeInfo_TeacherDataAccess.GetTeaNumbers(DateTime.Now.DayOfWeek.ToString(),dutyRow[0].ToString(),getDept);
                            realTimeInfo_TeacherDataAccess.GetTeaWorkingNumbers(dutyRow[0].ToString(), ref teaAttOnTimeNumbersInDuty, ref teaAttNotOnTimeNumbersInDuty, getDept, DateTime.Now.Date);
                            realTimeInfo_TeacherDataAccess.GetTeaLeaveNumbers(dutyRow[0].ToString(), ref teaLeaveOnTimeNumbersInDuty, ref teaLeaveNotOnTimeNumbersInDuty, getDept, DateTime.Now.Date);
                        }
                    }

                    int noDutyTotal  = 0;
                    int noDutyAttend = 0;
                    int noDutyLeave  = 0;

                    realTimeInfo_TeacherDataAccess.GetTeacherRealTimeInfoWithNoDuty(getDept, DateTime.Now.DayOfWeek.ToString(), ref noDutyTotal, ref noDutyAttend, ref noDutyLeave);

                    teaLeaveOnTimeNumbersInDuty += noDutyLeave;
                    teaShouldLeaveInDuty         = teaAttOnTimeNumbersInDuty + teaAttNotOnTimeNumbersInDuty + noDutyAttend;


                    double onTimePer    = (double)teaLeaveOnTimeNumbersInDuty / (double)teaShouldLeaveInDuty;
                    double notOnTimePer = (double)teaLeaveNotOnTimeNumbersInDuty / (double)teaShouldLeaveInDuty;
                    double remainPer    = 1 - (((double)teaLeaveOnTimeNumbersInDuty + (double)teaLeaveNotOnTimeNumbersInDuty) / (double)teaShouldLeaveInDuty);

                    zedGraph_RealtimeMorningInfoStatTeacher = new ZedGraphControl();
                    pControl.Controls.Clear();
                    pControl.Controls.Add(zedGraph_RealtimeMorningInfoStatTeacher);
                    zedGraph_RealtimeMorningInfoStatTeacher.Dock = DockStyle.Fill;

                    GraphPane myPane = zedGraph_RealtimeMorningInfoStatTeacher.GraphPane;

                    if (getDept.Equals(""))
                    {
                        myPane.Title = new GardenInfoDataAccess().GetGardenInfo().Tables[0].Rows[0][1].ToString()
                                       + "全体教职工下班情况实时统计图\n" + "统计日期: " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    }
                    else
                    {
                        myPane.Title = new GardenInfoDataAccess().GetGardenInfo().Tables[0].Rows[0][1].ToString()
                                       + getDept + "部教师下班情况实时统计图\n" + "统计日期: " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    }

                    double[] statusVal   = { onTimePer, notOnTimePer, remainPer };
                    string[] statusLabel = { "离开", "早退", "剩余" };

                    myPane.PaneFill             = new Fill(Color.Cornsilk);
                    myPane.AxisFill             = new Fill(Color.Cornsilk);
                    myPane.Legend.Position      = LegendPos.Right;
                    myPane.Legend.FontSpec.Size = 12;

                    PieItem [] slices = new PieItem[statusVal.Length];
                    slices = myPane.AddPieSlices(statusVal, statusLabel);

                    ((PieItem)slices[0]).LabelType = PieLabelType.Percent;
                    ((PieItem)slices[0]).LabelDetail.FontSpec.Size = 14;
                    ((PieItem)slices[1]).LabelType = PieLabelType.Percent;
                    ((PieItem)slices[1]).LabelDetail.FontSpec.Size = 14;
                    ((PieItem)slices[2]).LabelType = PieLabelType.Percent;
                    ((PieItem)slices[2]).LabelDetail.FontSpec.Size = 14;
                    ((PieItem)slices[1]).Displacement = .1;

                    BoxItem box = new BoxItem(new RectangleF(0F, 0F, 1F, 1F),
                                              Color.Empty, Color.PeachPuff);
                    box.Location.CoordinateFrame = CoordType.AxisFraction;
                    box.Border.IsVisible         = false;
                    box.Location.AlignH          = AlignH.Left;
                    box.Location.AlignV          = AlignV.Top;
                    box.ZOrder = ZOrder.E_BehindAxis;

                    myPane.GraphItemList.Add(box);

                    zedGraph_RealtimeMorningInfoStatTeacher.IsShowContextMenu = false;
                    zedGraph_RealtimeMorningInfoStatTeacher.IsEnableZoom      = false;
                    zedGraph_RealtimeMorningInfoStatTeacher.AxisChange();

                    return(myPane.Image);
                }
                catch (Exception e)
                {
                    Util.WriteLog(e.Message, Util.EXCEPTION_LOG_TITLE);
                    return(null);
                }
            }
        }
コード例 #7
0
        public Bitmap Pie_BackInfoStat(string getGrade, string getClass, DateTime getDate, PanelControl pControl)
        {
            using (RealtimeInfoDataAccess realTimeInfoDataAccess = new RealtimeInfoDataAccess())
            {
                try
                {
                    int getHasGone    = 0;
                    int getHasnotGone = 0;
                    int getStuNumbers = 0;

                    realTimeInfoDataAccess.GetRealtimeBackInfo_Graphic(getGrade, getClass, getDate, ref getHasGone, ref getHasnotGone, ref getStuNumbers);

                    double hasGonePer    = (double)getHasGone / (double)getStuNumbers;
                    double hasnotGonePer = (double)getHasnotGone / (double)getStuNumbers;

                    zedGraph_RealTimeInfoStatStudent = new ZedGraphControl();
                    pControl.Controls.Clear();
                    pControl.Controls.Add(zedGraph_RealTimeInfoStatStudent);
                    zedGraph_RealTimeInfoStatStudent.Dock = DockStyle.Fill;

                    GraphPane myPane = zedGraph_RealTimeInfoStatStudent.GraphPane;

                    if (getGrade.Equals(""))
                    {
                        myPane.Title = new GardenInfoDataAccess().GetGardenInfo().Tables[0].Rows[0][1].ToString()
                                       + "全年级晚接信息统计图\n" + "统计日期: " + getDate.ToString("yyyy-MM-dd");
                    }

                    else if (getClass.Equals(""))
                    {
                        myPane.Title = new GardenInfoDataAccess().GetGardenInfo().Tables[0].Rows[0][1].ToString()
                                       + new StuInfoDataAccess().GetGradeList("", getGrade).Tables[0].Rows[0][1].ToString()
                                       + "晚接信息统计图\n" + "统计日期: " + getDate.ToString("yyyy-MM-dd");
                    }
                    else
                    {
                        myPane.Title = new GardenInfoDataAccess().GetGardenInfo().Tables[0].Rows[0][1].ToString()
                                       + new RealtimeInfoDataAccess().setClassList("", getClass, getGrade).Tables[0].Rows[0][1].ToString()
                                       + "晚接信息统计图\n" + "统计日期: " + getDate.ToString("yyyy-MM-dd");
                    }

                    double[] statusVal   = { hasGonePer, hasnotGonePer };
                    string[] statusLabel = { "已接走", "未接走" };

                    myPane.PaneFill             = new Fill(Color.Cornsilk);
                    myPane.AxisFill             = new Fill(Color.Cornsilk);
                    myPane.Legend.Position      = LegendPos.Right;
                    myPane.Legend.FontSpec.Size = 12;

                    PieItem [] slices = new PieItem[statusVal.Length];
                    slices = myPane.AddPieSlices(statusVal, statusLabel);

                    ((PieItem)slices[0]).LabelType = PieLabelType.Percent;
                    ((PieItem)slices[0]).LabelDetail.FontSpec.Size = 14;
                    ((PieItem)slices[1]).LabelType = PieLabelType.Percent;
                    ((PieItem)slices[1]).LabelDetail.FontSpec.Size = 14;
                    ((PieItem)slices[1]).Displacement = .1;

                    BoxItem box = new BoxItem(new RectangleF(0F, 0F, 1F, 1F),
                                              Color.Empty, Color.PeachPuff);
                    box.Location.CoordinateFrame = CoordType.AxisFraction;
                    box.Border.IsVisible         = false;
                    box.Location.AlignH          = AlignH.Left;
                    box.Location.AlignV          = AlignV.Top;
                    box.ZOrder = ZOrder.E_BehindAxis;

                    myPane.GraphItemList.Add(box);

                    zedGraph_RealTimeInfoStatStudent.IsShowContextMenu = false;
                    zedGraph_RealTimeInfoStatStudent.IsEnableZoom      = false;
                    zedGraph_RealTimeInfoStatStudent.AxisChange();

                    return(myPane.Image);
                }
                catch (Exception e)
                {
                    Util.WriteLog(e.Message, Util.EXCEPTION_LOG_TITLE);
                    return(null);
                }
            }
        }
コード例 #8
0
        }   //  end CreateBarGraph

        private void CreatePieGraph(ZedGraphControl zgc)
        {
            //get reference to the GraphPane
            GraphPane currPane = zgc.GraphPane;

            currPane.CurveList.Clear();
            //  Set titles
            currPane.Title.Text = currTitle;
            currPane.Title.FontSpec.IsItalic = true;
            currPane.Title.FontSpec.Size     = 28;
            currPane.Title.FontSpec.Family   = "Times New Roman";

            //  fill the pane background with a color gradient
            currPane.Fill = new Fill(Color.White, Color.ForestGreen, 45.0f);
            //  No fill for the chart background
            currPane.Chart.Fill.Type = FillType.None;

            //  Set the legend to an arbitrary location
            currPane.Legend.Position = LegendPos.InsideBotRight;
            currPane.Legend.Location = new Location(0.95f, 0.12f, CoordType.PaneFraction,
                                                    AlignH.Right, AlignV.Top);
            currPane.Legend.FontSpec.Size = 8f;
            currPane.Legend.IsHStack      = false;

            //  Add pie slices
            int listTotal = 0;

            if (graphNum != 10)
            {
                listTotal = lcdList.Count;
            }
            else
            {
                listTotal = graphData.Count;
            }
            double[] valuesForSlices = new double[listTotal];
            string[] labelsForSlices = new string[listTotal];
            int      listCnt         = 0;
            double   valuesTotal     = 0;
            string   totalLabel      = "";
            //  request was made to put percentages on each group
            //  to capture the small areas that don't show up well in the chart
            double        totalValue      = 0;
            double        percentOfTotal  = 0;
            StringBuilder combinedLabel   = new StringBuilder();
            string        convertedNumber = "";

            switch (graphNum)
            {
            case 2:
                totalValue = lcdList.Sum(l => l.SumExpanFactor);
                //  dump needed values into arrays
                foreach (LCDDO l in lcdList)
                {
                    valuesForSlices[listCnt] = l.SumExpanFactor;
                    combinedLabel.Append(l.Species);
                    //  calculate percentage
                    percentOfTotal = l.SumExpanFactor / totalValue * 100;
                    combinedLabel.Append(" ");
                    convertedNumber = Utilities.FormatField(percentOfTotal, "{0,4:F1}").ToString();
                    combinedLabel.Append(convertedNumber);
                    combinedLabel.Append("%");
                    labelsForSlices[listCnt] = combinedLabel.ToString();
                    listCnt++;
                    combinedLabel.Remove(0, combinedLabel.Length);
                }       //  end foreach loop
                valuesTotal = lcdList.Sum(l => l.SumExpanFactor);
                totalLabel  = "TOTAL NUMBER OF TREES\n";
                totalLabel += Utilities.FormatField(valuesTotal, "{0,10:F0}").ToString();
                break;

            case 3:
                totalValue = lcdList.Sum(l => l.SumNCUFT);
                //  dump needed values into arrays
                foreach (LCDDO l in lcdList)
                {
                    valuesForSlices[listCnt] = l.SumNCUFT;
                    combinedLabel.Append(l.Species);
                    //  calculate percentage
                    percentOfTotal = l.SumNCUFT / totalValue * 100;
                    combinedLabel.Append(" ");
                    convertedNumber = Utilities.FormatField(percentOfTotal, "{0,4:F1}").ToString();
                    combinedLabel.Append(convertedNumber);
                    combinedLabel.Append("%");
                    labelsForSlices[listCnt] = combinedLabel.ToString();
                    listCnt++;
                    combinedLabel.Remove(0, combinedLabel.Length);
                }       //  end foreach loop
                valuesTotal = lcdList.Sum(l => l.SumNCUFT);
                totalLabel  = "TOTAL NET CUFT VOLUME\n";
                totalLabel += Utilities.FormatField(valuesTotal, "{0,10:F0}").ToString();
                break;

            case 4:
                totalValue = lcdList.Sum(l => l.SumNCUFT);
                //  dump needed values into arrays
                foreach (LCDDO l in lcdList)
                {
                    valuesForSlices[listCnt] = l.SumNCUFT;
                    //  NOTE -- for this report, primary product was dumped into species
                    //  for convenience in coding
                    combinedLabel.Append(l.Species);
                    //  calculate percentage
                    percentOfTotal = l.SumNCUFT / totalValue * 100;
                    combinedLabel.Append(" ");
                    convertedNumber = Utilities.FormatField(percentOfTotal, "{0,4:F1}").ToString();
                    combinedLabel.Append(convertedNumber);
                    combinedLabel.Append("%");
                    labelsForSlices[listCnt] = combinedLabel.ToString();
                    listCnt++;
                    combinedLabel.Remove(0, combinedLabel.Length);
                }       //  end foreach loop
                valuesTotal = lcdList.Sum(l => l.SumNCUFT);
                totalLabel  = "TOTAL NET CUFT VOLUME\n";
                totalLabel += Utilities.FormatField(valuesTotal, "{0,10:F0}").ToString();
                break;

            case 10:
                //  dump needed values into arrays
                foreach (CreateTextFile.ReportSubtotal gd in graphData)
                {
                    valuesForSlices[listCnt] = gd.Value3;
                    combinedLabel.Append(gd.Value1);
                    //  calculate percentage
                    combinedLabel.Append(" ");
                    convertedNumber = Utilities.FormatField(gd.Value3, "{0,4:F1}").ToString();
                    combinedLabel.Append(convertedNumber);
                    labelsForSlices[listCnt] = combinedLabel.ToString();

                    listCnt++;
                    combinedLabel.Remove(0, combinedLabel.Length);
                }       //  end foreach loop
                valuesTotal = totalValue;
                totalLabel  = "TOTAL BAF PER ACRE ";
                totalLabel += Utilities.FormatField(valuesTotal, "{0,10:F0}").ToString();
                break;
            }   //  end switch

            PieItem[] pieSlices = currPane.AddPieSlices(valuesForSlices, labelsForSlices);
            foreach (PieItem p in pieSlices)
            {
                p.LabelDetail.FontSpec.Size = 18f;
            }

            //  Make a text label to highlight the total value
            TextObj text = new TextObj(totalLabel, 0.10F, 0.18F, CoordType.ChartFraction);

            text.Location.AlignH           = AlignH.Center;
            text.Location.AlignV           = AlignV.Bottom;
            text.FontSpec.Size             = 10f;
            text.FontSpec.Border.IsVisible = false;
            text.FontSpec.Fill             = new Fill(Color.White, Color.FromArgb(0, 255, 64), 45F);
            text.FontSpec.StringAlignment  = StringAlignment.Center;
            currPane.GraphObjList.Add(text);

            //  Create a drop shadow for the total value text item
            TextObj text2 = new TextObj(text);

            text2.FontSpec.Fill = new Fill(Color.Black);
            text2.Location.X   += 0.008f;
            text2.Location.Y   += 0.01f;
            currPane.GraphObjList.Add(text2);

            //  Calculate the axis scale ranges
            zgc.AxisChange();


            //  save graphs
            Size   newSize    = new Size(337, 320);
            Bitmap currBMP    = new Bitmap(currPane.GetImage(), newSize);
            string outputFile = System.IO.Path.GetDirectoryName(fileName);

            outputFile += "\\Graphs\\";
            outputFile += currSaleName;
            System.IO.Directory.CreateDirectory(outputFile);
            outputFile += "\\";
            //  add graph report to file name
            switch (graphNum)
            {
            case 2:
                outputFile += "GR02";
                break;

            case 3:
                outputFile += "GR03";
                break;

            case 4:
                outputFile += "GR04";
                break;

            case 10:
                outputFile += "GR10";
                break;
            }   //  end switch
            outputFile += "_";
            outputFile += currSP;
            outputFile += ".jpg";
            currBMP.Save(@outputFile, System.Drawing.Imaging.ImageFormat.Jpeg);

            return;
        }   //  end CreatePieGraph
コード例 #9
0
        private void CreateGraph_DataSource(ZedGraphControl z1)
        {
            GraphPane myPane = z1.GraphPane;

            // Set the titles
            myPane.Title.Text       = titulo;
            myPane.XAxis.Title.Text = xAxisSource;
            myPane.YAxis.Title.Text = yAxisSource;

            // Create a new DataSourcePointList to handle the database connection
            var dspl = new DataSourcePointList
            {
                DataSource  = data.Tables[0],
                XDataMember = xAxisSource,
                YDataMember = yAxisSource,
                ZDataMember = null
            };

            // Specify the table as the data source
            // The X data will come from the "OrderDate" column
            // The Y data will come from the "Freight" column
            // The Z data are not used

            if (tipoGrafico == TipoGrafico.Torta)
            {
                // dibujar torta
                var values = new List <double>();
                var labels = new List <string>();
                foreach (DataRow dr in data.Tables[0].Rows)
                {
                    if (dr[xAxisSource] != DBNull.Value)
                    {
                        values.Add(Convert.ToDouble(dr[xAxisSource]));
                    }
                    else
                    {
                        values.Add(0);
                    }
                    if (dr[yAxisSource] != DBNull.Value)
                    {
                        labels.Add(Convert.ToString(dr[yAxisSource]));
                    }
                    else
                    {
                        labels.Add(string.Empty);
                    }
                }
                myPane.AddPieSlices(values.ToArray(), labels.ToArray());
            }
            else
            {
                // formatear strings
                if (data.Tables[0].Columns[xAxisSource].DataType == typeof(string))
                {
                    myPane.XAxis.Scale.FontSpec.Angle = 90;
                    myPane.XAxis.Scale.FontSpec.Size  = myPane.XAxis.Scale.FontSpec.Size / 2;
                    // agregar datos como textlabels
                    var labels = new List <string>();
                    foreach (DataRow dr in data.Tables[0].Rows)
                    {
                        if (dr[xAxisSource] != DBNull.Value)
                        {
                            labels.Add((string)dr[xAxisSource]);
                        }
                        else
                        {
                            labels.Add("");
                        }
                    }
                    myPane.XAxis.Scale.TextLabels = labels.ToArray();
                    myPane.XAxis.Type             = AxisType.Text;
                }

                if (data.Tables[0].Columns[yAxisSource].DataType == typeof(string))
                {
                    myPane.YAxis.Scale.FontSpec.Size = myPane.YAxis.Scale.FontSpec.Size / 2;
                    // agregar datos como textlabels
                    var labels = new List <string>();
                    foreach (DataRow dr in data.Tables[0].Rows)
                    {
                        if (dr[yAxisSource] != DBNull.Value)
                        {
                            labels.Add((string)dr[yAxisSource]);
                        }
                        else
                        {
                            labels.Add("");
                        }
                    }
                    myPane.YAxis.Scale.TextLabels = labels.ToArray();
                    myPane.YAxis.Type             = AxisType.Text;
                }

                // formatear fechas
                if (data.Tables[0].Columns[xAxisSource].DataType == typeof(DateTime))
                {
                    myPane.XAxis.Type = AxisType.Date;
                }
                if (data.Tables[0].Columns[yAxisSource].DataType == typeof(DateTime))
                {
                    myPane.YAxis.Type = AxisType.Date;
                }

                switch (tipoGrafico)
                {
                case TipoGrafico.Puntos:
                    myPane.AddCurve(yAxisSource, dspl, Color.Blue).Line.IsVisible = false;
                    break;

                case TipoGrafico.Lineas:
                    myPane.AddCurve(yAxisSource, dspl, Color.Blue);
                    break;

                case TipoGrafico.Barras:
                    myPane.AddBar(yAxisSource, dspl, Color.Blue);
                    break;

                default:
                    break;
                }
                myPane.Chart.Fill = new Fill(Color.White, Color.LightGoldenrodYellow, 45.0f);
                myPane.XAxis.MajorGrid.IsVisible = true;
                myPane.YAxis.MajorGrid.IsVisible = true;
            }

            // Auto set the scale ranges
            z1.AxisChange();
        }
コード例 #10
0
        public PieChartDemo() : base("A demo showing some pie chart features of ZedGraph",
                                     "Pie Chart Demo", DemoType.Pie)
        {
            GraphPane myPane = base.GraphPane;

            // Set the pane title
            myPane.Title.Text = "2004 ZedGraph Sales by Region\n ($M)";

            // Enter some data values
            double [] values       = { 15, 15, 40, 20 };
            double [] values2      = { 250, 50, 400, 50 };
            Color []  colors       = { Color.Red, Color.Blue, Color.Green, Color.Yellow };
            double [] displacement = { .0, .0, .0, .0 };
            string [] labels       = { "Europe", "Pac Rim", "South America", "Africa" };

            // Fill the pane and axis background with solid color
            myPane.Fill            = new Fill(Color.Cornsilk);
            myPane.Chart.Fill      = new Fill(Color.Cornsilk);
            myPane.Legend.Position = LegendPos.Right;

            // Create some pie slices
            PieItem segment1 = myPane.AddPieSlice(20, Color.Navy, .20, "North");
            PieItem segment2 = myPane.AddPieSlice(40, Color.Salmon, 0, "South");
            PieItem segment3 = myPane.AddPieSlice(30, Color.Yellow, .0, "East");
            PieItem segment4 = myPane.AddPieSlice(10.21, Color.LimeGreen, 0, "West");
            PieItem segment5 = myPane.AddPieSlice(10.5, Color.Aquamarine, .3, "Canada");

            // Add some more slices as an array
            PieItem [] slices = new PieItem[values2.Length];
            slices = myPane.AddPieSlices(values2, labels);

            // Modify the slice label types
            ((PieItem)slices[0]).LabelType    = PieLabelType.Name_Value;
            ((PieItem)slices[1]).LabelType    = PieLabelType.Name_Value_Percent;
            ((PieItem)slices[2]).LabelType    = PieLabelType.Name_Value;
            ((PieItem)slices[3]).LabelType    = PieLabelType.Name_Value;
            ((PieItem)slices[1]).Displacement = .2;
            segment1.LabelType = PieLabelType.Name_Percent;
            segment2.LabelType = PieLabelType.Name_Value;
            segment3.LabelType = PieLabelType.Percent;
            segment4.LabelType = PieLabelType.Value;
            segment5.LabelType = PieLabelType.Name_Value;
            segment2.LabelDetail.FontSpec.FontColor = Color.Red;

            // Sum up the values
            CurveList curves = myPane.CurveList;
            double    total  = 0;

            for (int x = 0; x < curves.Count; x++)
            {
                total += ((PieItem)curves[x]).Value;
            }

            // Add a text item to highlight total sales
            TextObj text = new TextObj("Total 2004 Sales - " + "$" + total.ToString() + "M", 0.85F, 0.80F, CoordType.PaneFraction);

            text.Location.AlignH           = AlignH.Center;
            text.Location.AlignV           = AlignV.Bottom;
            text.FontSpec.Border.IsVisible = false;
            text.FontSpec.Fill             = new Fill(Color.White, Color.PowderBlue, 45F);
            text.FontSpec.StringAlignment  = StringAlignment.Center;
            myPane.GraphObjList.Add(text);

            // Add a colored background behind the pie
            BoxObj box = new BoxObj(0, 0, 1, 1, Color.Empty, Color.PeachPuff);

            box.Location.CoordinateFrame = CoordType.ChartFraction;
            box.Border.IsVisible         = false;
            box.Location.AlignH          = AlignH.Left;
            box.Location.AlignV          = AlignV.Top;
            box.ZOrder = ZOrder.E_BehindCurves;
            myPane.GraphObjList.Add(box);

            base.ZedGraphControl.AxisChange();
        }
コード例 #11
0
ファイル: MainForm.cs プロジェクト: bmahaj2/Projects
        private async void populateControls(ZedGraphControl zgc)
        {
            /////////////Show the gridView control with verious columns////////////////////
            Double totalInvestment = 0.0;
            Double totalReturn     = 0.0;

            this.mainFormLoadingCircle.Visible = true;
            dt = await Task.Run(() => bLogic.getUserPurchaseTable(loggedUser.userName));

            if (dt.Rows.Count > 0)
            {
                dt.Columns.Add("Total Return", typeof(System.Double));
                dt.Columns.Add("Current Bid", typeof(System.Double));
                dt.Columns.Add("Current Ask", typeof(System.Double));
                List <Quote> quotes = new List <Quote>();

                foreach (DataRow dr in dt.Rows)
                {
                    quotes.Add(new Quote(dr["Symbol"].ToString()));
                }
                await Task.Run(() => YahooStockEngine.Fetch(quotes));

                int    i         = 0;
                double currPrice = 0.0;
                foreach (DataRow dr in dt.Rows)
                {
                    if (quotes != null && quotes[i] != null && quotes[i].Bid != null)
                    {
                        currPrice         = (double)quotes[i].Bid;
                        currPrice        *= System.Convert.ToDouble(dr["Total Stocks"].ToString());
                        dr["Current Bid"] = (double)quotes[i].Bid;
                    }
                    else
                    {
                        currPrice         = System.Convert.ToDouble(dr["Total Investment"]);
                        dr["Current Bid"] = 0.0;
                    }
                    if (quotes != null && quotes[i] != null && quotes[i].Ask != null)
                    {
                        dr["Current Ask"] = (double)quotes[i].Ask;
                    }
                    else
                    {
                        currPrice         = System.Convert.ToDouble(dr["Total Investment"]);
                        dr["Current Ask"] = 0.0;
                    }
                    totalReturn       += currPrice;
                    totalInvestment   += System.Convert.ToDouble(dr["Total Investment"]);
                    dr["Total Return"] = currPrice; //.ToString (String.Format("#.##"));
                    i++;
                }
                this.cashTextBox.Text   = loggedUser.balance.ToString(String.Format("c"));
                this.returnTextBox.Text = totalReturn.ToString(String.Format("c"));
                this.investTextBox.Text = totalInvestment.ToString(String.Format("c"));
                double profitLoss = (totalReturn - totalInvestment);
                this.profitTextBox.Text           = profitLoss.ToString();
                this.stockDataGridView.DataSource = dt;
                this.stockDataGridView.Columns["Total Return"].DefaultCellStyle.Format     = "c";
                this.stockDataGridView.Columns["Current Bid"].DefaultCellStyle.Format      = "c";
                this.stockDataGridView.Columns["Current Ask"].DefaultCellStyle.Format      = "c";
                this.stockDataGridView.Columns["Total Investment"].DefaultCellStyle.Format = "c";
                this.stockDataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            } // end of  if (dt.Rows.Count > 0)
            else
            {
                this.cashTextBox.Text   = loggedUser.balance.ToString(String.Format("c"));
                this.returnTextBox.Text = totalReturn.ToString(String.Format("c"));
                this.investTextBox.Text = totalInvestment.ToString(String.Format("c"));
                double profitLoss = (totalReturn - totalInvestment);
                this.profitTextBox.Text           = profitLoss.ToString();
                this.stockDataGridView.DataSource = null;
            }
            /////////////Show the graph control with current selected row from the gridView////////////////////

            populateGraphControl();

            /////////////Show the Pie Chart control with all the stocks////////////////////

            zgc.GraphPane.CurveList.Clear();
            zgc.GraphPane.GraphObjList.Clear();
            GraphPane myPane = zgc.GraphPane;

            // Set the Titles
            myPane.Title.Text = "Total assets distribution for " + loggedUser.firstName + " " + loggedUser.lastName;
            double[] totReturn = new double[dt.Rows.Count];
            String[] companies = new String[dt.Rows.Count];
            int      j         = 0;

            foreach (DataRow dr in dt.Rows)
            {
                totReturn[j] = System.Convert.ToDouble(dr["Total Return"].ToString());
                companies[j] = dr["Name"].ToString();
                j++;
            }
            myPane.AddPieSlices(totReturn, companies);
            // Fill the axis background with a gradient
            myPane.Chart.Fill = new Fill(Color.LightGreen, Color.DeepSkyBlue, 45.0f);
            myPane.Fill       = new Fill(Color.LightGreen);
            //myPane.Legend.Position = LegendPos.Bottom;
            myPane.Legend.IsVisible = false;
            foreach (var x in myPane.CurveList.OfType <PieItem>())
            {
                x.LabelType    = PieLabelType.Name_Percent;
                x.Displacement = x.Value % 0.07;
            }
            zgc.IsShowPointValues = true;
            zgc.AxisChange();
            zgc.Invalidate();
            this.mainFormLoadingCircle.Visible = false;
            return;
        }