Overview:
(UPDATE 12/04/07: Aliongeza mwingine rasilimali ya kuvutia mwishoni kuunganisha na mwingine blog kuwa anwani hii kupitia sehemu ya kuvutia sana mtandao)
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.
mbinu jumla ni kama ifuatavyo:
- Kuunda orodha au maktaba ya hati ambayo ina data unataka graph.
- Nafasi ya kuhusishwa hati maktaba / desturi orodha kwenye ukurasa na kubadili mtazamo wa data sehemu ya mtandao (DVWP).
- Kurekebisha DVWP ya XSL kuzalisha HTML kwamba inaonyesha kama graph.
Biashara Igizo / Kuanzisha:
I have umba orodha desturi na safu ya kiwango Kichwa na safu moja ya ziada, "Status". This models (sana simplistically) an "Authorization For Expense" mazingira ambapo cheo inawakilisha mradi na Hali ya thamani kutoka kwenye orodha ya:
- Mapendekezo
- Katika Mchakato
- Umesitishwa
Lengo ni kuzalisha maingiliano usawa bar graph inaonyesha kwamba kanuni hizi hali ya.
Mimi wakazi orodha na inaonekana kama hii:
Kujenga Takwimu View Mtandao Sehemu ya:
Kujenga DVWP kwa kuongeza orodha desturi ya ukurasa (tovuti ukurasa katika kesi yangu) na kufuata maelekezo hapa (http://paulgalvin.spaces.live.com/blog/cns!1CC1EDB3DAA9B8AA!395.entry).
Mbali na tu kujenga DVWP, we also need to set the paging property to show all available rows. Kwa ajili yangu, hii inaonekana kitu kama hiki:
Katika hatua hii, 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.
Kurekebisha XSLT:
Ni wakati sasa wa kurekebisha XSLT.
I always use visual studio for this. (Kuona hapa kwa kumbuka muhimu kuhusu Intellisense kwamba itasaidia mengi).
Mimi kujenga mradi tupu kuongeza wanne faili jipya (replacing the words "Original" and "New" kama inafaa):
- Original.xslt
- New.xslt
- Awali Params.xml
- Mpya Params.xml
Katika kesi yangu, inaonekana kama hii:
Modify the web part and copy the params and XSL to the "Original" toleo katika Visual Studio.
Lengo hapa ni kusababisha XSL wa kubadilisha matokeo ya sisi kupata nyuma kutoka swala DVWP katika HTML kuwa mithili kama graph.
Hadi mwisho huu, it helps to first consider what the HTML should look like before we get confused by the insanity that is known as "XSL". (Kuwa wazi, zifuatazo ni tu mfano; 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:
Sambamba HTML:
<html> <mwili> <kituo cha> <meza width = 80%> <tr><td><kituo cha>Horizontal Bar Grafu</td></tr> <tr> <td align="center"> <table border="1" width = 80%> <tr> <td width = 10%>Kufungua</td> <td><meza cellpadding ="0" cellspacing ="0" mpaka = 0 upana = 50%><tr Bgcolor = nyekundu><td> </td></tr></meza></td> </tr> <tr> <td width = 10%>Kufungwa</td> <td><meza cellpadding ="0" cellspacing ="0" mpaka = 0 width = 25%><tr Bgcolor = nyekundu><td> </td></tr></meza></td> </tr> <tr> <td width = 10%>Umesitishwa</td> <td><meza cellpadding ="0" cellspacing ="0" mpaka = 0 width = 25%><tr Bgcolor = nyekundu><td> </td></tr></meza></td> </tr> </meza> </td> </tr> </meza> </mwili> </html> |
I used a dead simple approach to creating my bars by setting the background color of a row to "red".
kuchukua-mbali hapa ni hii: Katika mwisho, wote sisi ni kufanya ni kujenga HTML na safu na nguzo.
Kigezo 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:
- Nilianza kwa XSL default kwamba SharePoint Designer alinipa wakati mimi kwanza kuundwa DVWP.
- Nilikuwa na uwezo wa kata hii ya chini kutoka SPD 657 mistari ya 166 lines.
- Mimi si fujo karibu na faili vigezo XML (ambayo ni tofauti na XSL na wewe utakuwa kujua nini maana mimi wakati wewe kwenda kurekebisha DVWP yenyewe; kuna mbili files unaweza kurekebisha). Hata hivyo, ili kurahisisha hilo, 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. Kisha, remove my calls and insert your own calls to "ShowBar".
- drill chini anafanya kazi kwa kujenga <href> kama hii: http://server/List?FilterField1=fieldname&FilterValue1=actualFilterValue. This technique may be of value in other contexts. At first, Nilidhani napenda haja ya kuendana na muundo ngumu zaidi: 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.
Hapa ni:
<xsl:Lahamtindo toleo="1.0" kuwatenga-matokeo-viambishi awali="rs z o s ddwrt dt msxsl" |
Matokeo:
XSL kutoka juu inazalisha hii graph:
Kuchimba chini kwa data ya msingi kwa kubonyeza kanuni hali ya:
Kuhitimisha Mawazo:
Hii inaweza kuwa jumla?
I love hii dhana graphing, 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, tafadhali kufanya kumbuka katika maoni au email yangu.
Wima Grafu:
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, tafadhali nijulishe na nitaunganisha kwa furaha blogi yako 🙂
Nadhani kuwa changamoto na graph wima ni kwamba maandiko kwa graph ni vigumu zaidi ya kusimamia, lakini kwa hakika si vigumu.
Shamba la Gotcha ya:
Kuna angalau vitu viwili kwa kuangalia nje kwa pamoja na majina yako shamba.
Kwanza, a field name with a space has to be escaped in the XSL. This will probably be an issue here:
<xsl:variable jina="totalProposed"
kuchagua="kuhesabu(/dsQueryResponse / Safu / Row[kurejesha-nafasi(@ Status) = 'Mapendekezo'])" />
If your "Status" column is actually named "Status Code" then you need to reference it as "Status_x0020_Code":
<xsl:variable jina="totalProposed"
kuchagua="kuhesabu(/dsQueryResponse / Safu / Row[kurejesha-nafasi(@ Status_x0020_Code) = 'Mapendekezo'])" />Pili, na mimi nina fuzzy kidogo juu ya hili, but you also need to be on the alert for field name changes. If you name your field "Status Code" na kisha baadaye, 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" viungo inaweza kusaidia kutambua na kurekebisha aina hii ya tatizo.
Kuhusu Alama ya kwamba:
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. Kwa mfano, if the percentage of "stalled" Aliamuru ni > 10% kisha kuonyesha kuwa nyekundu, otherwise show it in black. Kutumia <xsl:kuchagua> kukamilisha hili.
Rasilimali nyingine:
- Kuamua jina ndani (na nyingine nzuri ya maelezo) kwa data katika orodha: http://paulgalvin.spaces.live.com/blog/cns!1CC1EDB3DAA9B8AA!134.entry
- Kuonyesha data zote zinazotolewa na SharePoint (XML mbichi): http://paulgalvin.spaces.live.com/blog/cns!1CC1EDB3DAA9B8AA!190.entry
- Kupata kujieleza XPath wa safu maalum: http://paulgalvin.spaces.live.com/blog/cns!1CC1EDB3DAA9B8AA!155.entry
- Mkabala mwingine kutumia OWA(?). I have not dug into it, lakini inaonekana kuahidi, hasa kwa ajili ya pai: http://www.waka.dk/Blog/PermaLink,guid,e2532e71-d774-4ac9-8f25-883964b830f4.aspx
Furaha kubadilisha!
<mwisho />