3

Ok,

Im havving trouble accessing the survey graph.

My questions is how on earth does sharpoint create the graph from "graphical summary". I have a webpart, i can get the data and the questions without any issues but i want the graph that is produced or to reproduce it myself if possible!

Iv looked all over the internet and there is no info on how to get the graph on a webpart :( so im asking here!

I dont want to recreate the wheel if its already done for me on that view and just want to pull it out and display it on a webpart.

is there any function that i could use that would take it from the list and does the working out for me like within the list views webpart?

any advice would be great!

3

There is a great write up of how to do this with XSLT:

http://msdn.microsoft.com/en-us/library/cc300164(v=office.12).aspx

This link essentially describes how to use XSLT to manipulate a table to display the results in a horizontal graph. If you are doing this with client-side code, I'd highly recommend you use Javascript instead of XSLT though...

Here's a screenshot of the results:

enter image description here

  • thanks for the help but unfortunatly that doesnt help me as iv already looked at that solution :( but i did make my own as it needed to be done programmatically! but i will up vote as its relivant just not in my case as everything needs to be dynamic for multiple surveys! – Ali Jafer Oct 11 '13 at 14:38
2

altho there is xslt, unfortunatly its not the way thats right for me.

The list is pulled dynamically and it will display multiple graphs on the same page for any survey on any site (surveys collected and shown on one page).

I managed to figure it out yay:

to achive the given result I did:

1) get list

2) create chart

3) get fields name and value from list (make sure its a choice value)

4) loop through each question

5) for each question loop through each possible answer

6) use spquery to get the total using the question and possible answer

7) populate the result on the chart

8) once finished add chart to panel

9) add panel to controls

    private void getSurveyGraphResultForAll(string _ListName, string _SiteName, string _ViewName, Panel BODY)
    {
        using (SPSite site = new SPSite(_SiteName))
        {
            using (SPWeb web = site.OpenWeb())
            {
                try
                {
                    if (!string.IsNullOrEmpty(_ListName))
                    {
                        SPList list = null;
                        try
                        {
                            list = web.Lists[_ListName];

                            SPUser currentUser = SPContext.Current.Web.CurrentUser;

                            SPListItemCollection items = list.GetItems();

                            Random rnd = new Random();
                            Chart1.Width = 412;
                            Chart1.Height = 296;
                            Chart1.ImageStorageMode = ImageStorageMode.UseImageLocation;
                            Chart1.ID = rnd.Next().ToString();

                            Chart1.RenderType = RenderType.ImageTag;
                            string imagespath = "/chartimages/";
                            Chart1.ImageLocation = imagespath + "ChartPic_#SEQ(200,30)";
                            Chart1.Palette = ChartColorPalette.BrightPastel;
                            Title t = new Title(list.Title, Docking.Top, new System.Drawing.Font("Trebuchet MS", 14, System.Drawing.FontStyle.Bold), System.Drawing.Color.FromArgb(26, 59, 105));
                            Chart1.Titles.Add(t);
                            Chart1.ChartAreas.Add("Series 1");

                            foreach (SPListItem item in list.Items)
                            {

                                foreach (SPField field in item.Fields)
                                {
                                    if (field.TypeAsString == "Choice")
                                    {
                                        if (Chart1.Series.FindByName(field.Title) == null)
                                        {
                                            Chart1.Series.Add(field.Title);
                                        }

                                        SPFieldChoice fd = (SPFieldChoice)field;

                                        foreach (string str in fd.Choices)
                                        {

                                            SPQuery responseQuery = new SPQuery();

                                            responseQuery.Query = @"<Where><Eq><FieldRef Name=" + field.InternalName.ToString() + " /><Value Type=\"Choice\">" + str + @"</Value></Eq></Where>";

                                            Chart1.Series[field.Title.ToString()].Points.AddY(list.GetItems(responseQuery).Count);
                                        }

                                    }
                                }
                            }

                            Chart1.BorderSkin.SkinStyle = BorderSkinStyle.Emboss;
                            Chart1.BorderColor = System.Drawing.Color.FromArgb(26, 59, 105);
                            Chart1.BorderlineDashStyle = ChartDashStyle.Solid;
                            Chart1.BorderWidth = 2;

                            Chart1.Legends.Add("Legend1");
                            Chart1.Legends["Legend1"].Enabled = true;

                            BODY.Controls.Add(Chart1);
                        }
                        catch (Exception a)
                        {
                            //catch exception
                        }
                    }
                }
                catch (Exception ax)
                {
                    //catch exception
                }
            }
        }
    }

hope this is usefull to someone out there as I couldnt find anything about this online and this is what iv come up with so far.

  • Awesome! Thanks for sharing. Based on your reqs, Javascript would work as well. Good stuff! – iOnline247 Oct 11 '13 at 21:37
0

Open the site in SharePoint Designer. Navigate to the survey properties and open the view for the graphical display. Copy the code from code view.

Open the web part page with the list view of the survey and paste the copied code over the existing list view code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.