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 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); } }