2016-09-27 29 views
0

从你可以看到一个基本的条形图以下VAADIN图表演示链接,设置或获取颜色在VAADIN图表ListSeries

https://demo.vaadin.com/charts/#BasicColumn

的,我们可以在这里看到酒吧的颜色从CSS文件来而不是JAVA源代码文件。 有没有办法设置或获得这个酒吧的颜色?

请注意:

1)我不能与数据系列实现像在上面的链接所示的一个视图中使用DataSeries代替ListSeries的,因为是不可能的(或我不知道的)。

2)我已经检查了类似于我的其他堆栈溢出问题,但没有人能回答这个问题。

+0

我没有执照,所以我无法验证如何将这些应用,但也许你可以找到有用的东西:你的造型图表博客文章(https://vaadin.com/blog/-/blogs/styling-your-vaadin-charts)和[vaadin docs - charts config](https://vaadin.com/docs/-/part/charts/java-api/charts-configuration.html) – Morfic

回答

0

我找到了解决上述问题的方法。现在我可以在涉及ListSeries的条形图栏中设置我选择的颜色。

PlotOptionsColumn就是答案。

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