Exemplo n.º 1
0
 private void SetMoreProperties(ChartEngine engine)
 {
     engine.ChartPadding         = 15;
     engine.BottomChartPadding   = 10;
     engine.PlotBackground.Color = Color.FromArgb(240, 244, 248);
     engine.Background.Type      = InteriorType.LinearGradient;
     engine.Background.EndPoint  = new Point(700, 400);
     engine.Background.ForeColor = Color.FromArgb(245, 249, 251);
     engine.Background.Color     = Color.FromArgb(100, 75, 249);
 }
		private void Page_Load(object sender, System.EventArgs e)
		{
		
			_questionId = 
				Information.IsNumeric(Request["QuestionId"]) ? int.Parse(Request["QuestionId"]) : -1;
			_filterId = 
				Information.IsNumeric(Request["FilterId"]) ? int.Parse(Request["FilterId"]) : -1;
			_sortOrder =
				Request["SortOrder"] == null ? "ans" : Request["SortOrder"];

			if (_questionId == -1)
			{
				Response.End();
			}
			else if (!NSurveyUser.Identity.IsAdmin &&
				!NSurveyUser.Identity.HasAllSurveyAccess)
			{
				if (!new Question().CheckQuestionUser(_questionId, NSurveyUser.Identity.UserId))
				{
					Response.End();
				}
			}

			ChartEngine engine = new ChartEngine();
			ChartCollection charts = new ChartCollection(engine);

			engine.Size = new Size(700, 500);
			engine.Charts = charts;
			
			WebChart.ColumnChart chart = new WebChart.ColumnChart();
			chart.Fill.Color = Color.FromArgb(98,94,238);
			chart.MaxColumnWidth = 80;
			chart.DataLabels.Visible = true;
			chart.DataLabels.Position = DataLabelPosition.Bottom;
            chart.DataLabels.ForeColor = Color.White;
			chart.Shadow.Visible = true;
			chart.DataLabels.NumberFormat ="0.00";
            chart.ShowLineMarkers = true;

			SetQuestionData(engine, chart);
			SetMoreProperties(engine);

			charts.Add(chart);


			// send chart to browser
			Bitmap bmp;
			System.IO.MemoryStream memStream = new System.IO.MemoryStream();
			bmp = engine.GetBitmap();
			bmp.Save(memStream, System.Drawing.Imaging.ImageFormat.Png);
			memStream.WriteTo(Response.OutputStream);
			Response.End();

		}
        private void Page_Load(object sender, System.EventArgs e)
        {
            _questionId =
                Information.IsNumeric(Request["QuestionId"]) ? int.Parse(Request["QuestionId"]) : -1;
            _filterId =
                Information.IsNumeric(Request["FilterId"]) ? int.Parse(Request["FilterId"]) : -1;
            _sortOrder =
                Request["SortOrder"] == null ? "ans" : Request["SortOrder"];

            if (_questionId == -1)
            {
                Response.End();
            }
            else if (!NSurveyUser.Identity.IsAdmin &&
                     !NSurveyUser.Identity.HasAllSurveyAccess)
            {
                if (!new Question().CheckQuestionUser(_questionId, NSurveyUser.Identity.UserId))
                {
                    Response.End();
                }
            }

            ChartEngine     engine = new ChartEngine();
            ChartCollection charts = new ChartCollection(engine);

            engine.Size   = new Size(700, 500);
            engine.Charts = charts;

            WebChart.ColumnChart chart = new WebChart.ColumnChart();
            chart.Fill.Color              = Color.FromArgb(98, 94, 238);
            chart.MaxColumnWidth          = 80;
            chart.DataLabels.Visible      = true;
            chart.DataLabels.Position     = DataLabelPosition.Bottom;
            chart.DataLabels.ForeColor    = Color.White;
            chart.Shadow.Visible          = true;
            chart.DataLabels.NumberFormat = "0.00";
            chart.ShowLineMarkers         = true;

            SetQuestionData(engine, chart);
            SetMoreProperties(engine);

            charts.Add(chart);


            // send chart to browser
            Bitmap bmp;

            System.IO.MemoryStream memStream = new System.IO.MemoryStream();
            bmp = engine.GetBitmap();
            bmp.Save(memStream, System.Drawing.Imaging.ImageFormat.Png);
            memStream.WriteTo(Response.OutputStream);
            Response.End();
        }
 private void SetMoreProperties(ChartEngine engine)
 {
     engine.YCustomEnd           = 100;
     engine.ShowYValues          = true;
     engine.ShowXValues          = true;
     engine.ChartPadding         = 55;
     engine.BottomChartPadding   = 10;
     engine.RightChartPadding    = 20;
     engine.LeftChartPadding     = 20;
     engine.TopChartPadding      = 10;
     engine.GridLines            = WebChart.GridLines.Horizontal;
     engine.PlotBackground.Color = Color.FromArgb(240, 244, 248);
     engine.Background.Type      = InteriorType.LinearGradient;
     engine.Background.EndPoint  = new Point(700, 400);
     engine.Background.ForeColor = Color.FromArgb(245, 249, 251);
     engine.Background.Color     = Color.FromArgb(100, 75, 249);
 }
        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);
        }
Exemplo n.º 6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string[] s = new string[2] {
                "No data", "1"
            };
            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);
            }
            wcEng.GridLines  = GridLines.None;
            wcEng.Padding    = 0;
            wcEng.TopPadding = 0;

            ChartCollection wcCharts = new ChartCollection(wcEng);

            wcEng.Charts = wcCharts;

            PieChart slChart = new MyPieChart();

            slChart.Line.Color            = Color.Black;
            slChart.DataLabels.Visible    = true;
            slChart.DataLabels.ShowXTitle = true;
            slChart.DataLabels.ShowValue  = false;
            slChart.DataLabels.ShowLegend = false;
            slChart.Shadow.Visible        = true;
            slChart.Explosion             = 8;

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

            wcCharts.Add(slChart);
            wcEng.HasChartLegend = false;

            wcEng.Legend.Position = LegendPosition.Right;
            wcEng.Legend.Width    = 80;

            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();
        }
Exemplo n.º 7
0
        private void Page_Load(object sender, System.EventArgs e)
        {
            _questionId =
                Information.IsNumeric(Request["QuestionId"]) ? int.Parse(Request["QuestionId"]) : -1;
            _filterId =
                Information.IsNumeric(Request["FilterId"]) ? int.Parse(Request["FilterId"]) : -1;
            _sortOrder =
                Request["SortOrder"] == null ? "ans" : Request["SortOrder"];

            if (_questionId == -1)
            {
                Response.End();
            }
            else if (!NSurveyUser.Identity.IsAdmin &&
                     !NSurveyUser.Identity.HasAllSurveyAccess)
            {
                if (!new Question().CheckQuestionUser(_questionId, NSurveyUser.Identity.UserId))
                {
                    Response.End();
                }
            }

            ChartEngine     engine = new ChartEngine();
            ChartCollection charts = new ChartCollection(engine);

            engine.Size   = new Size(700, 500);
            engine.Charts = charts;


            PieChart pie = new PieChart();
            //pie.Colors = new Color[]{ Color.Red};

            ChartLegend legend = new ChartLegend();

            legend.Position         = LegendPosition.Right;
            legend.Width            = 200;
            legend.Background.Color = Color.FromArgb(245, 249, 251);

            pie.DataLabels.NumberFormat = "0.00";
            pie.Explosion         = 6;
            pie.Shadow.Visible    = true;
            pie.Shadow.Color      = Color.LightGray;
            pie.Shadow.OffsetY    = 5;
            engine.HasChartLegend = true;
            engine.Legend         = legend;
            engine.GridLines      = GridLines.None;


            SetQuestionData(engine, pie);
            SetMoreProperties(engine);

            charts.Add(pie);


            // send chart to browser
            Bitmap bmp;

            System.IO.MemoryStream memStream = new System.IO.MemoryStream();
            bmp = engine.GetBitmap();
            bmp.Save(memStream, System.Drawing.Imaging.ImageFormat.Png);
            memStream.WriteTo(Response.OutputStream);
            Response.End();
        }
Exemplo n.º 8
0
        protected void InitialiseChart()
        {
            Engine = new ChartEngine();

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

            // Set some display properties
            Engine.GridLines = GridLines.Horizontal;
            Fill.Color = Color.Red;

            Engine.ShowXValues = true;
            Engine.LeftChartPadding = 100;
            Engine.ShowYValues = true;
            Engine.BottomChartPadding = 10;

            Engine.YValuesInterval = 10;

            Engine.Charts.Add(this);
        }
Exemplo n.º 9
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();
        }
Exemplo n.º 10
0
        /// <summary>
        ///		Renders the chart
        /// </summary>
        /// <param name="graphics">Graphics object to output the drawing</param>
        /// <param name="width">Specifies the Width of the chart</param>
        /// <param name="height">Specifies the height of the chart</param>
        public override void Render(System.Drawing.Graphics graphics, int width, int height)
        {
            ChartEngine engine = this.Engine;
            float       scaleX = engine.ScaleX, scaleY = engine.ScaleY;
            Pen         pen   = this.Line.GetPen(graphics);
            Brush       brush = this.Fill.GetBrush(graphics);

            float xStart = 0, xWidth;

            int xCount = 0, xPosFinal = 0;

            if (engine.Charts.Count > 1)
            {
                foreach (Chart c in engine.Charts)
                {
                    if (c.Equals(this))
                    {
                        xPosFinal = xCount;
                    }
                    if (c as MapColumnChart != null)
                    {
                        xCount++;
                    }
                }
                xWidth = ((scaleX - 1) / xCount);
                xStart = xWidth * xPosFinal + 1;
            }
            else
            {
                xStart = 1;
                xWidth = scaleX;
            }

            float y;
            float yHeight;
            float x = 0;

            foreach (ChartPoint p in this.Data)
            {
                if (p.YValue * scaleY < 0)
                {
                    y       = (p.YValue * scaleY);
                    yHeight = -(p.YValue * scaleY);
                }

                else
                {
                    y       = 0;
                    yHeight = (p.YValue * scaleY);
                }
                Rectangle rect = new Rectangle(
                    (int)((float)(x * scaleX) + xStart),
                    (int)y,
                    (int)xWidth,
                    (int)yHeight);

                Point [] points = new Point[] { rect.Location };
                graphics.TransformPoints(
                    System.Drawing.Drawing2D.CoordinateSpace.Page,
                    System.Drawing.Drawing2D.CoordinateSpace.World,
                    points);

                if (this.rects != null)
                {
                    this.rects.Add(
                        new Rectangle(
                            points[0], new Size((int)xWidth, (int)yHeight))
                        );
                }
                graphics.FillRectangle(brush, rect);
                graphics.DrawRectangle(pen, rect);
                x++;
            }
        }
Exemplo n.º 11
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 SetMoreProperties(ChartEngine engine)
		{
			engine.YCustomEnd = 100;
			engine.ShowYValues = true;
			engine.ShowXValues = true;
            engine.ChartPadding = 55;
            engine.BottomChartPadding = 10;
            engine.RightChartPadding = 20;
            engine.LeftChartPadding = 20;
            engine.TopChartPadding = 10;
			engine.GridLines = WebChart.GridLines.Horizontal;
			engine.PlotBackground.Color = Color.FromArgb(240,244,248);
			engine.Background.Type = InteriorType.LinearGradient;
			engine.Background.EndPoint=new Point(700,400);
			engine.Background.ForeColor = Color.FromArgb(245,249,251);
			engine.Background.Color = Color.FromArgb(100,75,249);

		}
Exemplo n.º 13
0
        public void LoadGraph()
        {
            ChartEngine tempChartEngine = new ChartEngine();
            tempChartEngine.Size = GraphPictureBox.Size;
            tempChartEngine.ShowXValues = true;
            tempChartEngine.ShowYValues = true;
              //  tempChartEngine.Padding = 40;
            tempChartEngine.BottomChartPadding = 30;
            tempChartEngine.LeftChartPadding = 40;

            ChartText tempChartText = new ChartText();
            tempChartText.Text = "Hourly Sales";
            tempChartEngine.Title = tempChartText;

            CPaymentManager tempPaymentManager = new CPaymentManager();
            CResult oResult = tempPaymentManager.GetSortedPayment(DateTime.Now);
            double MaxAmount = 0.0;
            if (oResult.IsSuccess && oResult.Data != null)
            {
                MaxAmount = (double)oResult.Data;
            }

               // tempChartEngine.YValuesInterval = (int)Math.Floor(MaxAmount / 20);
            tempChartEngine.YValuesInterval = GetInterVal(MaxAmount);
            tempChartEngine.YCustomEnd = GetCustomEnd(GetInterVal(MaxAmount), MaxAmount);

            ChartCollection tempChartCollection = new ChartCollection(tempChartEngine);
            tempChartEngine.Charts = tempChartCollection;
            DateTime inCurrentDate = DateTime.Now;
            GetTimeSpan(inCurrentDate);

            //Data Access

            try
            {
                CPcInfoManager tempPcInfoManager = new CPcInfoManager();
                IPHostEntry ipEntry = System.Net.Dns.GetHostByName(Dns.GetHostName());
                CPcInfo tempPcInfo = (CPcInfo)tempPcInfoManager.PcInfoByPcIP(ipEntry.AddressList[0].ToString()).Data;

                DataSet tempHourlySaleDataSet = new DataSet();
                CCommonConstants oConstants = ConfigManager.GetConfig<CCommonConstants>();
                String sSql = String.Format("select 'NewTime' as \"NewTime\",bill_print_time.payment_time as \"Time\",payment.total_amount as \"Amount\" from payment,bill_print_time where payment.order_id=bill_print_time.order_id and bill_print_time.payment_time>={0} and bill_print_time.payment_time<{1} and payment.pc_id={2}", m_oStartTime, m_oEndTime, tempPcInfo.PcID);
                SqlDataAdapter tempSqlDataAdapter = new SqlDataAdapter(sSql, oConstants.DBConnection);
                tempSqlDataAdapter.Fill(tempHourlySaleDataSet);

                sSql = String.Format("select 'NewTime' as \"NewTime\",deposit_time as \"Time\",total_amount as \"Amount\" from deposit where deposit_time >= {0} and deposit_time < {1} and deposit.pc_id={2}", m_oStartTime, m_oEndTime, tempPcInfo.PcID);
                tempSqlDataAdapter = new SqlDataAdapter(sSql, oConstants.DBConnection);
                tempSqlDataAdapter.Fill(tempHourlySaleDataSet);

                ConvertTime(ref tempHourlySaleDataSet);

                //start dummy time
                DataRow row1 = tempHourlySaleDataSet.Tables[0].NewRow();
                row1["NewTime"] = "0:00";
                row1["Amount"] = "0.000";

                //end dummy time
                DataRow row2 = tempHourlySaleDataSet.Tables[0].NewRow();
                row2["NewTime"] = "23:59";
                row2["Amount"] = "0.000";

                tempHourlySaleDataSet.Tables[0].Rows.Add(row1);
                tempHourlySaleDataSet.Tables[0].Rows.Add(row2);

                Chart tempLineChart = new LineChart();
                tempLineChart.Line.Color = Color.Red;
                tempLineChart.ShowLineMarkers = false;
                tempLineChart.Line.Width = (float)2.0;

                DataTableReader oReader = tempHourlySaleDataSet.Tables[0].CreateDataReader();

                tempLineChart.DataSource = oReader;

                tempLineChart.DataXValueField = "NewTime";
                tempLineChart.DataYValueField = "Amount";
                tempLineChart.DataBind();
                tempChartCollection.Add(tempLineChart);

                Image image = tempChartEngine.GetBitmap();
                GraphPictureBox.Image = image;
                GraphPictureBox.Update();
            }
            catch (Exception exp)
            {
                throw exp;
            }
        }
		private void SetMoreProperties(ChartEngine engine)
		{
			engine.ChartPadding = 15;
            engine.BottomChartPadding = 10;
			engine.PlotBackground.Color = Color.FromArgb(240,244,248);
			engine.Background.Type = InteriorType.LinearGradient;
			engine.Background.EndPoint = new Point(700,400);
			engine.Background.ForeColor = Color.FromArgb(245,249,251);
			engine.Background.Color = Color.FromArgb(100,75,249);
		}
        private void SetAnswerData(QuestionResultsData.AnswersRow[] answers, float totalOfVotes, ChartEngine engine, WebChart.ColumnChart columnChart)
        {
            float currentRate    = 0;
            float totalRate      = 0;
            float totalRateVotes = 0;

            foreach (QuestionResultsData.AnswersRow answer in answers)
            {
                if ((((AnswerTypeMode)answer.TypeMode & AnswerTypeMode.Selection) > 0))
                {
                    float VotePercent = 0;

                    if (totalOfVotes != 0)
                    {
                        if (answer.VoterCount == 0)
                        {
                            VotePercent = 0;
                        }
                        else
                        {
                            VotePercent = ((float)answer.VoterCount / (float)totalOfVotes) * 100;
                        }
                    }

                    // Add answer text & vote count
                    answer.AnswerText = Server.HtmlDecode(System.Text.RegularExpressions.Regex.Replace(answer.AnswerText, "<[^>]*>", " "));
                    string answerChartText;
                    answerChartText = string.Format("{0} ({1})",
                                                    answer.AnswerText, answer.VoterCount.ToString());
                    columnChart.Data.Add(new ChartPoint(answerChartText, VotePercent));

                    // Do we include this answer in the
                    // rating total
                    if (answer.RatePart)
                    {
                        currentRate++;
                        totalRate      += currentRate * answer.VoterCount;
                        totalRateVotes += answer.VoterCount;
                    }
                }
            }

            StringFormat horizontalFormat = new StringFormat();

            horizontalFormat.LineAlignment = StringAlignment.Far;
            engine.XTitle = new ChartText();
            engine.XTitle.StringFormat = horizontalFormat;
            engine.XTitle.Font         = new System.Drawing.Font("Verdana", 7);

            // Do we show the average rating
            if (_dataSource.Questions[0].RatingEnabled)
            {
                double meanRate = 0;

                if (totalOfVotes == 0)
                {
                    meanRate = 0;
                }
                else
                {
                    meanRate = totalRate / totalRateVotes;
                }

                engine.XTitle.Text = string.Format("{0}{1}{2}{3}",
                                                   Environment.NewLine,
                                                   String.Format(ResourceManager.GetString("TotalOfVotes"), totalOfVotes),
                                                   Environment.NewLine,
                                                   string.Format(ResourceManager.GetString("RatingResults"), meanRate.ToString("##.##"), currentRate));
            }
            else
            {
                engine.XTitle.Text = String.Format(ResourceManager.GetString("TotalOfVotes"), totalOfVotes);
            }
        }
Exemplo n.º 16
0
        //        Dim myFont As New System.Drawing.Font("Tahoma", 8)
        //        engine.XTitle = New ChartText()
        //        Dim horizontalFormat As New StringFormat()
        //        horizontalFormat.LineAlignment = StringAlignment.Far
        //        engine.XTitle.StringFormat = horizontalFormat
        //        engine.XTitle.Text = "This is the XTitle"
        //        engine.XTitle.Font = myFont
        //
        //        ' Set-up the YTitle
        //        engine.YTitle = New ChartText()
        //        engine.YTitle.Font = myFont
        //        Dim verticalFormat As New StringFormat()
        //        verticalFormat.FormatFlags = StringFormatFlags.DirectionVertical
        //        verticalFormat.Alignment = StringAlignment.Near
        //        engine.YTitle.StringFormat = verticalFormat
        //        engine.YTitle.Text = "This is the YTitle"
        //
        //        ' Set-up the Title
        //        engine.Title = New ChartText()
        //        engine.Title.Text = "This is the Chart Title"
        //        
        //        ' Specify show XValues
        //        engine.ShowXValues = True
        //        engine.ShowYValues = True
        //        
        //        ' Some padding
        //        engine.Padding = 30
        //        engine.ChartPadding = 30
        //        
        //        ' some color
        //        engine.Background.Color = Color.FromArgb(70, Color.DarkBlue)
        //
        //        ' some color
        //        engine.PlotBackground.Color = Color.LightYellow
        //        Visible="False" ImageID="f917794c-5ba1-48bc-968a-a07b44313412" YCustomStart="0" Padding="1" YValuesInterval="0" GridLines="Both"
        //        ShowTitlesOnBackground="False" ChartPadding="30" YCustomEnd="0" BottomChartPadding="100" ChartFormat="Gif" BorderWidth="1px"
        //        Height="500px">
        //        <XTitle ForeColor="White" StringFormat="Center,Near,Character,LineLimit" Font="Tahoma, 8pt, style=Bold"></XTitle>
        //        <YAxisFont ForeColor="115, 138, 156" StringFormat="Far,Near,Character,LineLimit" Font="Tahoma, 8pt, style=Bold"></YAxisFont>
        //        <ChartTitle ForeColor="DeepSkyBlue" StringFormat="Near,Near,Character,LineLimit" Font="Verdana, 10pt, style=Bold"></ChartTitle>
        //        <XAxisFont ForeColor="115, 138, 156" StringFormat="Center,Center,Character,DirectionVertical"
        //        Font="Tahoma, 6pt, style=Bold"></XAxisFont>
        //        <Legend Position="Left" Width="70" Font="Tahoma, 7pt">
        //        <Background Color="WhiteSmoke"></Background>
        //             </Legend>
        //             <Background ForeColor="SteelBlue" EndPoint="500, 500"></Background>
        //        <YTitle ForeColor="White" StringFormat="Center,Near,Character,DirectionVertical" Text="Положение"
        //        Font="Tahoma, 8pt, style=Bold"></YTitle>
        //        <Border Color="51, 102, 102"></Border>
        //             <PlotBackground ForeColor="White"></PlotBackground>
        private void SetProperties(ref ChartEngine engine)
        {
            engine.Size = new Size(700,600) ;
            engine.ChartPadding = 20;
            engine.BottomChartPadding = 150;
            engine.Border.Width = 1;
            engine.ShowXValues = true;
            engine.ShowYValues = true;
            engine.HasChartLegend = true;
            engine.GridLines = WebChart.GridLines.None;
            //engine.YValuesFormat = "{0:N}";
            engine.YValuesInterval = 1;

            Font engTFont = new Font("verdana",8);
            engine.XTitle = new ChartText();
            engine.XTitle.ForeColor = Color.White;
            engine.XTitle.Font = engTFont;
            engine.XTitle.Text = "игры";
            engine.YTitle = new ChartText();
            engine.YTitle.ForeColor = Color.White;
            engine.YTitle.Font = engTFont;
            engine.YTitle.StringFormat.Alignment=StringAlignment.Center;
            engine.YTitle.StringFormat.LineAlignment=StringAlignment.Near;
            engine.YTitle.StringFormat.FormatFlags = StringFormatFlags.DirectionVertical;
            engine.YTitle.Text = "положение";

            engine.Background.ForeColor = Color.WhiteSmoke;

            Font engLFont = new Font("verdana",7);
            engine.Legend.Position = LegendPosition.Left;
            engine.Legend.Font = engLFont;
            ChartInterior ci = new ChartInterior();
            ci.ForeColor = Color.Black;
            engine.Legend.Background = ci;

            Font engXAFont = new Font("courier",7);
            engine.XAxisFont.Font = engXAFont;
            engine.XAxisFont.StringFormat.Alignment=StringAlignment.Center;
            engine.XAxisFont.StringFormat.LineAlignment=StringAlignment.Center;
            engine.XAxisFont.StringFormat.FormatFlags = StringFormatFlags.DirectionVertical;
            engine.XAxisFont.ForeColor = Color.Black;

            engine.YAxisFont.Font = engLFont;
            engine.YAxisFont.ForeColor = Color.Black;
        }
Exemplo n.º 17
0
        private void RenderUsers()
        {
            //Session["chart_ids"] = ids;
            //Session["chart_names"] = names;
            try
            {
                string[] ids_arr;
                string[] names_arr;
                ids_arr = Session["chart_ids"].ToString().Split('^');
                names_arr = Session["chart_names"].ToString().Split('^');

                DataSet dsUsers = new DataSet("UsersDS");
                dsUsers.Tables.Add("Users");
                DataTable dt = dsUsers.Tables["Users"];
                dt.Columns.Add("Id");
                dt.Columns.Add("Name");

                for(int i =0;i<ids_arr.GetUpperBound(0);i++)
                {
                    if( ids_arr[i] != "")
                    {
                        DataRow dr;
                        dr = dsUsers.Tables["Users"].NewRow();
                        dr["Id"] = ids_arr[i];
                        dr["Name"] = names_arr[i];
                        dsUsers.Tables["Users"].Rows.Add(dr);
                    }
                }

                wcEng = new ChartEngine();
                ChartCollection wcCharts = new ChartCollection(wcEng);
                wcEng.Charts = wcCharts;

                SetProperties(ref wcEng);

                DataSet dsXGames = new DataSet("XGames");
                FillXGames(ref dsXGames);

                int n = 0;
                DataSet dsUserPos = new DataSet("UserPos");
                foreach(DataRow dri in dsUsers.Tables["Users"].Rows)
                {
                    FillUserPos(ref dsUserPos,Convert.ToInt32(dri["id"]));
                    Chart lch = new WebChart.SmoothLineChart();
                    bool bNeedToShift = false;

                    //foreach (DataRow drxg in dsXGames.Tables[0].Rows)
                    //{
                    //    if (dsUserPos.Tables[0].Rows.Contains(drxg[0]))
                    //    {
                    //        DataRow drup = dsUserPos.Tables[0].Rows.Find(drxg[0]);
                    //        lch.Data.Add(new ChartPoint(ShiftGameName(drxg[0].ToString(), bNeedToShift), Convert.ToSingle(drup[1])));
                    //    }
                    //    else
                    //    {
                    //        DataRow drup = dsUserPos.Tables[0].Rows.Find(drxg[0]);
                    //        lch.Data.Add(new ChartPoint(ShiftGameName(drxg[0].ToString(), bNeedToShift), 30));
                    //    }

                    //    lch.DataLabels.Visible = true;
                    //    lch.DataLabels.ForeColor = Color.LightGray;
                    //    //bNeedToShift = !bNeedToShift;
                    //}

                    int nRowCount = dsXGames.Tables[0].Rows.Count;
                    //for(int z=nRowCount;z==1;z--)
                    for (int z = nRowCount - 1; z >= 0; z = z - 1)
                    //DataRow drxg in dsXGames.Tables[0].Rows)
                    {
                        DataRow drxg = dsXGames.Tables[0].Rows[z];
                        if (dsUserPos.Tables[0].Rows.Contains(drxg[0]))
                        {
                            DataRow drup = dsUserPos.Tables[0].Rows.Find(drxg[0]);
                            lch.Data.Add(new ChartPoint(ShiftGameName(drxg[0].ToString(), bNeedToShift), Convert.ToSingle(drup[1])));
                        }
                        else
                        {
                            //DataRow drup = dsUserPos.Tables[0].Rows.Find(drxg[0]);
                            //lch.Data.Add(new ChartPoint(ShiftGameName(drxg[0].ToString(), bNeedToShift), -1));
                        }
                        lch.DataLabels.Visible = true;
                        lch.DataLabels.ForeColor = Color.LightGray;
                        //bNeedToShift = !bNeedToShift;
                    }

                    lch.Line.Color = user_color[n%10];
                    n++;
                    lch.DataLabels.Visible=true;

                    Font dlFont = new Font("verdana",5);
                    lch.DataLabels.Font = dlFont;

                    lch.Legend = dri["name"].ToString();
                    lch.DataLabels.ForeColor = Color.Black;
                    lch.LineMarker = new CircleLineMarker(3, lch.Line.Color, lch.Line.Color);

                    wcEng.YCustomEnd  = Convert.ToInt32(Session["chart_Ycount"]);
                    wcEng.Charts.Add(lch);
                }

                Bitmap bmp;
                System.IO.MemoryStream memStream = new System.IO.MemoryStream();
                bmp = wcEng.GetBitmap();
                bmp.Save(memStream, System.Drawing.Imaging.ImageFormat.Png);
                memStream.WriteTo(Response.OutputStream);
                Response.End();
            }
            catch (Exception exc)
            {
                Response.Write(exc.Message);
            }
        }
Exemplo n.º 18
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);
    }
        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);
            }
        }
		private void Page_Load(object sender, System.EventArgs e)
		{
		
			_questionId = 
				Information.IsNumeric(Request["QuestionId"]) ? int.Parse(Request["QuestionId"]) : -1;
			_filterId = 
				Information.IsNumeric(Request["FilterId"]) ? int.Parse(Request["FilterId"]) : -1;
			_sortOrder =
				Request["SortOrder"] == null ? "ans" : Request["SortOrder"];

			if (_questionId == -1)
			{
				Response.End();
			}
			else if (!NSurveyUser.Identity.IsAdmin &&
				!NSurveyUser.Identity.HasAllSurveyAccess)
			{
				if (!new Question().CheckQuestionUser(_questionId, NSurveyUser.Identity.UserId))
				{
					Response.End();
				}
			}

			ChartEngine engine = new ChartEngine();
			ChartCollection charts = new ChartCollection(engine);
			engine.Size = new Size(700, 500);
			engine.Charts = charts;
			
			
			PieChart pie = new PieChart();
			//pie.Colors = new Color[]{ Color.Red};

			ChartLegend legend = new ChartLegend();
			legend.Position = LegendPosition.Right;
			legend.Width = 200;
			legend.Background.Color = Color.FromArgb(245,249,251);
			
			pie.DataLabels.NumberFormat ="0.00";
			pie.Explosion = 6; 
			pie.Shadow.Visible = true; 
			pie.Shadow.Color=Color.LightGray; 
			pie.Shadow.OffsetY = 5; 
			engine.HasChartLegend = true;
			engine.Legend = legend;
			engine.GridLines = GridLines.None;


			SetQuestionData(engine, pie);
			SetMoreProperties(engine);

			charts.Add(pie);


			// send chart to browser
			Bitmap bmp;
			System.IO.MemoryStream memStream = new System.IO.MemoryStream();
			bmp = engine.GetBitmap();
			bmp.Save(memStream, System.Drawing.Imaging.ImageFormat.Png);
			memStream.WriteTo(Response.OutputStream);
			Response.End();

		}
		protected void SetQuestionData(ChartEngine engine, PieChart pieChart)
		{
			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, pieChart);
		}
Exemplo n.º 22
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 SetAnswerData(QuestionResultsData.AnswersRow[] answers, float totalOfVotes, ChartEngine engine, WebChart.PieChart pieChart)
		{
			float currentRate = 0; 
			float totalRate = 0;
			float totalRateVotes = 0;
			
			foreach (QuestionResultsData.AnswersRow answer in answers)
			{
				if ((((AnswerTypeMode)answer.TypeMode & AnswerTypeMode.Selection) > 0))
				{
					float VotePercent = 0;

					if (totalOfVotes != 0)
					{
						if (answer.VoterCount==0)
							VotePercent = 0;		
						else
							VotePercent = ((float)answer.VoterCount / (float)totalOfVotes) * 100;
					}

					// Add answer text & vote count
					answer.AnswerText = Server.HtmlDecode(System.Text.RegularExpressions.Regex.Replace(answer.AnswerText, "<[^>]*>", " "));
					string answerChartText;
					
					if (VotePercent == 0)
					{
						answerChartText = string.Format("{0} " + Environment.NewLine +"({1} - 0%)",
							answer.AnswerText, answer.VoterCount.ToString(), VotePercent.ToString("##.##"));
					}
					else
					{
						answerChartText = string.Format("{0} " + Environment.NewLine +" ({1} - {2}%)",
							answer.AnswerText, answer.VoterCount.ToString(), VotePercent.ToString("##.##"));
					}
					
					
					pieChart.Data.Add(new ChartPoint(answerChartText, VotePercent));

					// Do we include this answer in the
					// rating total
					if (answer.RatePart)
					{
						currentRate++;
						totalRate += currentRate * answer.VoterCount;
						totalRateVotes += answer.VoterCount;
					}
				}
			}
		
			StringFormat horizontalFormat = new StringFormat();
			horizontalFormat.LineAlignment = StringAlignment.Near;
			engine.XTitle  = new ChartText();
			engine.XTitle.StringFormat = horizontalFormat;
			engine.XTitle.Font = new System.Drawing.Font("Verdana", 8);

			// Do we show the average rating 
			if (_dataSource.Questions[0].RatingEnabled)
			{
				double meanRate = 0;

				if (totalOfVotes == 0)
					meanRate = 0;
				else
					meanRate = totalRate / totalRateVotes;

				engine.XTitle.Text = string.Format("{0} - {1}",
					String.Format(ResourceManager.GetString("TotalOfVotes"), totalOfVotes),
					string.Format(ResourceManager.GetString("RatingResults"), meanRate.ToString("##.##"), currentRate));		
			}
			else
			{
				engine.XTitle.Text = String.Format(ResourceManager.GetString("TotalOfVotes"), totalOfVotes);
			}
		}
Exemplo n.º 24
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;
    }