问题
From the following VAADIN Charts Demo Link you can see a basic bar graph,
https://demo.vaadin.com/charts/#BasicColumn
The colors of the bars we can see here are coming from CSS file and not the JAVA Source Code File. Is there no way possible to set or get the colors for this bars?
Please Note:
1) I cannot use DataSeries instead of ListSeries, since with Data Series achieving a view like the one shown in the above link is not possible(or I am not aware of).
2) I have already checked other stack overflow questions similar to mine but none of them could answer this question.
回答1:
I have found the solution to my above problem. Now I can set colors of my choice in the Bars of the Bargraph involving ListSeries.
PlotOptionsColumn is the answer.
//Hard Coded Values
String months[] = { "DataSet 1", "DataSet 2", "DataSet 3", "DataSet 4", "DataSet 5"};
int dataArray[][] = {
{ 8, 13, 7, 4 },
{ 23, 1, 30, 7 },
{ 37, 3, 22, 2 },
{ 13, 23, 4, 3 },
{ 3, 10, 9, 5 },
};
int counter = 0;
// Data series for each numeric column in the table
for (int month = 0; month < 4; month++) {
ListSeries series = new ListSeries();
PlotOptionsColumn options = new PlotOptionsColumn();
options.setColor(colors[counter++]);
series.setPlotOptions(options);
series.setName(months[month]);
// The rows of the table
for (int data = 0; data < dataArray.length; data++) {
series.addData(dataArray[data][month]);
}
conf.addSeries(series);
}
来源:https://stackoverflow.com/questions/39718729/set-or-get-color-for-listseries-in-vaadin-charts