2

I am implementing Struts 2 JQuery pie charts. I don't know how set custom colors for the chart. In backend I just create map with key as String and value as integer. What attribute I should use for setting custom color or how to set custom color in the pie chart.

My code is:

<sjc:chart
    id="chartPie2"
    cssStyle="width: 600px; height: 400px;"
    legendShow="false"
    pie="true"
    pieLabel="true"
    pieInnerRadius="0.3"
    pieLabelRadius="0.6"
    pieLabelBackgroundColor="#555"
    pieLabelBackgroundOpacity="0.7"
>
    <s:iterator value="%{pieDataMap}">
        <sjc:chartData
            label="%{key}"
            data="%{value}"
        />
    </s:iterator>
</sjc:chart>

BackEnd:

   Map<Integer, Integer> pieDataMap = new TreeMap<String, Integer>();
   pieDataMap.put("Java", 18);
   pieDataMap.put("C", 17);
   pieDataMap.put("C++", 10);
   pieDataMap.put("PHP", 8);
   pieDataMap.put("(Visual) Basic", 6);
   pieDataMap.put("C#", 5);
4

1 回答 1

0

该标签<sjc:chartData>具有color您可以在迭代地图时设置的属性。为此,您需要修改集合以包含您的系列的颜色。

public class Pie {
  private String name;
  private String color;
  //getters setters and full constructor here    
} 

然后放物体

pieDataMap.put(18, new Pie("Java","#990033"));
...

之后更改迭代器

<s:iterator value="%{pieDataMap}">
    <sjc:chartData
        label="%{value.name}"
        data="%{key}"
        color="%{value.color}"
    />
</s:iterator>
于 2013-09-07T08:16:14.780 回答