Search code examples
jqplottapestrypie-chart

Tapestry: How to put options into jqplot Pie chart


My pie chart is displayed in percentages and the legend is outside the pie chart, at the bottom. I would like the label of pie chart to be in numbers and the legend to be inside the pie chart, to the east. I would like to change the color of the pie chart as well. I tried using "params=pieOptions" but it is not working. The params is being displayed in the div element. It shouldn't be. Here is what I have tried.

public JSONObject getPieOptions() 
{
   JSONObject json = new JSONObject();
   JSONObject legend =new JSONObject();
   legend.put("show", new JSONLiteral("true"));
   legend.put("location", "e");
   json.put("legend", legend);


   JSONObject options = new JSONObject();
   options.put("options", json);
   return options;
}

Any help would be much appreciated. Thanks.


Solution

  • The solution I use is to directly change the JqPlotPie.java file in the tapestry5-jqplot project. As Nathan has mentioned, there seems to be no params parameter in the pie component. Here is the code fragment of changes I have done.

    @Parameter(name = "seriesColor", required = false, defaultPrefix = BindingConstants.PROP)
    private List<String> seriesColor;
    
    
    renderer.put("rendererOptions",new JSONLiteral("{showDataLabels: true, dataLabels:'value'}"));
    
    options.put("legend", new JSONObject("{ show:true, 
                 rendererOptions: { numberRows: 3 }, location: 'e' }")); //Remove placement
    
    if(seriesColor != null && seriesColor.size()>0) 
    {
        JSONArray series = new JSONArray();
        for(String currentLabel: seriesColor) 
        {
            series.put(currentLabel);
        }
    
        options.put("seriesColors",series);
    }