C.Carol
(C. C.)
August 1, 2017, 8:59am
#1
Hi,
I want to give to my pie chart a colors array, but I do not know how to code it correctly.
What I tried (but did not work of course) :
<chart:serialChart id="chart"
categoryField="year"
creditsPosition="bottom-left"
height="100%"
width="100%"
<b> colors="["#42f486", "#ea36f7"]"</b>>
And I got an other question. how to disable the text next to the chart?
Like here , the “New” and the “Returning” text?
I have a legend part next to the pie chart and I think it do not looks well if texts are twice.
Thanks
C.Carol
(C. C.)
August 1, 2017, 11:04am
#2
Okay, I could solve the second problem with that: labelsEnabled=“false”
C.Carol
(C. C.)
August 2, 2017, 7:37am
#3
For the other problem, to set the pieChart’s slices colors, I found in documentation , that I can set in the Controller. So I inserted this to my controller:
@Inject
private Chart piechart;
@Override
public void init(Map<String, Object> params) {
piechart.setColors(Arrays.asList(
Color.valueOf("#446493"),
Color.valueOf("#5E3D2C"),
Color.valueOf("#D0A557")));
}
But I get an error: setColors is undefined…
C.Carol
(C. C.)
August 2, 2017, 12:38pm
#4
Okay I could make it with that:
((PieChart) piechart).setColors(Arrays.asList(
Color.valueOf("#18db38"),
Color.valueOf("#ce1616")));
artamonov
(Yuriy Artamonov)
August 2, 2017, 2:08pm
#5
Hi,
If you want to set colors declaratively use colors tag instead of property:
<chart:serialChart height="100%"
width="100%"
categoryField="id">
<chart:colors>
<chart:color value="BLUE"/>
<chart:color value="GREEN"/>
</chart:colors>
<chart:data>
<chart:item>
<chart:property name="id" value="1" type="int"/>
<chart:property name="value1" value="1" type="int"/>
<chart:property name="value2" value="4" type="int"/>
</chart:item>
<chart:item>
<chart:property name="id" value="2" type="int"/>
<chart:property name="value1" value="4" type="int"/>
<chart:property name="value2" value="3" type="int"/>
</chart:item>
<chart:item>
<chart:property name="id" value="3" type="int"/>
<chart:property name="value1" value="3" type="int"/>
<chart:property name="value2" value="9" type="int"/>
</chart:item>
</chart:data>
<chart:graphs>
<chart:graph valueField="value1"/>
<chart:graph valueField="value2"/>
</chart:graphs>
</chart:serialChart>
In case of programmatic changes I recommend that you inject your chart using typed reference, for instance:
@Inject
private SerialChart myChart;
...
myChart.setColors(Arrays.asList(
Color.AQUAMARINE,
Color.ALICEBLUE)
);
If you use Intellij Idea IDE, you can simply use Code - Generate - Inject menu (or Alt+Insert shortcut) to insert fields with @Inject annotation.
1 Like