Esempio n. 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            configurarColores(Titulo);
            
            chart = new ColumnChart();
            chart.Fill.Color = Color.FromArgb(50, Color.SteelBlue);
            chart.Line.Color = Color.SteelBlue;
            chart.Line.Width = 4;
            chart.Legend = Leyenda;

            chart.DataBind();
        }
        private void cargarEjemplo()
        {
            ColumnChart chart = new ColumnChart();
            chart.Fill.Color = Color.FromArgb(50, Color.SteelBlue);
            chart.Line.Color = Color.SteelBlue;
            chart.Line.Width = 4;

            chart.Legend = "Compras por mes";
            chart.Data.Add(new ChartPoint("Ene", 10));
            chart.Data.Add(new ChartPoint("Feb", 20));
            chart.Data.Add(new ChartPoint("Mar", 14));
            chart.Data.Add(new ChartPoint("Abr", 30));
            chart.Data.Add(new ChartPoint("May", 18));
            chart.Data.Add(new ChartPoint("Jun", 7));
            chart.Data.Add(new ChartPoint("Jul", 8));
            chart.Data.Add(new ChartPoint("Ago", 18));
            chart.Data.Add(new ChartPoint("Sep", 24));
            chart.Data.Add(new ChartPoint("Oct", 30));
            chart.Data.Add(new ChartPoint("Nov", 17));
            chart.Data.Add(new ChartPoint("Dic", 5));
        }
Esempio n. 3
0
    private void LoadExcel2()
    {
        DataTable  dt = new DataTable("Chart");
        DataColumn dc = new DataColumn("Website", typeof(string));

        //DataColumn dc1 = new DataColumn("Validation", typeof(string));
        dt.Columns.Add(dc);
        //dt.Columns.Add(dc1);
        //DataRow dr = dt.NewRow();

        Excel.Application xlApp       = null;
        Excel.Workbook    xlWorkBook  = null;
        Excel.Worksheet   xlWorkSheet = null;
        Excel.Range       range       = null;
        //Excel.Sheets sheets;

        //string str1, str2;
        //int rCnt = 0;
        //int cCnt = 0;
        //System.Array[] myvalues;
        //string[] strArray;
        object obj;

        try
        {
            xlApp      = new Excel.Application();
            xlWorkBook = xlApp.Workbooks.Open(path1, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
            //xlWorkSheet = (Excel.Worksheet)xlWorkBook.ActiveSheet;
            //sheets = xlWorkBook.Worksheets;
            //xlWorkSheet = (Excel.Worksheet)sheets.get_Item(1);
            //xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(2);
            xlWorkSheet = (Excel.Worksheet)xlWorkBook.ActiveSheet;
            //str1 = xlWorkBook.Name;
            //str2 = xlWorkSheet.Name;

            int firstRow = 15;
            int lastRow  = 1331;
            for (int i = firstRow; i <= lastRow; i++)
            {
                range = xlWorkSheet.get_Range("A" + i.ToString(), "Z" + i.ToString());
                obj   = range.Cells.Value;
                System.Array myvalues = (System.Array)obj;

                //myvalues = (System.Array)range.Cells.Value;
                //strArray = ConvertToStringArray(myvalues);
                //string str = strArray[1];
                DataRow dr1 = dt.NewRow();
                string  str = myvalues.GetValue(1, 2).ToString();
                dr1[0] = str;
                dt.Rows.Add(dr1);
            }


            var result = dt.AsEnumerable()
                         .GroupBy(r => r.Field <string>("Website"), StringComparer.InvariantCultureIgnoreCase)
                         .Select(r => new
            {
                Str   = r.Key,
                Count = r.Count()
            });

            //LineChart chart = new LineChart();//Class instance for LineChart
            //SmoothLineChart chart = new SmoothLineChart();//Class instance for LineChart
            //AreaChart chart = new AreaChart();//Class instance for LineChart
            ColumnChart chart = new ColumnChart();
            //ScatterChart chart = new ScatterChart();
            //StackedColumnChart chart = new StackedColumnChart();

            chart.Fill.Color         = Color.FromArgb(50, Color.SteelBlue);
            chart.Fill.Type          = InteriorType.Hatch;
            chart.Fill.HatchStyle    = System.Drawing.Drawing2D.HatchStyle.DottedDiamond;
            chart.Fill.ForeColor     = Color.DarkBlue;
            chart.Line.Width         = 1;
            chart.Line.Color         = Color.SteelBlue;
            chart.ShowLineMarkers    = true;
            chart.DataLabels.Visible = true;
            //chart.DataLabels.ShowValue = true;
            //chart.DataLabels.ShowXTitle = true;
            //chart.DataXValueField = "Websites"; ;
            //chart.DataYValueField = "Validations";
            //chart.Legend = "X Axis: Websites \nY Axis: Validations";
            //chart.ShowLegend = true;

            //looping through datatable and adding to chart control

            foreach (var item in result)
            {
                string str = item.Str;
                int    i   = item.Count;
                chart.Data.Add(new ChartPoint(str, (float)System.Convert.ToSingle(i)));
                //Console.WriteLine($"{item.Str} : {item.Count}");
            }

            //chart.DataLabels.ForeColor = Color.White;
            //chart.DataLabels.NumberFormat = "$0.00";
            //chart.DataLabels.Position = DataLabelPosition.Center;
            //chart.DataLabels.Background.Color = Color.SteelBlue;
            //chart.DataLabels.Border.Color = Color.Red;
            //chart.DataLabels.Separator = " ";
            //chart.DataLabels.ShowLegend = true;
            //chart.DataLabels.MaxPointsWidth = 1;
            //chart.ShowLineMarkers = true;
            //chart.LineMarker = new XLineMarker(6, Color.Red, Color.Green);


            //foreach (DataRow dr2 in dt.Rows)
            //{
            //    string str = dr2["Website"].ToString();
            //    chart.Data.Add(new ChartPoint(dr2["Website"].ToString(), (float)System.Convert.ToSingle(dr2["Validation"])));
            //}
            //ChartEngine engine = new ChartEngine();
            //ChartCollection charts = new ChartCollection(engine);
            //engine.Charts = charts;
            //engine.TopChartPadding = 20;
            //charts.Add(chart);


            ConfigureColors();
            ChartControl1.Charts.Clear();
            ChartControl1.Charts.Add(chart);
            ChartControl1.RedrawChart();


            xlWorkBook.Close(false, Missing.Value, Missing.Value);
            xlApp.Quit();
        }
        catch (Exception e)
        {
            string str = e.Message;
        }
        finally
        {
            // Close the Excel process
            releaseObject(range);
            releaseObject(xlWorkSheet);
            releaseObject(xlWorkBook);
            releaseObject(xlApp);
        }
    }
Esempio n. 4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string[] s = new string[2] {
                "No data", "0"
            };
            if (Request.QueryString["data"] != null)
            {
                s = Request.QueryString["data"].Split('|');
            }
            ChartEngine wcEng = new ChartEngine();

            if (Request.QueryString["size"] != null)
            {
                string[] size = Request.QueryString["size"].Split('|');
                wcEng.Size = new Size(Convert.ToInt32(size[0]), Convert.ToInt32(size[1]));
            }
            else
            {
                wcEng.Size = new Size(400, 400);
            }

            ChartCollection wcCharts = new ChartCollection(wcEng);

            wcEng.Charts             = wcCharts;
            wcEng.RenderHorizontally = false;
            wcEng.Border.Color       = Color.FromArgb(99, Color.SteelBlue);
            wcEng.ShowXValues        = true;
            wcEng.ShowYValues        = true;
            wcEng.ChartPadding       = 30;
            wcEng.Padding            = 0;
            wcEng.TopPadding         = 0;

            ColumnChart chart = new ColumnChart();

            chart.Shadow.Visible       = false;
            chart.MaxColumnWidth       = Convert.ToInt32(wcEng.Size.Height / s.Length);
            chart.Fill.Color           = Color.FromArgb(90, Color.SteelBlue);
            chart.Line.Color           = Color.SteelBlue;
            chart.Line.Width           = 2;
            chart.DataLabels.Visible   = true;
            chart.DataLabels.ShowValue = true;

            for (int i = 0; i < s.Length; i++)
            {
                ChartPoint cp = new ChartPoint();
                cp.XValue = s[i];
                cp.YValue = Convert.ToInt32(s[i + 1]);
                chart.Data.Add(cp);
                i += 1;
            }
            wcCharts.Add(chart);

            MemoryStream memStream = new MemoryStream();
            Bitmap       bmp       = wcEng.GetBitmap();
            Graphics     g         = Graphics.FromImage(bmp);
            Pen          mypen     = new Pen(Color.Black, 1F);

            g.DrawRectangle(mypen, 0, 0, bmp.Width - 1, bmp.Height - 1);
            bmp.Save(memStream, ImageFormat.Png);
            memStream.WriteTo(Response.OutputStream);
            Response.ContentType = "image/png";
            Response.End();
        }
Esempio n. 5
0
    protected void LoadChart()
    {
        DataTable tblDivision = clsDivision.DSAll();

        foreach (DataRow drw in tblDivision.Rows)
        {
            ColumnChart ccValue  = new ColumnChart();
            Color       clrChart = Color.SkyBlue;
            switch (drw["divicode"].ToString())
            {
            case "ACDMCS":
                clrChart = Color.Green;
                break;

            case "AUDCOM":
                clrChart = Color.Gray;
                break;

            case "CISERV":
                clrChart = Color.Blue;
                break;

            case "CNLMGT":
                clrChart = Color.Yellow;
                break;

            case "COOEVP":
                clrChart = Color.Orange;
                break;

            case "FNANCE":
                clrChart = Color.Fuchsia;
                break;

            case "MKTING":
                clrChart = Color.Red;
                break;

            case "OOCOOP":
                clrChart = Color.SkyBlue;
                break;
            }
            ccValue.Shadow.Visible  = true;
            ccValue.MaxColumnWidth  = 15;
            ccValue.Fill.Color      = Color.FromArgb(90, clrChart);
            ccValue.Legend          = drw["division"].ToString();
            ccValue.DataSource      = clsTimesheet.DSCDTRSummary(drw["divicode"].ToString(), clsDateTime.GetDateOnly(dtpStart.Date), clsDateTime.GetDateOnly(dtpEnd.Date.AddDays(1))).DefaultView;
            ccValue.DataXValueField = "xvalue";
            ccValue.DataYValueField = "yvalue";
            ccValue.DataBind();
            chaDTRSummary.Charts.Add(ccValue);
        }
        chaDTRSummary.RedrawChart();


        //foreach (DataRow drw in tblDivision.Rows)
        //{
        // ColumnChart ccPercentage = new ColumnChart();
        // Color clrChart = Color.SkyBlue;
        // switch (drw["divicode"].ToString())
        // {
        //  case "ACDMCS":
        //   clrChart = Color.Green;
        //   break;
        //  case "AUDCOM":
        //   clrChart = Color.Gray;
        //   break;
        //  case "CISERV":
        //   clrChart = Color.Blue;
        //   break;
        //  case "CNLMGT":
        //   clrChart = Color.Yellow;
        //   break;
        //  case "COOEVP":
        //   clrChart = Color.Orange;
        //   break;
        //  case "FNANCE":
        //   clrChart = Color.Fuchsia;
        //   break;
        //  case "MKTING":
        //   clrChart = Color.Red;
        //   break;
        //  case "OOCOOP":
        //   clrChart = Color.SkyBlue;
        //   break;
        // }
        // ccPercentage.Shadow.Visible = true;
        // ccPercentage.MaxColumnWidth = 15;
        // ccPercentage.Fill.Color = Color.FromArgb(90, clrChart);
        // ccPercentage.Legend = drw["division"].ToString();
        // ccPercentage.DataSource = clsTimesheet.DSCDTRSummaryPercentage(drw["divicode"].ToString(), clsDateTime.GetDateOnly(dtpStart.Date), clsDateTime.GetDateOnly(dtpEnd.Date.AddDays(1))).DefaultView;
        // ccPercentage.DataXValueField = "xvalue";
        // ccPercentage.DataYValueField = "yvalue";
        // ccPercentage.DataBind();
        // chaDTRSummaryPercentage.Charts.Add(ccPercentage);
        //}

        //chaDTRSummary.RedrawChart();
    }
Esempio n. 6
0
    public override TransitPicture GetPictureWithBitmap(int id)
    {
        ChartEngine engine = new ChartEngine();

        engine.Size               = new Size(570, 300);
        engine.GridLines          = WebChart.GridLines.None;
        engine.ShowXValues        = true;
        engine.ShowYValues        = true;
        engine.LeftChartPadding   = 50;
        engine.BottomChartPadding = 50;
        engine.XAxisFont.StringFormat.LineAlignment = StringAlignment.Center;
        engine.XAxisFont.StringFormat.FormatFlags   = StringFormatFlags.DirectionVertical;
        engine.XAxisFont.ForeColor = engine.YAxisFont.ForeColor = Color.Black;

        ChartCollection charts = new ChartCollection(engine);

        engine.Charts = charts;

        List <List <TransitSummarizedCounter> > counters = new List <List <TransitSummarizedCounter> >();
        string format;
        string title = RequestType.ToString();

        switch (RequestType)
        {
        case ChartType.DailyNew:
            counters.Add(Summary.NewDaily);
            format = "MMM d";
            title  = "New Daily";
            break;

        case ChartType.DailyReturning:
            counters.Add(Summary.ReturningDaily);
            format = "MMM d";
            title  = "Returning Daily";
            break;

        case ChartType.Daily:
            counters.Add(Summary.Daily);
            format = "MMM d";
            break;

        case ChartType.Hourly:
            counters.Add(Summary.Hourly);
            format = "htt";
            break;

        case ChartType.MonthlyUnique:
            counters.Add(Summary.UniqueMonthly);
            format = "MMM";
            title  = "Monthly Unique";
            break;

        case ChartType.Monthly:
            counters.Add(Summary.Monthly);
            format = "MMM";
            break;

        case ChartType.Weekly:
            counters.Add(Summary.Weekly);
            format = "MMM dd";
            break;

        case ChartType.Yearly:
            counters.Add(Summary.Yearly);
            format = "yyyy";
            break;

        case ChartType.AccountDaily:
            counters.Add(Summary.AccountDaily);
            format = "MMM d";
            title  = "New Daily";
            break;

        case ChartType.AccountMonthly:
            counters.Add(Summary.AccountMonthly);
            format = "MMM";
            title  = "New Monthly";
            break;

        case ChartType.AccountWeekly:
            counters.Add(Summary.AccountWeekly);
            format = "MMM dd";
            title  = "New Weekly";
            break;

        case ChartType.AccountYearly:
            counters.Add(Summary.AccountYearly);
            format = "yyyy";
            title  = "New Yearly";
            break;

        default:
            throw new ArgumentOutOfRangeException("type");
        }

        long  total = 0;
        long  count = 0;
        Color fill  = Color.FromArgb(0x9F, 0x6, 0x15);

        foreach (List <TransitSummarizedCounter> clist in counters)
        {
            ColumnChart chart = new ColumnChart();
            chart.ShowLineMarkers         = false;
            chart.ShowLegend              = true;
            chart.Line.Color              = Color.White;
            chart.Line.Width              = 2;
            chart.Fill.Color              = engine.Border.Color = fill;
            chart.Fill.LinearGradientMode = System.Drawing.Drawing2D.LinearGradientMode.Vertical;
            chart.MaxColumnWidth          = 100;

            count += clist.Count;

            foreach (TransitSummarizedCounter counter in clist)
            {
                total += counter.Total;
                chart.Data.Add(new ChartPoint(counter.Timestamp.ToString(format), counter.Total));
            }

            charts.Add(chart);
            fill = Color.FromArgb(fill.R + 0x30, fill.G + 0x30, fill.B + 0x30);
        }

        engine.Title = new ChartText();
        double average = count > 0 ? total / count : 0;

        engine.Title.Text = string.Format("{0} (average: {1})", RequestType, average);

        TransitPicture picture = new TransitPicture();

        picture.Id       = 0;
        picture.Modified = picture.Created = DateTime.UtcNow;
        picture.Name     = RequestType.ToString();

        MemoryStream ds = new MemoryStream();

        engine.GetBitmap().Save(ds, System.Drawing.Imaging.ImageFormat.Png);
        picture.Bitmap = new byte[ds.Length];
        MemoryStream ms = new MemoryStream(picture.Bitmap);

        ds.WriteTo(ms);

        return(picture);
    }
Esempio n. 7
0
        private void setViewByData(int gid, double num)
        {
            double tar = 0;

            if (num > ColumnChart.Series[0].Points[gid].YValues[0])
            {
                tar = num - ColumnChart.Series[0].Points[gid].YValues[0];
                for (int i = 1; i <= tar; i++)
                {
                    ColumnChart.Invoke(new EventHandler(delegate {
                        ColumnChart.Series[0].Points[gid].YValues = new Double[] { ColumnChart.Series[0].Points[gid].YValues[0] + 1 };
                        int cur = (int)ColumnChart.Series[0].Points[gid].YValues[0];
                        if (cur >= 0 && cur < 10)
                        {
                            ColumnChart.Series[0].Points[gid].Color = Color.Green;
                        }
                        else if (cur >= 10 && cur < 50)
                        {
                            ColumnChart.Series[0].Points[gid].Color = Color.Blue;
                        }
                        else if (cur >= 50 && cur < 80)
                        {
                            ColumnChart.Series[0].Points[gid].Color = Color.Orange;
                        }
                        else if (cur >= 80 && cur < 100)
                        {
                            ColumnChart.Series[0].Points[gid].Color = Color.Red;
                        }
                        Thread.Sleep(10);
                        RefreshTheChart();
                    }));
                }
                if (num < ColumnChart.Series[0].Points[gid].YValues[0])
                {
                    tar = ColumnChart.Series[0].Points[gid].YValues[0] - num;
                    for (int i = 1; i <= tar; i++)
                    {
                        ColumnChart.Invoke(new EventHandler(delegate
                        {
                            ColumnChart.Series[0].Points[gid].YValues = new Double[] { ColumnChart.Series[0].Points[gid].YValues[0] - 1 };
                            int cur = (int)ColumnChart.Series[0].Points[gid].YValues[0];
                            if (cur >= 0 && cur < 10)
                            {
                                ColumnChart.Series[0].Points[gid].Color = Color.Green;
                            }
                            else if (cur >= 10 && cur < 50)
                            {
                                ColumnChart.Series[0].Points[gid].Color = Color.Blue;
                            }
                            else if (cur >= 50 && cur < 80)
                            {
                                ColumnChart.Series[0].Points[gid].Color = Color.Orange;
                            }
                            else if (cur >= 80 && cur < 100)
                            {
                                ColumnChart.Series[0].Points[gid].Color = Color.Red;
                            }
                        }));
                    }
                }
            }
        }
Esempio n. 8
0
    protected void Page_Load(object sender, EventArgs e)
    {
        clsSpeedo.Authenticate();
        clsCRS.CRSUserType cutUserLevel = clsCRS.GetUserLevel(Request.Cookies["Speedo"]["UserName"].ToString());

        if (!Page.IsPostBack)
        {
            if (cutUserLevel == clsCRS.CRSUserType.ChannelManager)
            {
                ddlSchools.DataSource     = clsSchool.GetSchoolCmDdlDataTable(Request.Cookies["Speedo"]["UserName"].ToString());
                ddlSchools.DataValueField = "pvalue";
                ddlSchools.DataTextField  = "ptext";
                ddlSchools.DataBind();
            }

            if (cutUserLevel == clsCRS.CRSUserType.EliteUsers)
            {
                int         intCtr = 0;
                ColumnChart ccCR;
                DataTable   tblCR = new DataTable();
                tblCR.Columns.Add("month", System.Type.GetType("System.String"));
                tblCR.Columns.Add("tcount", System.Type.GetType("System.Int32"));

                DataRow  rowCR;
                Color[]  clrColor  = new Color[] { Color.Yellow, Color.Purple, Color.DarkGreen, Color.Orange, Color.Red };
                string[] strLabel  = new string[] { "Completed", "Partial Process", "For Processing (Endorsed)", "For Endorsement", "Disapproved" };
                string[] strStatus = new string[] { "C", "P", "E", "F", "D" };
                //cmd.CommandText = "SELECT DATEPART(mm,datereq) AS pmonth,COUNT(crsecode) AS tcrscode FROM CM.CrsDetails INNER JOIN CM.Crs ON Cm.CrsDetails.crscode = CM.Crs.crscode WHERE DATEPART(mm,datereq) BETWEEN " + DateTime.Now.AddMonths(-2).Month + " AND " + DateTime.Now.Month + " AND DATEPART(yy,datereq) = '" + DateTime.Now.Year + "' GROUP BY DATEPART(mm,datereq) ORDER BY DATEPART(mm,datereq)";

                using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["Speedo"].ToString()))
                {
                    SqlCommand cmd = cn.CreateCommand();
                    cn.Open();
                    SqlDataReader dr;

                    for (intCtr = 0; intCtr < 5; intCtr++)
                    {
                        rowCR = tblCR.NewRow();
                        tblCR.Rows.Clear();

                        rowCR["month"]  = DateTime.Now.AddMonths(-2).ToString("MMMM");
                        cmd.CommandText = "SELECT COUNT(crsecode) AS tcrsecode FROM CM.CrsDetails WHERE crscode IN (SELECT crscode FROM CM.Crs WHERE DATEPART(mm,datereq) = " + DateTime.Now.AddMonths(-2).Month + " AND DATEPART(yy,datereq) = '" + DateTime.Now.Year + "') AND pstatus='" + strStatus[intCtr] + "'";
                        dr = cmd.ExecuteReader();
                        if (dr.Read())
                        {
                            rowCR["tcount"] = dr["tcrsecode"].ToString();
                        }
                        else
                        {
                            rowCR["tcount"] = dr["tcrsecode"].ToString();
                        }
                        dr.Close();
                        tblCR.Rows.Add(rowCR);

                        rowCR           = tblCR.NewRow();
                        rowCR["month"]  = DateTime.Now.AddMonths(-1).ToString("MMMM");
                        cmd.CommandText = "SELECT COUNT(crsecode) AS tcrsecode FROM CM.CrsDetails WHERE crscode IN (SELECT crscode FROM CM.Crs WHERE DATEPART(mm,datereq) = " + DateTime.Now.AddMonths(-1).Month + " AND DATEPART(yy,datereq) = '" + DateTime.Now.Year + "') AND pstatus='" + strStatus[intCtr] + "'";
                        dr = cmd.ExecuteReader();
                        if (dr.Read())
                        {
                            rowCR["tcount"] = dr["tcrsecode"].ToString();
                        }
                        else
                        {
                            rowCR["tcount"] = dr["tcrsecode"].ToString();
                        }
                        dr.Close();
                        tblCR.Rows.Add(rowCR);

                        rowCR           = tblCR.NewRow();
                        rowCR["month"]  = DateTime.Now.ToString("MMMM");
                        cmd.CommandText = "SELECT COUNT(crsecode) AS tcrsecode FROM CM.CrsDetails WHERE crscode IN (SELECT crscode FROM CM.Crs WHERE DATEPART(mm,datereq) = " + DateTime.Now.Month + " AND DATEPART(yy,datereq) = '" + DateTime.Now.Year + "') AND pstatus='" + strStatus[intCtr] + "'";
                        dr = cmd.ExecuteReader();
                        if (dr.Read())
                        {
                            rowCR["tcount"] = dr["tcrsecode"].ToString();
                        }
                        else
                        {
                            rowCR["tcount"] = dr["tcrsecode"].ToString();
                        }
                        dr.Close();
                        tblCR.Rows.Add(rowCR);

                        ccCR = new ColumnChart();
                        ccCR.Shadow.Visible              = true;
                        ccCR.MaxColumnWidth              = 15;
                        ccCR.Fill.Color                  = System.Drawing.Color.FromArgb(90, clrColor[intCtr]);
                        ccCR.DataLabels.Visible          = true;
                        ccCR.DataLabels.Background.Color = System.Drawing.Color.White;
                        ccCR.Legend          = strLabel[intCtr];
                        ccCR.DataSource      = tblCR.DefaultView;
                        ccCR.DataXValueField = "month";
                        ccCR.DataYValueField = "tcount";
                        ccCR.DataBind();

                        chaCRSSummary.Charts.Add(ccCR);
                    }
                }

                chaCRSSummary.ChartTitle.Text = "Courseware Request Summary";
                chaCRSSummary.RedrawChart();
            }
        }


        if (cutUserLevel == clsCRS.CRSUserType.ChannelManager)
        {
            lblE.Text = "0";
            lblP.Text = "0";
            using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["Speedo"].ToString()))
            {
                SqlCommand cmd = cn.CreateCommand();
                cmd.CommandText = "SELECT COUNT(crsecode) AS te FROM CM.Crs INNER JOIN CM.CrsDetails ON CM.Crs.crscode = CM.CrsDetails.crscode WHERE cmname='" + Request.Cookies["Speedo"]["UserName"] + "' AND CM.CrsDetails.pstatus='F'";
                cn.Open();
                SqlDataReader dr = cmd.ExecuteReader();
                if (dr.Read())
                {
                    if (!Convert.IsDBNull(dr["te"].ToString()))
                    {
                        lblE.Text = dr["te"].ToString();
                    }
                }
                dr.Close();

                cmd.CommandText = "SELECT COUNT(crsecode) AS tp FROM CM.Crs INNER JOIN CM.CrsDetails ON CM.Crs.crscode = CM.CrsDetails.crscode WHERE cmname='" + Request.Cookies["Speedo"]["UserName"] + "' AND CM.CrsDetails.pstatus='P'";
                dr = cmd.ExecuteReader();
                if (dr.Read())
                {
                    if (!Convert.IsDBNull(dr["tp"].ToString()))
                    {
                        lblP.Text = dr["tp"].ToString();
                    }
                }
                dr.Close();
            }
        }
    }
        /// <summary>
        /// Shows column chart in separate window
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ColumnChartButton_OnClick(object sender, RoutedEventArgs e)
        {
            try
            {
                ChartBy chartBy = this.ByRows.IsChecked == true ? ChartBy.Rows : ChartBy.Cols;
                Dictionary<string, double> chartData = this.GetChartDataOfSelectedCells(chartBy);

                ColumnChart window = new ColumnChart();
                window.SetDataSumValuesList(chartData, chartBy);
                window.Show();

                Logger.WriteLogInfo(string.Format("Successfully drawed Column chart by {0} of selected cells",
                                                  (chartBy == ChartBy.Rows ? "rows" : "columns")));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.GetType().Name + ": " + ex.Message, "Error occured during drawing graph", MessageBoxButton.OK, MessageBoxImage.Error);
                Logger.WriteLogException(ex.GetType().Name + ": " + ex.Message);
            }
        }
    protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e)
    {
        // Label2.Text = "RATING GIVEN TO '" + DropDownList3.SelectedItem.ToString() + "' FOR '" + DropDownList2.SelectedItem.ToString() + "' = " + DropDownList2.SelectedValue.ToString();

        Label1.Text = DropDownList3.SelectedItem.ToString();
        SqlConnection connection = new SqlConnection("Data Source=universitycollege.database.windows.net;Initial Catalog=feedback;User ID=khalid;Password=99%isnotenough");

        connection.Open();

        string         query   = "select subject, avgtotal from suballoc where facultycode='" + DropDownList3.SelectedValue.ToString().TrimEnd() + "';";
        SqlDataAdapter adapter = new SqlDataAdapter(query, connection);
        DataSet        dataSet = new DataSet();


        adapter.Fill(dataSet);

        if (dataSet != null)
        {
            Chart chart = new ColumnChart();

            chart.Line.Color = Color.CornflowerBlue;

            chart.DataSource = dataSet.Tables[0].DefaultView;

            chart.DataXValueField = "subject";
            chart.DataYValueField = "avgtotal";
            chart.DataBind();

            chart.Fill.Color = Color.CornflowerBlue;


            Chart chart1 = new ColumnChart();
            chart1.Line.Color = Color.Blue;

            chart1.Data.Add(new ChartPoint("", 0));
            chart1.Data.Add(new ChartPoint("", 0));
            chart1.Data.Add(new ChartPoint("", 0));
            chart1.Data.Add(new ChartPoint("", 0));
            chart1.Data.Add(new ChartPoint("", 0));
            chart1.Data.Add(new ChartPoint("", 0));
            chart1.Data.Add(new ChartPoint("", 0));
            chart1.Data.Add(new ChartPoint("", 0));
            chart1.Data.Add(new ChartPoint("", 0));
            chart1.Data.Add(new ChartPoint("", 0));


            chart.DataLabels.Visible = true;

            ChartControl2.Charts.Add(chart1);
            ChartControl2.Charts.Add(chart);
            ChartControl2.RedrawChart();
            ChartControl2.Visible = true;

            Grid1.DataSource = chart.Data;
            Grid1.DataBind();



            //MapColumnChart cl = new MapColumnChart();
            //cl.Legend = "User A";
            //cl.Fill.Color = Color.Blue;

            //ChartPointCollection data2 = cl.Data;
            //data2.Add(new ChartPoint("", 0));
            //data2.Add(new ChartPoint(st, ft1));
            ////data2.Add(new ChartPoint("Mar", 60));
            ////data2.Add(new ChartPoint("Apr", 40));
            ////data2.Add(new ChartPoint("May", 30));
            ////data2.Add(new ChartPoint("Jun", 10));
            ////data2.Add(new ChartPoint("Jul", 30));
            ////data2.Add(new ChartPoint("Aug", 20));
            ////data2.Add(new ChartPoint("Sep", 60));
            ////data2.Add(new ChartPoint("Oct", 40));
            ////data2.Add(new ChartPoint("Nov", 20));
            ////data2.Add(new ChartPoint("Dec", 30));

            //cl.Rects = new System.Collections.ArrayList();
            //ChartControl1.Charts.Add(cl);

            //MapColumnChart c2 = new MapColumnChart();
            //c2.Legend = "User B";
            //c2.Fill.Color = Color.DarkBlue;

            //data2 = c2.Data;
            //data2.Add(new ChartPoint("", 0));
            //data2.Add(new ChartPoint("", 0));
            //data2.Add(new ChartPoint("", 0));
            //data2.Add(new ChartPoint("", 0));
            //data2.Add(new ChartPoint("", 0));
            //data2.Add(new ChartPoint("", 0));
            //data2.Add(new ChartPoint("", 0));
            //data2.Add(new ChartPoint("", 0));
            ////data2.Add(new ChartPoint("", 0));
            ////data2.Add(new ChartPoint("", 0));
            ////data2.Add(new ChartPoint("", 0));
            ////data2.Add(new ChartPoint("", 0));

            //c2.Rects = cl.Rects;
            //ChartControl1.Charts.Add(c2);

            //ChartControl1.RedrawChart();
            //ChartControl1.YCustomEnd = 6;
            //ChartControl1.Visible = true;
        }
        connection.Close();
    }
        private void UpdateTemplate()
        {
            var stackPanel = new StackPanel {
                Orientation = Orientation.Vertical
            };

            Content = stackPanel;

            var titleText = new TextBlock
            {
                Style        = _pageSubHeaderTextStyle,
                TextWrapping = TextWrapping.Wrap,
            };

            stackPanel.Children.Add(titleText);
            var hasTitle = PopupInfo != null && PopupInfo.Title != null && PopupInfo.Title.Trim().Length > 0;

            if (hasTitle)
            {
                titleText.SetBinding(InlineCollectionProperty, new Binding
                {
                    Path               = new PropertyPath("Attributes"),
                    Source             = this,
                    Converter          = new StringFormatToInlineCollectionConverter(),
                    ConverterParameter = PopupInfo.Title
                });
            }
            if (PopupInfo != null && PopupInfo.Description != null && PopupInfo.Description.Trim().Length > 0)
            {
                if (!hasTitle)
                {
                    hasTitle = true;
                    titleText.SetBinding(InlineCollectionProperty, new Binding
                    {
                        Path               = new PropertyPath("Attributes"),
                        Source             = this,
                        Converter          = new StringFormatToInlineCollectionConverter(),
                        ConverterParameter = PopupInfo.Description
                    });
                }
                var desc = new RichTextBlock
                {
                    FontSize   = _controlContentThemeFontSize,
                    FontFamily = _contentControlThemeFontFamily
                };
                stackPanel.Children.Add(desc);

                var p = new Paragraph();
                desc.Blocks.Add(p);

                BindingOperations.SetBinding(p, HtmlToTextConverter.HtmlToInlinesProperty, new Binding
                {
                    Path               = new PropertyPath("Attributes"),
                    Source             = this,
                    Converter          = new HtmlToTextConverter(),
                    ConverterParameter = PopupInfo.Description
                });
            }
            else //Show attribute list
            {
                List <FieldInfo> displayFields = null;
                if (PopupInfo != null && PopupInfo.FieldInfos != null)
                {
                    displayFields = new List <FieldInfo>(PopupInfo.FieldInfos.Where(a => a.IsVisible));
                }
                if (displayFields == null)
                {
                    return;
                }
                var attributes = Attributes as IDictionary <string, object>;
                foreach (var item in displayFields)
                {
                    var sp = new StackPanel();
                    stackPanel.Children.Add(sp);
                    var l = new TextBlock
                    {
                        Style        = _baselineTextStyle,
                        Margin       = new Thickness(0, 10, 0, 0),
                        Text         = item.Label ?? item.FieldName,
                        Foreground   = new SolidColorBrush(Colors.DarkGray),
                        TextWrapping = TextWrapping.Wrap,
                        TextTrimming = TextTrimming.WordEllipsis
                    };
                    sp.Children.Add(l);
                    if (!hasTitle)
                    {
                        hasTitle = true;
                        titleText.SetBinding(InlineCollectionProperty, new Binding
                        {
                            Path   = new PropertyPath(string.Format("Attributes[{0}]", item.FieldName)),
                            Source = this
                        });
                    }
                    var useHyperlink = attributes != null && attributes.ContainsKey(item.FieldName) &&
                                       attributes[item.FieldName] is string && ((string)attributes[item.FieldName]).StartsWith("http");
                    if (useHyperlink || string.Equals("url", item.FieldName, StringComparison.OrdinalIgnoreCase))
                    {
                        var hyperlink = new HyperlinkButton();
                        sp.Children.Add(hyperlink);
                        hyperlink.SetBinding(HyperlinkButton.NavigateUriProperty,
                                             new Binding
                        {
                            Path   = new PropertyPath(string.Format("Attributes[{0}]", item.FieldName)),
                            Source = this
                        });
                        hyperlink.SetBinding(ContentProperty,
                                             new Binding
                        {
                            Path   = new PropertyPath(string.Format("Attributes[{0}]", item.FieldName)),
                            Source = this
                        });
                        hyperlink.Template = (ControlTemplate)XamlReader.Load(
                            "<ControlTemplate TargetType='HyperlinkButton' xmlns='http://schemas.microsoft.com/client/2007' >" +
                            "<TextBlock Text='{TemplateBinding Content}' Padding='0' Margin='0' RenderTransformOrigin='0.5,0.5' TextWrapping='Wrap' TextTrimming ='WordEllipsis'>" +
                            "<TextBlock.RenderTransform>" +
                            "<CompositeTransform TranslateY='5' />" +
                            "</TextBlock.RenderTransform>" +
                            "</TextBlock>" +
                            "</ControlTemplate>");
                        hyperlink.FontFamily = new FontFamily("Segoe UI Light");
                        hyperlink.FontWeight = FontWeights.Normal;
                        hyperlink.Margin     = new Thickness(0);
                        hyperlink.Padding    = new Thickness(0);
                    }
                    else
                    {
                        var t = new TextBlock
                        {
                            Style        = _baselineTextStyle,
                            Margin       = new Thickness(0, 10, 0, 0),
                            TextWrapping = TextWrapping.Wrap,
                            TextTrimming = TextTrimming.WordEllipsis
                        };
                        sp.Children.Add(t);
                        t.SetBinding(TextBlock.TextProperty, new Binding
                        {
                            Path   = new PropertyPath(string.Format("Attributes[{0}]", item.FieldName)),
                            Source = this
                        });
                    }
                }
            }
            if (PopupInfo != null && PopupInfo.MediaInfos != null)
            {
                foreach (var item in PopupInfo.MediaInfos)
                {
                    if (!string.IsNullOrEmpty(item.Title))
                    {
                        var mediaTitle = new TextBlock
                        {
                            Style        = _baselineTextStyle,
                            Margin       = new Thickness(0, 10, 0, 0),
                            FontWeight   = FontWeights.Bold,
                            TextWrapping = TextWrapping.Wrap,
                            TextTrimming = TextTrimming.WordEllipsis
                        };
                        stackPanel.Children.Add(mediaTitle);
                        if (!hasTitle)
                        {
                            hasTitle = true;
                            titleText.SetBinding(InlineCollectionProperty, new Binding
                            {
                                Path               = new PropertyPath("Attributes"),
                                Source             = this,
                                Converter          = new StringFormatToInlineCollectionConverter(),
                                ConverterParameter = item.Title
                            });
                        }
                        mediaTitle.SetBinding(TextBlock.TextProperty, new Binding
                        {
                            Path               = new PropertyPath("Attributes"),
                            Source             = this,
                            Converter          = new StringFormatToStringConverter(),
                            ConverterParameter = item.Title
                        });
                    }
                    if (!string.IsNullOrEmpty(item.Caption))
                    {
                        var mediaCaption = new TextBlock
                        {
                            Style        = _baselineTextStyle,
                            Margin       = new Thickness(0, 10, 0, 0),
                            FontStyle    = FontStyle.Italic,
                            TextWrapping = TextWrapping.Wrap,
                            TextTrimming = TextTrimming.WordEllipsis
                        };
                        stackPanel.Children.Add(mediaCaption);
                        if (!hasTitle)
                        {
                            hasTitle = true;
                            titleText.SetBinding(InlineCollectionProperty, new Binding
                            {
                                Path               = new PropertyPath("Attributes"),
                                Source             = this,
                                Converter          = new StringFormatToInlineCollectionConverter(),
                                ConverterParameter = item.Caption
                            });
                        }
                        mediaCaption.SetBinding(TextBlock.TextProperty, new Binding
                        {
                            Path               = new PropertyPath("Attributes"),
                            Source             = this,
                            Converter          = new StringFormatToStringConverter(),
                            ConverterParameter = item.Caption
                        });
                    }

                    IEnumerable <KeyValuePair <string, string> > fieldMappings = null;
                    if (PopupInfo != null && PopupInfo.FieldInfos != null)
                    {
                        fieldMappings = from f in PopupInfo.FieldInfos
                                        select(new KeyValuePair <string, string>(f.FieldName, f.Label ?? f.FieldName));
                    }
                    BaseChart chart = null;
                    switch (item.Type)
                    {
                    case MediaType.Image:
                        var imageGrid = new Grid();
                        stackPanel.Children.Add(imageGrid);
                        if (!string.IsNullOrEmpty(item.Value.SourceUrl))
                        {
                            var image = new Image
                            {
                                Margin  = new Thickness(0, 10, 0, 0),
                                Width   = 200d,
                                Height  = 200d,
                                Stretch = Stretch.UniformToFill
                            };
                            imageGrid.Children.Add(image);
                            image.SetBinding(Image.SourceProperty, new Binding
                            {
                                Path               = new PropertyPath("Attributes"),
                                Source             = this,
                                Converter          = new StringFormatToBitmapSourceConverter(),
                                ConverterParameter = item.Value.SourceUrl
                            });
                        }
                        if (!string.IsNullOrEmpty(item.Value.LinkUrl))
                        {
                            var hyperlinkButton = new HyperlinkButton
                            {
                                Margin = new Thickness(0, 10, 0, 0),
                                Width  = 200d,
                                Height = 200d
                            };
                            imageGrid.Children.Add(hyperlinkButton);
                            hyperlinkButton.SetBinding(HyperlinkButton.NavigateUriProperty, new Binding
                            {
                                Path               = new PropertyPath("Attributes"),
                                Source             = this,
                                Converter          = new StringFormatToUriConverter(),
                                ConverterParameter = item.Value.LinkUrl
                            });
                        }
                        break;

                    case MediaType.BarChart:
                        chart = new BarChart();
                        break;

                    case MediaType.ColumnChart:
                        chart = new ColumnChart();
                        break;

                    case MediaType.LineChart:
                        chart = new LineChart();
                        break;

                    case MediaType.PieChart:
                        //string normalizeField = item.Value.NormalizeField;
                        chart = new PieChart();
                        break;
                    }
                    if (chart != null)
                    {
                        var fieldString    = string.Join(",", item.Value.Fields);
                        var normalizeField = item.Value.NormalizeField;
                        if (!string.IsNullOrEmpty(normalizeField) && !normalizeField.Equals("null"))
                        {
                            fieldString += BaseChart.NormalizeSeparator + normalizeField;
                        }
                        chart.Margin   = new Thickness(0, 10, 0, 0);
                        chart.Fields   = fieldString;
                        chart.Height   = 200;
                        chart.Width    = 200;
                        chart.FontSize = 10d;
                        var keyValuePairs = fieldMappings as KeyValuePair <string, string>[] ?? fieldMappings.ToArray();
                        if (keyValuePairs.Any())
                        {
                            chart.KeyToLabelDictionary = new ResourceDictionary();
                            foreach (var pair in keyValuePairs)
                            {
                                chart.KeyToLabelDictionary[pair.Key] = pair.Value;
                            }
                        }
                        stackPanel.Children.Add(chart);
                        chart.SetBinding(DataContextProperty, new Binding
                        {
                            Path   = new PropertyPath("Attributes"),
                            Source = this,
                        });
                    }
                }
            }
        }
Esempio n. 12
0
    public override PicturePage.Picture GetPictureWithBitmap(int id)
    {
        ChartEngine engine = new ChartEngine();

        engine.Size               = new Size(570, 300);
        engine.GridLines          = WebChart.GridLines.None;
        engine.ShowXValues        = true;
        engine.ShowYValues        = true;
        engine.LeftChartPadding   = 50;
        engine.BottomChartPadding = 50;
        engine.XAxisFont.StringFormat.LineAlignment = StringAlignment.Center;
        engine.XAxisFont.StringFormat.FormatFlags   = StringFormatFlags.DirectionVertical;
        engine.XAxisFont.ForeColor = engine.YAxisFont.ForeColor = Color.Black;

        ChartCollection charts = new ChartCollection(engine);

        engine.Charts = charts;

        List <TransitCounter> counters = SessionManager.GetCachedCollection <TransitCounter>(
            "GetStatsSummary", SessionManager.Ticket, new TransitStatsQueryOptions(RequestType));

        string format;

        switch (RequestType)
        {
        case TransitStats.Type.Daily:
            format = "MMM d";
            break;

        case TransitStats.Type.Hourly:
            format = "htt";
            break;

        case TransitStats.Type.Monthly:
            format = "MMM";
            break;

        case TransitStats.Type.Weekly:
            format = "MMM dd";
            break;

        case TransitStats.Type.Yearly:
            format = "yyyy";
            break;

        default:
            throw new ArgumentOutOfRangeException("type");
        }

        Color fill = Color.Black;

        ColumnChart chart = new ColumnChart();

        chart.ShowLineMarkers         = false;
        chart.ShowLegend              = true;
        chart.Line.Color              = Color.White;
        chart.Line.Width              = 2;
        chart.Fill.Color              = engine.Border.Color = fill;
        chart.Fill.LinearGradientMode = LinearGradientMode.Vertical;
        chart.MaxColumnWidth          = 100;

        foreach (TransitCounter counter in counters)
        {
            chart.Data.Add(new ChartPoint(counter.Created.ToString(format), counter.Count));
        }

        charts.Add(chart);

        PicturePage.Picture picture = new PicturePage.Picture();
        picture.Id       = 0;
        picture.Modified = DateTime.UtcNow;
        picture.Name     = RequestType.ToString();

        MemoryStream ds = new MemoryStream();

        engine.GetBitmap().Save(ds, ImageFormat.Png);
        picture.Bitmap = new byte[ds.Length];
        MemoryStream ms = new MemoryStream(picture.Bitmap);

        ds.WriteTo(ms);

        return(picture);
    }
Esempio n. 13
0
    public override TransitPicture GetPictureWithBitmap(int id)
    {
        ChartEngine engine = new ChartEngine();
        engine.Size = new Size(570, 300);
        engine.GridLines = WebChart.GridLines.None;
        engine.ShowXValues = true;
        engine.ShowYValues = true;
        engine.LeftChartPadding = 50;
        engine.BottomChartPadding = 50;
        engine.XAxisFont.StringFormat.LineAlignment = StringAlignment.Center;
        engine.XAxisFont.StringFormat.FormatFlags = StringFormatFlags.DirectionVertical;
        engine.XAxisFont.ForeColor = engine.YAxisFont.ForeColor = Color.Black;

        ChartCollection charts = new ChartCollection(engine);
        engine.Charts = charts;

        List<List<TransitSummarizedCounter>> counters = new List<List<TransitSummarizedCounter>>();
        string format;
        string title = RequestType.ToString();

        switch (RequestType)
        {
            case ChartType.DailyNew:
                counters.Add(Summary.NewDaily);
                format = "MMM d";
                title = "New Daily";
                break;
            case ChartType.DailyReturning:
                counters.Add(Summary.ReturningDaily);
                format = "MMM d";
                title = "Returning Daily";
                break;
            case ChartType.Daily:
                counters.Add(Summary.Daily);
                format = "MMM d";
                break;
            case ChartType.Hourly:
                counters.Add(Summary.Hourly);
                format = "htt";
                break;
            case ChartType.MonthlyUnique:
                counters.Add(Summary.UniqueMonthly);
                format = "MMM";
                title = "Monthly Unique";
                break;
            case ChartType.Monthly:
                counters.Add(Summary.Monthly);
                format = "MMM";
                break;
            case ChartType.Weekly:
                counters.Add(Summary.Weekly);
                format = "MMM dd";
                break;
            case ChartType.Yearly:
                counters.Add(Summary.Yearly);
                format = "yyyy";
                break;
            case ChartType.AccountDaily:
                counters.Add(Summary.AccountDaily);
                format = "MMM d";
                title = "New Daily";
                break;
            case ChartType.AccountMonthly:
                counters.Add(Summary.AccountMonthly);
                format = "MMM";
                title = "New Monthly";
                break;
            case ChartType.AccountWeekly:
                counters.Add(Summary.AccountWeekly);
                format = "MMM dd";
                title = "New Weekly";
                break;
            case ChartType.AccountYearly:
                counters.Add(Summary.AccountYearly);
                format = "yyyy";
                title = "New Yearly";
                break;
            default:
                throw new ArgumentOutOfRangeException("type");
        }

        long total = 0;
        long count = 0;
        Color fill = Color.FromArgb(0x9F, 0x6, 0x15);
        foreach (List<TransitSummarizedCounter> clist in counters)
        {
            ColumnChart chart = new ColumnChart();
            chart.ShowLineMarkers = false;
            chart.ShowLegend = true;
            chart.Line.Color = Color.White;
            chart.Line.Width = 2;
            chart.Fill.Color = engine.Border.Color = fill;
            chart.Fill.LinearGradientMode = System.Drawing.Drawing2D.LinearGradientMode.Vertical;
            chart.MaxColumnWidth = 100;

            count += clist.Count;

            foreach (TransitSummarizedCounter counter in clist)
            {                
                total += counter.Total;
                chart.Data.Add(new ChartPoint(counter.Timestamp.ToString(format), counter.Total));
            }

            charts.Add(chart);
            fill = Color.FromArgb(fill.R + 0x30, fill.G + 0x30, fill.B + 0x30);
        }

        engine.Title = new ChartText();
        double average = count > 0 ? total / count : 0;
        engine.Title.Text = string.Format("{0} (average: {1})", RequestType, average);

        TransitPicture picture = new TransitPicture();
        picture.Id = 0;
        picture.Modified = picture.Created = DateTime.UtcNow;
        picture.Name = RequestType.ToString();

        MemoryStream ds = new MemoryStream();
        engine.GetBitmap().Save(ds, System.Drawing.Imaging.ImageFormat.Png);
        picture.Bitmap = new byte[ds.Length];
        MemoryStream ms = new MemoryStream(picture.Bitmap);
        ds.WriteTo(ms);

        return picture;
    }
        private void UpdateOppoUI(string id)
        {
            try
            {
                ISDataService service;
                service = SDataDataService.mydataService();

                SDataResourceCollectionRequest oppoContactsCollection = new SDataResourceCollectionRequest(service);

                oppoContactsCollection.ResourceKind = "opportunitycontacts";
                oppoContactsCollection.QueryValues.Add("where", "Contact.Id eq '" + id + "'");

                AtomFeed oppoContactsFeed = oppoContactsCollection.Read();

                picBoxOpportunity.Visible = false;

                if (oppoContactsFeed.Entries.Count() > 0)
                {

                    DataTable table = new DataTable();

                    table.Columns.Add("Id");
                    table.Columns.Add("Description");
                    table.Columns.Add("Probability");
                    table.Columns.Add("Potential");
                    table.Columns.Add("ActualAmount");
                    table.Columns.Add("Status");

                    //--------------------------------------
                    // Create The Chart
                    ChartEngine engine = new ChartEngine();
                    engine.Size = picBoxOpportunity.Size;
                    ChartCollection charts = new ChartCollection(engine);
                    engine.Charts = charts;
                    int pointCount = 0;

                    ChartPointCollection data = new ChartPointCollection();
                    Chart columnChart = new ColumnChart(data, Color.DarkGreen);
                    columnChart.Fill.Color = Color.FromArgb(50, Color.Green);
                    columnChart.ShowLineMarkers = true;
                    columnChart.DataLabels.Visible = true;

                    foreach (AtomEntry entry in oppoContactsFeed.Entries)
                    {
                        SDataPayload oppoContact = entry.GetSDataPayload();

                        SDataPayload tempOppo = (SDataPayload)oppoContact.Values["Opportunity"];

                        SDataSingleResourceRequest oppo = new SDataSingleResourceRequest(service);

                        oppo.ResourceKind = "Opportunities";

                        oppo.ResourceSelector = "('" + tempOppo.Key + "')";

                        AtomEntry oppoEnty = oppo.Read();

                        SDataPayload opportunitiy = (SDataPayload)oppoEnty.GetSDataPayload();

                        DataRow dr = table.NewRow();

                        dr[0] = opportunitiy.Key.ToString();
                        dr[1] = (opportunitiy.Values["Description"] != null ? opportunitiy.Values["Description"].ToString() : "No Description");
                        dr[2] = (opportunitiy.Values["CloseProbability"] != null ? opportunitiy.Values["CloseProbability"].ToString() + "%" : "0%");
                        dr[3] = (opportunitiy.Values["SalesPotential"] != null ? String.Format("{0:C}", Convert.ToDecimal(opportunitiy.Values["SalesPotential"])) : "");
                        dr[4] = (opportunitiy.Values["ActualAmount"] != null ? String.Format("{0:C}", Convert.ToDecimal(opportunitiy.Values["ActualAmount"])) : "");
                        dr[5] = (opportunitiy.Values["Status"] != null ? opportunitiy.Values["Status"].ToString() : "No Status");

                        pointCount = Convert.ToInt32(opportunitiy.Values["SalesPotential"].ToString().Substring(0,opportunitiy.Values["SalesPotential"].ToString().IndexOf('.')));

                        data.Add(new ChartPoint("Some Data", pointCount));

                        table.Rows.Add(dr);
                    }

                    dgvOpportunities.DataSource = table;
                    dgvOpportunities.Columns["Id"].Visible = false;
                    dgvOpportunities.Refresh();

                    charts.Add(columnChart);
                    engine.GridLines = GridLines.Horizontal;
                    Image image = engine.GetBitmap();
                    //--------------------------------------
                    // At this point we have the chart already
                    //--------------------------------------
                    // show the already generated image
                    picBoxOpportunity.Image = image;

                    if (SLX_Outlook_AddIn.Properties.Settings.Default.OppoChartPanelMinimized == true)
                    {
                        picBoxOpportunity.Visible = false;
                    }
                    else
                    {
                        picBoxOpportunity.Visible = true;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
		protected void SetQuestionData(ChartEngine engine, ColumnChart columnChart)
		{
			try
			{
				DateTime startDate = Information.IsDate(Request["StartDate"]) ?
					DateTime.Parse(Request["StartDate"]) : new DateTime(1900,1,1),
					endDate = Information.IsDate(Request["EndDate"]) ?
					DateTime.Parse(Request["EndDate"]) : new DateTime(2100,1,1);

				_dataSource = new Questions().GetQuestionResults(_questionId, _filterId, _sortOrder, 
					Request["LanguageCode"], startDate, endDate);
			}
			catch (QuestionNotFoundException)
			{
				return;
			}

			QuestionResultsData.AnswersRow[] answers = _dataSource.Questions[0].GetAnswersRows();

			// Set-up question text
			engine.Title  = new ChartText();
			engine.Title.ForeColor = Color.FromArgb(255, 255, 255);
			engine.Title.Font = new Font("Tahoma", 9, FontStyle.Bold);

			// Do we need to show the parent question text for matrix based child questions
			if (!_dataSource.Questions[0].IsParentQuestionIdNull() && _dataSource.Questions[0].ParentQuestionText != null) 
			{
				String questionText = String.Format("{0} - {1}", 
					_dataSource.Questions[0].ParentQuestionText, 
					_dataSource.Questions[0].QuestionText);

				// Show parent and child question text
				engine.Title.Text = Server.HtmlDecode(questionText);
			} 
			else 
			{
				// Show question text
				engine.Title.Text = Server.HtmlDecode(_dataSource.Questions[0].QuestionText);
			}

			SetAnswerData(answers, GetVotersTotal(answers), engine, columnChart);
		}
Esempio n. 16
0
    public override PicturePage.Picture GetPictureWithBitmap(int id)
    {
        ChartEngine engine = new ChartEngine();
        engine.Size = new Size(570, 300);
        engine.GridLines = WebChart.GridLines.None;
        engine.ShowXValues = true;
        engine.ShowYValues = true;
        engine.LeftChartPadding = 50;
        engine.BottomChartPadding = 50;
        engine.XAxisFont.StringFormat.LineAlignment = StringAlignment.Center;
        engine.XAxisFont.StringFormat.FormatFlags = StringFormatFlags.DirectionVertical;
        engine.XAxisFont.ForeColor = engine.YAxisFont.ForeColor = Color.Black;

        ChartCollection charts = new ChartCollection(engine);
        engine.Charts = charts;

        List<TransitCounter> counters = SessionManager.GetCachedCollection<TransitCounter>(
            "GetStatsSummary", SessionManager.Ticket, new TransitStatsQueryOptions(RequestType));

        string format;

        switch (RequestType)
        {
            case TransitStats.Type.Daily:
                format = "MMM d";
                break;
            case TransitStats.Type.Hourly:
                format = "htt";
                break;
            case TransitStats.Type.Monthly:
                format = "MMM";
                break;
            case TransitStats.Type.Weekly:
                format = "MMM dd";
                break;
            case TransitStats.Type.Yearly:
                format = "yyyy";
                break;
            default:
                throw new ArgumentOutOfRangeException("type");
        }

        Color fill = Color.Black;

        ColumnChart chart = new ColumnChart();
        chart.ShowLineMarkers = false;
        chart.ShowLegend = true;
        chart.Line.Color = Color.White;
        chart.Line.Width = 2;
        chart.Fill.Color = engine.Border.Color = fill;
        chart.Fill.LinearGradientMode = LinearGradientMode.Vertical;
        chart.MaxColumnWidth = 100;

        foreach (TransitCounter counter in counters)
        {
            chart.Data.Add(new ChartPoint(counter.Created.ToString(format), counter.Count));
        }

        charts.Add(chart);

        PicturePage.Picture picture = new PicturePage.Picture();
        picture.Id = 0;
        picture.Modified = DateTime.UtcNow;
        picture.Name = RequestType.ToString();

        MemoryStream ds = new MemoryStream();
        engine.GetBitmap().Save(ds, ImageFormat.Png);
        picture.Bitmap = new byte[ds.Length];
        MemoryStream ms = new MemoryStream(picture.Bitmap);
        ds.WriteTo(ms);

        return picture;
    }