0
votes

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.

1
Are you using tapestry5-jqPlot library? Because there seems to be no "params" parameter on the component. Maybe you can raise an issue on the github of the library and ask for this possibility to be built in.Nathan Q

1 Answers

0
votes

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);
}