-
-
Save arruda/78453a5a55fc63284126 to your computer and use it in GitHub Desktop.
A simple JSF Tag example for optimizing the usage of JayFlot.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
<myTags:JayFlot_CheckBoxTag_JSF | |
plot="#{myManageBean.myPlot}" | |
placeholder="placeholder" | |
width="600" height="300" | |
/> | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | |
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml" | |
xmlns:h="http://java.sun.com/jsf/html" | |
xmlns:ui="http://java.sun.com/jsf/facelets" | |
xmlns:c="http://java.sun.com/jstl/core" | |
> | |
<ui:composition> | |
<script language="javascript" type="text/javascript" src="/yourProject/js/jquery-1.5.1.js"></script> | |
<script language="javascript" type="text/javascript" src="/yourProject/js/flot/jquery.flot.js"></script> | |
<script language="javascript" type="text/javascript" src="/yourProject/js/flot/jquery.flot.axislabels.js"></script> | |
<table id="choices" style="font-weight: bold"><tr ><td>Show:</td></tr></table> | |
<div id="#{placeholder}" style="width:#{width}px;height:#{height}px"></div> | |
<script language="javascript" type="text/javascript"> | |
var $j = jQuery.noConflict(); | |
$j(function () { | |
var datasets = {}; | |
<c:if test="${plot != null}"> | |
datasets = #{plot.printData}; | |
</c:if> | |
// hard-code color indices to prevent them from shifting as | |
// datas are turned on/off | |
var i = 0; | |
$j.each(datasets, function(key, val) { | |
val.color = i; | |
++i; | |
}); | |
// insert checkboxes | |
var choiceContainer = $j("#choices"); | |
var iterator = 0; | |
$j.each(datasets, function(key, val) { | |
if(iterator % 2==0){ | |
choiceContainer.append('<td style="padding-right: 10px"><input type="checkbox" name="' + key + | |
'" checked="checked" id="id' + key + '"/>' + | |
'<label for="id' + key + '">' | |
+ val.label + '</label></td>'); | |
} | |
}); | |
choiceContainer.find("input").click(plotAccordingToChoices); | |
function plotAccordingToChoices() { | |
var data = []; | |
choiceContainer.find("input:checked").each(function () { | |
var key = $j(this).attr("name"); | |
if (key) | |
if (datasets[key]) | |
data.push(datasets[key]); | |
}); | |
if (maiorQue(data.length, 0)) | |
$j.plot($j("##{placeholder}"), data, #{plot.printOptions}); | |
} | |
plotAccordingToChoices(); | |
}); | |
</script> | |
</ui:composition> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment