2016-09-27 30 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); 
}