NSurvey - Pie Charts

Posted Tuesday, February 22, 2005 8:40 PM by CumpsD
NSurvey already provides general charts displaying the results, but it uses a bar chart and I had to output pie charts as well. So, I implemented them as well.

First, I created a new page, called PieChartReport.aspx, which was empty. After this I used the same code as the BarChartReport and filled up a ChartPointCollection, which I then used to create a new PieChart, render it and send it back to the client

 

ChartEngine engine = new ChartEngine();

ChartCollection charts = new ChartCollection(engine);     

           

engine.Size = new Size(350, 400);

engine.Charts = charts;

engine.Title = new ChartText();

           

if (questions.Questions[0].IsParentQuestionIdNull()) {

  engine.Title.Text = Server.HtmlDecode(

          Regex.Replace(questions.Questions[0].QuestionText, "<[^>]*>", " "));

} else {

  String questionText = String.Format("{0} - {1}",

                      questions.Questions[0]["ParentQuestionText"].ToString(),

                      questions.Questions[0].QuestionText);

  questionText = questionText.Replace(Environment.NewLine, "");

  questionText = questionText.Replace("\t", "");

  questionText = questionText.Replace("<p>", "");

  questionText = questionText.Replace("</p>", "");

  engine.Title.Text = Server.HtmlDecode(

                                 Regex.Replace(questionText, "<[^>]*>", " "));

}

 

PieChart pie = new PieChart(data);

engine.Charts.Add(pie);

ChartLegend legend = new ChartLegend();

legend.Position = LegendPosition.Bottom;

engine.HasChartLegend = true;

engine.Legend = legend;

engine.GridLines = GridLines.None;

 

 

Update: I used the following control by the way (which was already in NSurvey): http://www.carlosag.net/Tools/WebChart/Default.aspx

Filed under:

Comments

# re: NSurvey - Pie Charts

Tuesday, February 22, 2005 4:45 PM by BertG

now make it 3D!
get your geometry from under the dust :p

# re: NSurvey - Pie Charts

Tuesday, February 22, 2005 11:21 PM by ecktwo

for 3d effect, add...
pie.Explosion=8;
pie.Shadow.Visible=true;
pie.Shadow.Color=Color.LightGray;
pie.Shadow.OffsetY=5;

# re: NSurvey - Pie Charts

Tuesday, March 1, 2005 8:10 PM by ecktwo

Post the improved pie chart image.

# re: NSurvey - Pie Charts

Tuesday, March 15, 2005 7:20 AM by Patrick

have u done the 3d effect?
That would be interesting to have.