I found the fix passing the arguments like javascript objects, this is my
code Taha :
<code>
@Import(library = {
"context:js/jqplot/jquery.jqplot.min.js", // jqplot base
"JQPlotInit.js",
"context:js/jquery-ui-resizable-1.8.6.min.js",// resize
"context:js/jqplot/jqplot.canvasTextRenderer.min.js",
"context:js/jqplot/jqplot.canvasAxisLabelRenderer.min.js",
"context:js/jqplot/jqplot.canvasAxisTickRenderer.min.js", // Permite
rotar los datos de los ejes
"context:js/jqplot/jqplot.categoryAxisRenderer.min.js",
"context:js/jqplot/jqplot.pointLabels.min.js", // pinta los valores
arriba de las barras
"context:js/jqplot/jqplot.barRenderer.min.js" //Pinta las series como
barras
},
stylesheet = {
"context:css/jqplot/jquery.jqplot.min.css", // css jqplot
"context:css/ui-lightness/jquery-ui-1.8.6.resizable.css" // css resize
})
public class PlotVBar {
// Datos que serán graficados, formato: [['uno',1],['dos',2],['tres',3]]
@Parameter(required = true)
private JSONArray _data;
// Título de la gráfica
@Parameter(defaultPrefix = "literal")
private String _titulo;
// Etiqueta que se mostrará en el eje X
@Parameter(defaultPrefix = "literal")
private String _labelX;
// Etiqueta que se mostrará en el eje Y
@Parameter(defaultPrefix = "literal")
private String _labelY;
// Indica si se desea rotar 30° a la izquierda las etiquetas del eje X,
este parámetro debe
// ser establecido cuando sean muy largas las etiquetas del eje X, por
ejemplo en una pregunta
// de opciones
@Parameter
private boolean _rotarEtiquetasX;
// Indica los colores que tendrán las barras. Si sólo se indican 2
colores y hay
// 6 barras entonces se repitirán esos 2 colores 3 veces
@Parameter
private String[] _colores;
// Opciones de las gráficas
private JSONObject options;
@Inject
private JavaScriptSupport jsSupport;
void setupRender() {
////////////////////////////////////////////////////////////////////////
// GRÁFICA
////////////////////////////////////////////////////////////////////////
options = new JSONObject();
options.put("title", _titulo);
if (_colores != null) {
options.put("seriesColors", WUtils.toJSONArray(_colores)); //
Array con los colores de las barras
}
////////////////////////////////////////////////////////////////////////
// DATOS
////////////////////////////////////////////////////////////////////////
JSONArray series = new JSONArray();
options.put("series", series);
JSONObject renderer = new JSONObject();
series.put(renderer);
renderer.put("renderer", new
JSONLiteral("jQuery.jqplot.BarRenderer")); // Renderiza los datos como
barras
renderer.put("rendererOptions", new JSONObject().put("varyBarColor",
true)); // Cada barra tiene un color distinto, los colores se definen en
"seriesColors"
////////////////////////////////////////////////////////////////////////
// DEFAULT EN LOS EJES (X,Y)
////////////////////////////////////////////////////////////////////////
JSONObject axesDefaults = new JSONObject();
options.put("axesDefaults", axesDefaults);
axesDefaults.put("labelRenderer", new
JSONLiteral("jQuery.jqplot.CanvasAxisLabelRenderer"));
JSONObject tickOptions = new JSONObject();
axesDefaults.put("tickOptions", tickOptions);
tickOptions.put("fontSize", "10pt");
if (_rotarEtiquetasX) {
tickOptions.put("angle", "-20"); // Rota las etiquetas 30° a la
izquierda
}
tickOptions.put("formatString", "%d"); // Todos los valores que
muestra son enteros
JSONObject axes = new JSONObject();
options.put("axes", axes);
////////////////////////////////////////////////////////////////////////
// EJE X
////////////////////////////////////////////////////////////////////////
JSONObject xaxis = new JSONObject();
axes.put("xaxis", xaxis);
xaxis.put("renderer", new
JSONLiteral("jQuery.jqplot.CategoryAxisRenderer"));
xaxis.put("tickRenderer", new
JSONLiteral("jQuery.jqplot.CanvasAxisTickRenderer"));
xaxis.put("label", _labelX);
////////////////////////////////////////////////////////////////////////
// EJE Y
////////////////////////////////////////////////////////////////////////
JSONObject yaxis = new JSONObject();
axes.put("yaxis", yaxis);
yaxis.put("label", _labelY);
yaxis.put("min", 0); // El eje y empieza en 0
}
void beginRender(MarkupWriter writer) {
// div que contiene la gráfica para hacer resize
writer.element("div",
"id", "resizablediv",
"class", "ui-widget-content",
"align", "center",
"style", "width: 400px; height: 300px;margin-top:
2em;margin-bottom: 2em;");
// div que contiene la gráfica
writer.element("div",
"id", "chartdiv",
"style", "height:96%; width:96%;");
// [object: array], [object: jsonobject]
jsSupport.addScript("new JQPlot(%s,%s);", _data.toCompactString(),
options.toCompactString());
}
void afterRender(MarkupWriter writer) {
writer.end(); // </div> id=chartdiv
writer.end(); // </div> id=resizablediv
}
}
</code>
--
View this message in context:
http://tapestry.1045711.n5.nabble.com/T5-2-6-JSONLiteral-Bug-tp4584187p4618258.html
Sent from the Tapestry - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]