Jump to content
We've recently updated our Privacy Statement, available here ×
  • How to add a Threshold line in an HTML5 chart (a.k.a Highchart)


    stasp
    • Version: v6.4.2, v6.4.0, v6.3, v6.2.1 Product: JasperReports® Server

    Use case description

    There is more than one way to add a threshold line to a chart. For example, the simplest one is just add another measure to your chart and then hide it from legend using the showInLegend advanced property:

    showinlegend.png.2c42e8010e7f939e3a8aa43a5cab3e3e.png

    The solution suggest below is probably the one the gives report developer the most control over the threshold line layout.


    Solution

    You can add thresholds to the charts as plotlines instead of measures. The Jaspersoft Studio user interface does not provide a good option to add a plotline at the moment. It has to be passed as a function with an array of values, and it's best added directly to XML and looks like this: 

    <hc:chartProperty name="yAxis.plotLines">
        <hc:propertyExpression>
            <![CDATA["function(){return [{ color: 'red', 
                                           value: 2500, 
                                           dashStyle: 'longdashdot',
                                           width: 2},
                                         { color: 'green',
                                           value: 7500,
                                           dashStyle: 'longdashdot',
                                           width: 2}
                                        ]}()"]]>
        </hc:propertyExpression>
    </hc:chartProperty>
    

    See also the attached sample report that demonstrates this.

    One more thing to keep in mind is that in order to use functions with HTML5 charts you have to enable the following property:

    com.jaspersoft.jasperreports.highcharts.function.properties.allowed=true

    For JasperReports Server this property has to be added in .../WEB-INF/classes/jasperreports.properties file. Make sure to save the changes and restart the application server for the property to take effect.

    In Studio this property has to be added under Window->Preferences->Jaspersoft Studio->Properties

    plotlines_0.jrxml


    User Feedback

    Recommended Comments

    There are no comments to display.



    Guest
    This is now closed for further comments

×
×
  • Create New...