Start a new topic
Answered

Accumulated bar chart

I want to make a chart for accumulated test results


image


Is there a way to use the script language to achieve this?



Best Answer

Below is a simple example using the configurable charts to achieve this. The example uses the following model:

image

A workarea containing documents and sections. Each section has an attribute containing a status. The chart will show each document and the amount of sections having ‘OK’ and not ‘OK’ statuses.

image

Applying the following script on the workarea:

  

<Charts>
  <AreaChart>
    <Slices>
      <Slice name="first" caption="OK" color="green"/>
      <Slice name="second" caption="Not OK" color="red"/>
    </Slices>                                      

    <!-- For each document -->
    <ForEachPart type="IDI">
      <DefObj>
        <!-- the counter make up each entry on the x axis -->
        <Counter name="#{Name}" caption="#{Name}">
          <!-- filter out all sections with attribute value 'OK' -->
          <ForEach select="/IRRS[@PTCS='OK']">
            <AddToSlice name="first"/>
          </ForEach>
          <!-- filter out all sections that have attribute value seperate from 'OK' -->
          <ForEach select="/IRRS[not @PTCS='OK']">
            <AddToSlice name="second"/>
          </ForEach>
        </Counter>
      </DefObj>
    </ForEachPart>
  </AreaChart>
</Charts> 

  Gives the following result:

image


Using an <AreaChart> will give an Area chart. The counter represents each entry on the x axis. Adding sections with specific properties to the counter makes up the height of each area. 




Answer

Below is a simple example using the configurable charts to achieve this. The example uses the following model:

image

A workarea containing documents and sections. Each section has an attribute containing a status. The chart will show each document and the amount of sections having ‘OK’ and not ‘OK’ statuses.

image

Applying the following script on the workarea:

  

<Charts>
  <AreaChart>
    <Slices>
      <Slice name="first" caption="OK" color="green"/>
      <Slice name="second" caption="Not OK" color="red"/>
    </Slices>                                      

    <!-- For each document -->
    <ForEachPart type="IDI">
      <DefObj>
        <!-- the counter make up each entry on the x axis -->
        <Counter name="#{Name}" caption="#{Name}">
          <!-- filter out all sections with attribute value 'OK' -->
          <ForEach select="/IRRS[@PTCS='OK']">
            <AddToSlice name="first"/>
          </ForEach>
          <!-- filter out all sections that have attribute value seperate from 'OK' -->
          <ForEach select="/IRRS[not @PTCS='OK']">
            <AddToSlice name="second"/>
          </ForEach>
        </Counter>
      </DefObj>
    </ForEachPart>
  </AreaChart>
</Charts> 

  Gives the following result:

image


Using an <AreaChart> will give an Area chart. The counter represents each entry on the x axis. Adding sections with specific properties to the counter makes up the height of each area. 



The example used above is attached to this post.

xml

If a column chart is preferred, the configuration would be the same as described above except you would replace the <AreaChart> tag with <ColumnChart>. 

<Charts>
  <ColumnChart>
    <Slices>
      <Slice name="first" caption="OK" color="green"/>
      <Slice name="second" caption="Not OK" color="red"/>
    </Slices>                                      

    <!-- For each document -->
    <ForEachPart type="IDI">
      <DefObj>
        <!-- the counter make up each entry on the x axis -->
        <Counter name="#{Name}" caption="#{Name}">
          <!-- filter out all sections with attribute value 'OK' -->
          <ForEach select="/IRRS[@PTCS='OK']">
            <AddToSlice name="first"/>
          </ForEach>
          <!-- filter out all sections that have attribute value seperate from 'OK' -->
          <ForEach select="/IRRS[not @PTCS='OK']">
            <AddToSlice name="second"/>
          </ForEach>
        </Counter>
      </DefObj>
    </ForEachPart>
  </ColumnChart>
</Charts> 

 The result would be: 


image




2 people like this

Hello. I have noticed in a "R24 (20656)" release an interesting feature: <ColumnChart> which should solve the original issue with accumulated chart in a more straight-forward way. Any chance for update in this thread, @Martin?  

Hello Jakub! I think our paths crossed a bit. I have updated this topic to include the column chart example. Let us know if you need anything else! 


1 person likes this

Ha! I should update the window before writing my previous post! 


One more question in that case: Let's say we have "doc" items in a 3 different versions (e.g. 1,2,3), which we would like to include to that chart instead of using already available tools to compare different versions. Is there any variant-handling feature that we could us in that case?

Yes, you can handle versions. Using the same example, the configuration would look like this: 

<Charts>
	<ColumnChart>
		<Slices>
			<Slice name="first" caption="OK" color="green"/>
			<Slice name="second" caption="Not OK" color="red"/>
		</Slices>                                      

		<!--AllVersions: Returns all versions of an item.-->
		<ForEach select="AllVersions">    
			<Counter name="#{Name}" caption="#{Name} Version: #{Version}">

				<!-- For each document -->
				<ForEachPart type="IDI">
					<DefObj>
						<!-- the counter make up each entry on the x axis -->
						<!-- filter out all sections with attribute value 'OK' -->
						<ForEach select="/IRRS[@PTCS='OK']">
							<AddToSlice name="first"/>
						</ForEach>
						<!-- filter out all sections that have attribute value seperate from 'OK' -->
						<ForEach select="/IRRS[not @PTCS='OK']">
							<AddToSlice name="second"/>
						</ForEach>
					</DefObj>
				</ForEachPart>
			</Counter>
		</ForEach>
	</ColumnChart>
</Charts> 

 With the result being: 


image


As you can see, I updated the PTCS results a bit to illustrate a difference. 


image




1 person likes this

Perfect, thanks a lot!

I managed to adopt feedback from this thread and finally different versions are correctly listed on my chart. However, it becomes difficult to generate the proper graphs when I have to deal with different versions within a longer tree structure. Is there any possibility to compare e.g. time of release and create those graphs based on that (by reference to sth like "version attribute: date of release")?    

Hi Jakub,

 

I think one of the following path query methods or a combination of them would serve your need (you can find more information on the Help manual).


VersionNumber returns the version number of an item.

Example:

?> /IRRS
Result:
{sec2, sec1, sec3}

?> /IRRS.Select(VersionNumber)
Result:
[2, 1, 3]

 

Max returns the maximum value in a set of integer values.

Example:

?> /IRRS.Select(VersionNumber)
Result:
[2, 1, 3]

?> /IRRS.Select(VersionNumber).Max
Result:
3

 

MaxByDate() returns the objects from the list with the latest date property (required SystemWeaver R24).

Example:

?> /IRRS
Result:
{sec2, sec1, sec3}

?> /IRRS.MaxByDate(LastChanged)
Result:
[sec3]

?> /IRRS.MaxByDate(CreationDate)
Result:
[sec3]


Best Regards,

Bashar

 


1 person likes this

Hello,


Is there any way to show the counter caption on the x axis only and not once per slice in the bar chart? The chart area gets a bit crowded for charts with several counters and slices. And is it possible to have x axis captions rotated as in the top picture of this article?

Hello David,


Currently in SystemWeaver you can only configure the content of charts (PieChart, AreaChart and ColumnChart) not how they look like. So in short, no it is not  possible to show the counter caption on the x axis only.

Thanks,
Bashar


Login to post a comment