Aylıq Arxiv: Dekabr 2007

SharePoint ilə Bar grafik yaratmaq

Baxış:

(UPDATE 12/04/07: Çox maraqlı bir web hissəsi vasitəsilə bu müraciət ki, bir blog keçid sonunda bir maraqlı resurs Əlavə)

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:

  1. Create a list or document library that contains the data you want to graph.
  2. Place the associated document library / custom list onto a page and convert it to a data view web part (DVWP).
  3. Modify the DVWP’s XSL to generate HTML that shows as a graph.

Biznes Ssenari / Setup:

Mən standart Title sütun və bir əlavə sütun ilə xüsusi bir siyahısını yaratdıq,,en,"Status",,en,bu modellər,,en,çox simplistically,,en,Xərcləri üçün bir "Avtorizasiya,,en,title layihə və statusu siyahıdan bir dəyər təmsil ssenari,,en,Təklif olunan,,en,Prosesində,,en,dayandırılıbdır,,en,obyektiv, bu status kodları göstərir ki, interaktiv üfüqi bar grafik istehsal edir,,en,Mən siyahısını əhalisi var və bu kimi görünür,,en,Data View Web Part yarat,,en,Bir səhifə üçün xüsusi siyahı əlavə DVWP yarat,,en,mənim halda site səhifə,,en,və təlimatlara əməl edin,,en,Bundan əlavə, sadəcə DVWP yaratmaq üçün,,en,biz də bütün mövcud satır göstərmək paging əmlak qurmaq lazımdır,,en,bu kimi bir şey görünür,,en,Mən həmişə yaxın SPD və browser,,en,Mən browser istifadə edərək səhifə yenidən açmaq,,en, "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:

image

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 burada (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. Mənim üçün, this looks something like this:

image

Bu noktada, 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. (Görmək burada 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

Mənə gəldikdə isə, bu kimi görünür:

image

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.

Bu məqsədlə, 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:

Sample Bar Graph

Corresponding HTML:

<html>
<orqan>
<mərkəz>
<table width=80%>
<tr><TD><mərkəz>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 = red><TD>&nbsp;</TD></tr></masa></TD>
</tr>
<tr>
<td width=10%>Qapalı</TD>
<TD><table cellpadding="0" cellspacing="0" border=0 width=25%><tr bgcolor = red><TD>&nbsp;</TD></tr></masa></TD>
</tr>
<tr>
<td width=10%>Stalled</TD>
<TD><table cellpadding="0" cellspacing="0" border=0 width=25%><tr bgcolor = red><TD>&nbsp;</TD></tr></masa></TD>
</tr>
</masa>
</TD>
</tr>
</masa>
</orqan>
</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: Sonda, 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). Lakin, 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. Sonra, remove my calls and insert your own calls to "ShowBar".
  • The drill down works by creating an <a href> like this: http://server/List?FilterField1=fieldname&FilterValue1=actualFilterValue. This technique may be of value in other contexts. Əvvəlcə, 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 variant="1.0" exclude-result-prefixes="rs z o s ddwrt dt msxsl" 
xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:XSL="http://www.w3.org/1999/XSL/Transform"
xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer"
xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime"
xmlns:bu="urn:schemas-microsoft-com:idarə" xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882"
xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema"
xmlns:ddwrt2="urn:frontpage:internal"
> <XSL:output üsul="html" indent="no" /> <XSL:Mexanizmi Boylam decimal format NaN="" /> <XSL:Param ad="ListUrlDir"></XSL:Param> <!-- I need this to support a drill-down. --> <XSL:şablon matç="/" xmlns:SharePoint="Microsoft.SharePoint.WebControls"
xmlns:__designer=http://schemas.microsoft.com/WebParts/v2/DataView/designer xmlns:asp="http://schemas.microsoft.com/ASPNET/20"
> <XSL:dəyişən ad="dvt_StyleName">Masa</XSL:dəyişən> <XSL:dəyişən ad="Rows" seçmək="/dsQueryResponse/Rows/Row" /> <XSL:dəyişən ad="dvt_RowCount" seçmək="count($Rows)" /> <XSL:dəyişən ad="IsEmpty" seçmək="$dvt_RowCount = 0" /> <XSL:dəyişən ad="dvt_IsEmpty" seçmək="$dvt_RowCount = 0" /> <XSL:seçmək> <XSL:zaman sınaq="$dvt_IsEmpty"> There is no data to graph!<br/> </XSL:zaman> <XSL:başqa cür> <!-- The interesting stuff begins here. We need to define a pair of variables for each row in the graph: total number of items and percent of total. --> <XSL:dəyişən ad="totalProposed" seçmək="count(/dsQueryResponse/Rows/Row[normalize-space(@Status) = 'Proposed'])" /> <XSL:dəyişən ad="percentProposed" seçmək="$totalProposed div $dvt_RowCount" /> <XSL:dəyişən ad="totalInProcess" seçmək="count(/dsQueryResponse/Rows/Row[normalize-space(@Status) = 'In Process'])" /> <XSL:dəyişən ad="percentInProcess" seçmək="$totalInProcess div $dvt_RowCount" /> <XSL:dəyişən ad="totalStalled" seçmək="count(/dsQueryResponse/Rows/Row[normalize-space(@Status) = 'Stalled'])" /> <XSL:dəyişən ad="percentStalled" seçmək="$totalStalled div $dvt_RowCount" /> <!-- We define our HTML table here. I'm borrowing from some standard SharePoint styles here to make it consistent. I think it will honor changes to the global css file as well as theme overrides. --> <masa en="100%" cellspacing="0" cellpadding="2" üslub="border-right: 1 solid #C0C0C0; border-bottom: 1 solid #C0C0C0; border-left-style: solid; border-left-width: 1; border-top-style: solid; border-top-width: 1;"> <tr> <TD align="mərkəz"> <masa sərhəd="1" en="100%"> <!-- For each status that we want to graph, we call the "ShowBar" şablon. We pass it: 1. A label for the row. This is transformed into a hyperlink. 2. The percent (variable from above). 3. The actual field name of the code from the underlying list. This does not need to match the display label. 4. Field value matched for #3. 5. Total items of this status code (not the grand total of all status codes). It emits a <tr></tr> and the horizontal bar graph line. We call this template for each status code we want to view. --> <XSL:Zəng şablon ad="ShowBar"> <XSL:ilə-Param ad="BarDisplayLabel" seçmək="'Proposed'"/> <XSL:ilə-Param ad="BarPercent" seçmək="$percentProposed"/> <XSL:ilə-Param ad="QueryFilterFieldName" seçmək="'Status'"/> <XSL:ilə-Param ad="QueryFilterFieldValue" seçmək="'Proposed'"/> <XSL:ilə-Param ad="TotalItems" seçmək="$totalProposed"></XSL:ilə-Param> </XSL:Zəng şablon> <XSL:Zəng şablon ad="ShowBar"> <XSL:ilə-Param ad="BarDisplayLabel" seçmək="'Stalled'"/> <XSL:ilə-Param ad="BarPercent" seçmək="$percentStalled"/> <XSL:ilə-Param ad="QueryFilterFieldName" seçmək="'Status'"/> <XSL:ilə-Param ad="QueryFilterFieldValue" seçmək="'Stalled'"/> <XSL:ilə-Param ad="TotalItems" seçmək="$totalStalled"></XSL:ilə-Param> </XSL:Zəng şablon> <XSL:Zəng şablon ad="ShowBar"> <XSL:ilə-Param ad="BarDisplayLabel" seçmək="'In Process'"/> <XSL:ilə-Param ad="BarPercent" seçmək="$percentInProcess"/> <XSL:ilə-Param ad="QueryFilterFieldName" seçmək="'Status'"/> <XSL:ilə-Param ad="QueryFilterFieldValue" seçmək="'In Process'"/> <XSL:ilə-Param ad="TotalItems" seçmək="$totalInProcess"></XSL:ilə-Param> </XSL:Zəng şablon> </masa> </TD> </tr> </masa> </XSL:başqa cür> </XSL:seçmək> </XSL:şablon> <!-- This template does the work of displaying individual lines in the bar graph. You'll probably do most of your tweaking here. --> <XSL:şablon ad="ShowBar"> <XSL:Param ad="BarDisplayLabel" /> <!-- label to show --> <XSL:Param ad="BarPercent"/> <!-- Percent of total. --> <XSL:Param ad="QueryFilterFieldName"/> <!-- Used to jump to the query & filter --> <XSL:Param ad="QueryFilterFieldValue"/> <!-- Used to jump to the query & filter --> <XSL:Param ad="TotalItems" /> <!-- total count of this barlabel --> <tr> <!-- The bar label itself. --> <TD sinfi="ms-formbody" en="30%"> <!-- This next set of statements builds a query string that allows us to drill down to a filtered view of the underlying data. We make use of a few things here: 1. We can pass FilterField1 and FilterValue1 to a list to filter on a column. 2. SharePoint is passing a key parameter to us, ListUrlDir that points to the underlying list against which this DVWP is "running". Isn't XSL fun? --> <XSL:text aradan çıxdı-qaçan="bəli"> <![CDATA[<a href ="]]></XSL:text> <XSL:dəyər və seçmək="$ListUrlDir"/> <XSL:text aradan çıxdı-qaçan="bəli"><![CDATA[?FilterField1=]]></XSL:text> <XSL:dəyər və seçmək="$QueryFilterFieldName"/> <XSL:text aradan çıxdı-qaçan="bəli"><![CDATA[&FilterValue1=]]></XSL:text> <XSL:dəyər və seçmək="$QueryFilterFieldValue"/> <XSL:text aradan çıxdı-qaçan="bəli"><![CDATA[">]]></XSL:text> <XSL:dəyər və seçmək="$BarDisplayLabel"/> <XSL:text aradan çıxdı-qaçan="bəli"><![CDATA[</bir>]]></XSL:text> <!-- The next bit shows some numbers in the format: "(total / % of total)" --> (<XSL:dəyər və seçmək="$TotalItems"/> / <!-- This creates a nice percent label for us. Təşəkkür, Microsoft! --> <XSL:Zəng şablon ad="percentformat"> <XSL:ilə-Param ad="percent" seçmək="$BarPercent"/> </XSL:Zəng şablon>) </TD> <!-- Nəhayət, emit a <TD> tag for the bar itself.--> <TD> <masa cellpadding="0" cellspacing="0" sərhəd="0" en="{round($BarPercent*100)+1}%"> <tr bgcolor="red"> <XSL:text aradan çıxdı-qaçan="bəli"><![CDATA[&nbsp;]]></XSL:text> </tr> </masa> </TD> </tr> </XSL:şablon> <!-- This is taken directly from some XSL I found in an MS template. --> <XSL:şablon ad="percentformat"> <XSL:Param ad="percent"/> <XSL:seçmək> <XSL:zaman sınaq="format nömrəsi($percent, '#,##0%;-#,##0%')= 'NaN'">0%</XSL:zaman> <XSL:başqa cür> <XSL:dəyər və seçmək="format nömrəsi($percent, '#,##0%;-#,##0%')" /> </XSL:başqa cür> </XSL:seçmək> </XSL:şablon> </XSL:stylesheet>

The Results:

The XSL from above generates this graph:

image

Drill down to the underlying data by clicking on the status code:

image

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 Mənə e-poçt.

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.

Ilk, a field name with a space has to be escaped in the XSL. This will probably be an issue here:

        <XSL:dəyişən ad="totalProposed" 
seçmək="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:dəyişən ad="totalProposed" 
seçmək="count(/dsQueryResponse/Rows/Row[normalize-space(@Status_x0020_Code) = 'Proposed'])" />

Ikinci, 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. Məsələn, if the percentage of "stalled" AFE’s is > 10% then show it red, otherwise show it in black. Istifadə <XSL:seçmək> to accomplish this.

Other Resources:

Happy transforming!

<Tamamlama />

Blog abunə!

SharePoint vermir “Kim çata” Hesabatlar

UPDATE 01/28/08: Bu codeplex layihə bu sorunu giderir: http://www.codeplex.com/AccessChecker. I have not used it, Bu, ətraf mühit müraciət etmək lazımdır məsələ əgər ancaq perspektivli görünür.

UPDATE 11/13/08: Joel Oleson burada böyük təhlükəsizliyinin idarə məsələ ilə bağlı çox yaxşı bir ismarıc qədər yazıb: http://www.sharepointjoel.com / siyahısı / İsmarıclar / Post.aspx?List=0cd1a63d-183c-4fc2-8320-ba5369008acb&Id = 113. It links to a number of other useful resources.

Forum istifadəçiləri və müştərilərə tez-tez bu xətt boyunca bir sual: "How do I generate a list of all users with access to a site" or "How can I automatically alert all users with access to list about changes made to the list?"

There is no out of the box solution for this. If you think about it for a moment, o niyə anlamaq çətin deyil.

SharePoint security is very flexible. There are at least four major categories of users:

  • Gizli istifadəçilər.
  • SharePoint İstifadəçilər və Qruplar.
  • Active Directory istifadəçilər.
  • Əsaslı Authentication təşkil edir (FBA) istifadəçilər.

Rahatlıq deməkdir ki, təhlükəsizlik baxımından, any given SharePoint site will be dramatically different from another. In order to generate an access list report, bir saytda təmin necə müəyyən etmək lazımdır, query multiple different user profile repositories and then present it in a useful fashion. That’s a hard problem to solve generically.

Necə təşkilatlar bu ilə məşğul olur? I’d love to hear from you in comments or e-poçt.

</son>