Visión global:
(Actualización 12/04/07: Engadido outro recurso interesante a finais ligazón a outro blog que aborda esta vía a parte da web moi interesante)
This blog entry describes how to create a bar graph in SharePoint. This works in both WSS and MOSS environments as it only depends upon the data view web part.
The overall approach is as follows:
- Create a list or document library that contains the data you want to graph.
- Place the associated document library / custom list onto a page and convert it to a data view web part (DVWP).
- Modify the DVWP’s XSL to generate HTML that shows as a graph.
Escenario empresarial / Instalación:
I have created a custom list with the standard Title column and one additional column, "Status". This models (very simplistically) an "Authorization For Expense" scenario where the title represents the project and the Status a value from the list of:
- Proposed
- In Process
- Stalled
The objective is to produce an interactive horizontal bar graph that shows these status codes.
I have populated the list and it looks like this:
Create Data View Web Part:
Create the DVWP by adding the custom list to a page (site page in my case) and follow the instructions aquí (http://paulgalvin.spaces.live.com/blog/cns!1CC1EDB3DAA9B8AA!395.entry).
In addition to simply creating the DVWP, we also need to set the paging property to show all available rows. Para min, this looks something like this:
Neste punto, I always close SPD and the browser. I then re-open the page using the browser. This avoids accidentally mucking up the web part layout on the page.
Modify the XSLT:
It’s now time to modify the XSLT.
I always use visual studio for this. (Ver aquí for an important note about intellisense that will help you a lot).
I create an empty project add four new files (replacing the words "Original" and "New" as appropriate):
- Original.xslt
- New.xslt
- Original Params.xml
- New Params.xml
No meu caso, parece que esta:
Modify the web part and copy the params and XSL to the "Original" version in Visual Studio.
The objective here is to cause the XSL to transform the results we get back from the DVWP query into HTML that renders as a graph.
Para este fin, it helps to first consider what the HTML should look like before we get confused by the insanity that is known as "XSL". (To be clear, the following is simply an example; don’t type it or copy/paste into visual studio. I provide a full blow starting point for that later in the write-up). The following sample graph is rendered as per the HTML immediately following:
Corresponding HTML:
<html> <corpo> <centro> <table width=80%> <tr><td><centro>Horizontal Bar Graph</td></tr> <tr> <td align="center"> <table border="1" width=80%> <tr> <td width=10%>Open</td> <td><table cellpadding="0" cellspacing="0" border=0 width=50%><tr bgcolor = vermello><td> </td></tr></mesa></td> </tr> <tr> <td width=10%>Pechado</td> <td><table cellpadding="0" cellspacing="0" border=0 width=25%><tr bgcolor = vermello><td> </td></tr></mesa></td> </tr> <tr> <td width=10%>Stalled</td> <td><table cellpadding="0" cellspacing="0" border=0 width=25%><tr bgcolor = vermello><td> </td></tr></mesa></td> </tr> </mesa> </td> </tr> </mesa> </corpo> </html> |
I used a dead simple approach to creating my bars by setting the background color of a row to "red".
The take-away here is this: A finais, all we are doing is creating HTML with rows and columns.
Template XSLT:
I’ve copied the XSLT that generates a horizontal bar graph. It’s fairly well commented so I won’t add much here except for these notes:
- I started with the default XSL that SharePoint Designer gave me when I first created the DVWP.
- I was able to cut this down from SPD’s 657 lines to 166 lines.
- I didn’t mess around with the parameters XML file (which is separate from the XSL and you’ll know what I mean when you go to modify the DVWP itself; there are two files you can modify). Con todo, in order to simplify it, I did remove nearly all of them from the XSL. This means that if you want to make use of those parameters, you just need to add their variable definitions back to the XSL. That will be easy since you will have the original XSL variable definitions in your visual studio project.
- You ought to be able to copy and paste this directly into your visual studio project. Entón, remove my calls and insert your own calls to "ShowBar".
- The drill down works by creating an <a href> así: http://server/List?FilterField1=fieldname&FilterValue1=actualFilterValue. This technique may be of value in other contexts. A principio, I thought I would need to conform to a more complex format: http://server/List/AllItems.aspx?View={guid}&FilterField1=blah&FilterValue1=blah, but in my environment that is not necessary. The List’s URL is passed to us by SharePoint so this is quite easy to generalize.
Here it is:
<XSL:stylesheet versión="1.0" exclude-result-prefixes="rs z o s ddwrt dt msxsl" |
The Results:
The XSL from above generates this graph:
Drill down to the underlying data by clicking on the status code:
Concluding Thoughts:
Can This Be Generalized?
I love this graphing concept, but I hate the fact that I have to go in and do so much hand-coding. I’ve given a little thought to whether it can be generalized and I’m optimistic, but I’m also a little fearful that there may be a brick wall somewhere along the path that won’t offer any work-around. If anyone has some good ideas on this, please make a note in the comments or enviar correo-e me.
Vertical Graphs:
This is a horizontal bar graph. It’s certainly possible to create a vertical graph. We just need to change the HTML. I would start the same way: Create an HTML representation of a vertical bar graph and then figure out how to get that via XSL. If anyone is interested in that, I could be persuaded to try it out and work out the kinks. If someone has already done that, please let me know and I’ll gladly link to your blog 🙂
I think that challenge with a vertical graph is that the labels for the graph are more difficult to manage, but certainly not impossible.
Field Name Gotcha’s:
There are at least two things to look out for with your field names.
Primeiro, a field name with a space has to be escaped in the XSL. This will probably be an issue here:
<XSL:variable nome="totalProposed"
seleccionar="count(/dsQueryResponse/Rows/Row[normalize-space(@Status) = 'Proposed'])" />
If your "Status" column is actually named "Status Code" then you need to reference it as "Status_x0020_Code":
<XSL:variable nome="totalProposed"
seleccionar="count(/dsQueryResponse/Rows/Row[normalize-space(@Status_x0020_Code) = 'Proposed'])" />Segundo, and I’m a little fuzzy on this, but you also need to be on the alert for field name changes. If you name your field "Status Code" and then later on, rename it to "AFE Status", the "internal name" does not change. The internal name will still be "Status Code" and must be referenced as "Status_x0020_Code". The "other resources" links may help diagnose and correct this kind of problem.
About that Color:
I picked "red" because it’s pleasing to me at the moment. It would not be a big deal to show different colors so as to provide more than just a visual description of a number, but to also provide a useful KPI. Por exemplo, if the percentage of "stalled" AFE’s is > 10% then show it red, otherwise show it in black. Usar <XSL:escoller> to accomplish this.
Other Resources:
- Determine the internal name (and other good info) for the data in a list: http://paulgalvin.spaces.live.com/blog/cns!1CC1EDB3DAA9B8AA!134.entry
- Show all the data provided by SharePoint (the raw XML): http://paulgalvin.spaces.live.com/blog/cns!1CC1EDB3DAA9B8AA!190.entry
- Get the XPATH expression of a specific column: http://paulgalvin.spaces.live.com/blog/cns!1CC1EDB3DAA9B8AA!155.entry
- Another approach using OWA(?). I have not dug into it, but looks promising, especially for pie charts: http://www.waka.dk/Blog/PermaLink,guid,e2532e71-d774-4ac9-8f25-883964b830f4.aspx
Happy transforming!
</ Comezo>
Esta páxina case concluído o traballo que eu estaba a buscar.
Eu teño un grupo que quere usar a lista do SharePoint Enquisa para crear unha enquisa semanal. A captura? Non quere ver código… Ou cambiar o sistema cada vez que enviar a enquisa (planeado para unha actualización semanal).
Eu era capaz de conectar este á lista de Izado e crear o gráfico na primeira columna resposta. O que eu non podo prever, porén, son os valores e as etiquetas que precisan avanzar. Aínda por riba poden ter máis ou menos respostas dispoñibles cada semana.
Vou buscar noutro lugar só no caso, pero ten alguén atopou un xeito de crear liñas e etiquetas con base fóra do número de opcións dispoñibles e configurar dinámica estes en vez de codificar os valores esperados?
Grazas Paul. Very helpful. Grazas ao seu traballo, Eu era capaz de engadir unha columna bar gráfico para un DVWP existente (e.g. para tarefas) moi facilmente con só algunhas liñas de código.
No SharePoint Designer, Inserir unha exhibición de datos co título e % columnas completas de unha lista de tarefas. Engada o cursor nunha das células e prema co botón dereito. Eu selecciono inserir unha columna á dereita. En vista de código, Eu atopei o <td> e substituíu o <XSL:elemento de texto dentro da célula co seu código:
<table cellpadding="0" cellspacing="0" border ="0"
ancho = "{round(@ * 100 PercentComplete)+1}%">
<estilo tr = "background-color:vermello ">
<XSL:texto disable-output-Escaping = "yes"><![CDATA[ ]]></XSL:texto>
</tr>
</mesa>
Nota eu mudei o código de cor liña de bgcolor = "red" a style = "background-color:red"
Tamén, was able to select one of the columns in my list (@PercentComplete) in place of "$BarPercent"
Greg
Another method (using only the SharePoint UI):
http://pathtosharepoint.wordpress.com/2008/09/02/a-progress-bar-for-your-tasks-list/
http://pathtosharepoint.wordpress.com/2008/10/21/progress-bar-color-coding/
xmlns:__designer=http://schemas.microsoft.com/WebParts/v2/DataView/designer xmlns:asp="http://schemas.microsoft.com/ASPNET/20">
select="count(/dsQueryResponse/Rows/Row[normalize-space(@Status)=’WIP’])" />
http://www.microsoft.com/sharepoint/downloads/components/detail.asp?a1=701Ian Morrish posted this in May 2006. I tried in MOSS 2007 and it works well. Added to GAC, had to execadmsvcjobs and iisreset…
Gran post, grazas!
Gran post, grazas!
Ola Paulo!
Nice work! I also had something like this in my mind to view SharePoint lists in a graphical way 😉
I have a ‘Using Dashboards in SharePoint’ question. We are a military hospital using MOSS standard for our Intranet and would like to build a dashboard for our Command Group to see ‘real time’ if possible. One of the main points is viewing the real-time current workload within the facility and literally watch it change up and down (may have to click “refresh”/F5).
Thank you in advance,
Pode facer algo de útil con jQuery para acadar este efecto. Email me at galvin.paul @ gmail.com e eu vou ser feliz para tratar de dar unha man.