Regarding adjusting height of p:stackedBarChart dynamically

UI Components for JSF
Post Reply
User avatar
skillassert
Posts: 12
Joined: 06 Sep 2009, 21:18

22 Oct 2009, 20:32

We have a stackedBarChart as below in which the number of items in the List completedJaxbExam.score.scoretag can be from 1 to 20.

Code: Select all

  <p:stackedBarChart value="#{completedJaxbExam.score.scoretag}" var="st"
                                yfield="#{st.name}" styleClass="stackedbar" style="chartStyle">
                <p:chartSeries label="Correct" value="#{st.correct}"/>
                <p:chartSeries label="Wrong" value="#{st.wrong}" />
  </p:stackedBarChart>
Hence specifying a fixed width and height in the CSS class stackedbar may not make the chart look good when the number of scoretags is too high or too low. Is there some way to specify the height of the stackedBarChart (width can be controlled by maxX and minX attributes) as a multiple of number of scoretags? ie something similar to below code where width is an attribute which we would like to have.

Code: Select all

<p:stackedBarChart value="#{completedJaxbExam.score.scoretag}" var="st" width="#{completedJaxbExam.scoretagcount*30}"
                                yfield="#{st.name}" styleClass="stackedbar" style="chartStyle">

User avatar
skillassert
Posts: 12
Joined: 06 Sep 2009, 21:18

23 Oct 2009, 20:07

If this will be of any use for some one in future, here is how I did it. For stackedBarChart please make the height to be a dynamic value

Code: Select all

   <ui:repeat value="#{completedJaxbExam.score.scoretag}" var="scoret">
                <pf:outputPanel rendered="#{NULL != scoret.subtag}">
                    <style>
                        .stacked#{scoret.name}{
                            width:#{200+scoret.subtag.size()*70}px;
                            height:300px;
                        }
                    </style>
                    <b> #{scoret.name} - Strength and weakness analysis</b>
                </pf:outputPanel>


                <pf:stackedColumnChart  value="#{scoret.subtag}" var="subtag" rendered="#{NULL != scoret.subtag}"
                                       xfield="#{subtag.name}" styleClass="stacked#{scoret.name}" style="chartStyle">
                    <pf:chartSeries label="Correct" value="#{subtag.correct}" style="correctStyle"/>
                    <pf:chartSeries label="Wrong" value="#{subtag.wrong}" style="wrongStyle"/>
                </pf:stackedColumnChart>
            </ui:repeat>

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 40 guests