Ħarsa ġenerali:
(UPDATE 12/04/07: Miżjud riżors ieħor interessanti fl-aħħar jgħaqqdu għal ieħor blog li tindirizza din permezz ta 'parti web interessanti ħafna)
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.
L-approċċ ġenerali hija kif ġej:
- Tinħoloq lista jew il-librerija dokument li jkun fih l-informazzjoni li inti tixtieq li graff.
- Poġġi l-librerija dokument ieħor assoċjat, / lista tad-dwana fuq il-paġna u jaqilbu għal parti data web ħsieb (DVWP).
- Tibdel XSL l DVWP li tiġġenera HTML li turi bħala graff.
Xenarju Business / Setup:
I ħolqu lista custom mal-Titolu kolonna standard u l-kolonna addizzjonali waħda, "Status". This models (ħafna simplistikament) an "Authorization For Expense" xenarju fejn it-titolu jirrappreżenta l-proġett u l-Istatus ta 'valur mil-lista ta':
- Propost
- Fil Proċess
- Waqfu
L-għan huwa li jipproduċu graff interattiv bar orizzontali li turi dawn il-kodiċijiet istat.
Għandi popolati il-lista u jidher qisu dan:
Oħloq Data View Web Parti:
Oħloq il-DVWP billi żżid il-lista tad-dwana għal paġna (Paġna sit fil-każ tiegħi) u segwi l-istruzzjonijiet hawn (http://paulgalvin.spaces.live.com/blog/cns!1CC1EDB3DAA9B8AA!395.entry).
Minbarra li sempliċiment toħloq l-DVWP, we also need to set the paging property to show all available rows. Għalija, dan jistenna xi ħaġa bħal din:
F'dan il-punt, 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.
Tibdel il XSLT:
Issa huwa żmien biex jimmodifika l-XSLT.
I always use visual studio for this. (Ara hawn għal nota importanti dwar IntelliSense li ser jgħinek ħafna).
I joħolqu proġett vojta żid erba fajls ġodda (replacing the words "Original" and "New" kif xieraq):
- Original.xslt
- New.xslt
- Params.xml Original
- New Params.xml
Fil-każ tiegħi, jidher qisu dan:
Modify the web part and copy the params and XSL to the "Original" verżjoni fis Visual Studio.
L-għan hawnhekk huwa li jikkawża l XSL li tittrasforma r-riżultati nikbru lura mill-mistoqsija DVWP fis HTML li jirrendi bħala graff.
Biex dan il-għan, it helps to first consider what the HTML should look like before we get confused by the insanity that is known as "XSL". (Biex ikunu ċari, li ġej huwa sempliċement eżempju; 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:
HTML Korrispondenti:
<html> <korp> <ċentru> <wisa tabella = 80%> <tr><td><ċentru>Grafika Bar orizzontali</td></tr> <tr> <td align="center"> <table border="1" wisa '= 80%> <tr> <wisa td = 10%>Open</td> <td><tabella cellpadding ="0" cellspacing ="0" fruntiera = 0 wisa '= 50%><tr bgcolor = aħmar><td> </td></tr></tabella></td> </tr> <tr> <wisa td = 10%>Magħluq</td> <td><tabella cellpadding ="0" cellspacing ="0" fruntiera = 0 wisa '= 25%><tr bgcolor = aħmar><td> </td></tr></tabella></td> </tr> <tr> <wisa td = 10%>Waqfu</td> <td><tabella cellpadding ="0" cellspacing ="0" fruntiera = 0 wisa '= 25%><tr bgcolor = aħmar><td> </td></tr></tabella></td> </tr> </tabella> </td> </tr> </tabella> </korp> </html> |
I used a dead simple approach to creating my bars by setting the background color of a row to "red".
Il-take-away hawnhekk hija din: Fl-aħħar, kollha qed nagħmlu qed toħloq HTML ma ringieli u kolonni.
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 beda bil-default XSL li SharePoint Designer tatni meta I ewwel ħolqu l-DVWP.
- I kien kapaċi li tnaqqas din stabbiliti minn dak tal-SPD 657 linji għal 166 lines.
- I ma mess madwar il-fajl XML parametri (li hija separata mill-XSL u tkun taf taf dak li jfisser meta inti tmur biex jimmodifikaw il-DVWP innifsu; hemm żewġ fajls li inti tista 'timmodifika). Madankollu, sabiex tkun issimplifikata, 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. Imbagħad, remove my calls and insert your own calls to "ShowBar".
- Il-drill isfel jaħdem billi toħloq <a href> bħal dan: http://server/List?FilterField1=fieldname&FilterValue1=actualFilterValue. This technique may be of value in other contexts. Fl-ewwel, Ħsibt I bżonn biex jikkonformaw ma 'format aktar kumplessi: 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.
Hawnhekk huwa:
<XSL:stylesheet Verżjoni="1.0" jeskludu-riżultat-prefissi="rs z o i ddwrt dt msxsl" |
Ir-Riżultati:
Il XSL minn fuq jiġġenera dan il-graff:
Drill stabbiliti għad-data sottostanti billi tikklikkja fuq l-status code:
Ħsibijiet konklużivi:
Jista 'dan jiġi Ġeneralizzata?
I love dan il-kunċett 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, jekk jogħġbok ħu nota fil-kummenti jew email me.
Grafiċi vertikali:
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 🙂
Naħseb li l-isfida ma graff vertikali hija li t-tikketti għall-graff huma aktar diffiċli biex tamminstrahom, iżda ċertament mhux impossibbli.
Isem il-Qasam Gotcha tal:
Hemm mill-inqas żewġ affarijiet li għandek toqgħod attent għal mal-qasam ismijiet tiegħek.
Ewwel, a field name with a space has to be escaped in the XSL. This will probably be an issue here:
<XSL:varjabbli isem="totalProposed"
tagħżel="joqgħod(/dsQueryResponse / Ringieli / Ringiela[jinnormalizzaw l-ispazju(@ Status) = "Proposti"])" />
If your "Status" column is actually named "Status Code" then you need to reference it as "Status_x0020_Code":
<XSL:varjabbli isem="totalProposed"
tagħżel="joqgħod(/dsQueryResponse / Ringieli / Ringiela[jinnormalizzaw l-ispazju(@ Status_x0020_Code) = "Proposti"])" />Tieni, u jien fuzzy ftit fuq dan, but you also need to be on the alert for field name changes. If you name your field "Status Code" u mbagħad aktar tard, 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" rabtiet jistgħu jgħinu dijanjosi u jikkoreġu dan it-tip ta 'problema.
Dwar dak Kulur:
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. Per eżempju, if the percentage of "stalled" Tal-AFE huwa > 10% mbagħad juru dan aħmar, otherwise show it in black. Użu <XSL:jagħżlu> biex dan jintlaħaq.
Riżorsi oħra:
- Iddetermina l-isem intern (u info oħra tajba) għad-data fil-lista: http://paulgalvin.spaces.live.com/blog/cns!1CC1EDB3DAA9B8AA!134.entry
- Uri d-data kollha pprovduti mill SharePoint (l-XML prima): http://paulgalvin.spaces.live.com/blog/cns!1CC1EDB3DAA9B8AA!190.entry
- Niżżel l-espressjoni XPath ta 'kolonna speċifika: http://paulgalvin.spaces.live.com/blog/cns!1CC1EDB3DAA9B8AA!155.entry
- Approċċ ieħor bl OWA(?). I have not dug into it, iżda jistenna promettenti, speċjalment għall-mapep pie: http://www.waka.dk/Blog/PermaLink,guid,e2532e71-d774-4ac9-8f25-883964b830f4.aspx
Happy trasformazzjoni!
<aħħari />