如何设置googleVis气泡图的colorAxis?

时间:2018-11-09 12:06:04

标签: r googlevis

我尝试根据“利润”列以连续的色标调整GoogleVis气泡图example

library(googleVis)
Bubble <- gvisBubbleChart(Fruits, idvar="Fruit", 
                          xvar="Sales", yvar="Expenses",
                          colorvar="Profit", 
                          options=list(
                              ## custom color
                              ## colors = "['red', 'green', 'blue']",
                              ## custom color scale does not work
                              colorAxis="{colors: ['yellow', 'red']}",
                              hAxis='{minValue:75, maxValue:125}'))
plot(Bubble)

但是,无论我如何尝试使用'colorAxis'选项,它都不会起作用,尽管我确实遵循official documentation。似乎很奇怪,因为当我查看绘图的源代码时,我可以看到该选项已设置:

// jsDrawChart
function drawChartBubbleChartID2b6add84971() {
var data = gvisDataBubbleChartID2b6add84971();
var options = {};
options["colorAxis"] = {colors: ['yellow', 'red']};
options["hAxis"] = {minValue:75, maxValue:125};
    var chart = new google.visualization.BubbleChart(
    document.getElementById('BubbleChartID2b6add84971')
    );
    chart.draw(data,options);   
}

我在做什么错?感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

更新:

在GitHub上添加issue后,应该为GitHub(std::string)上的当前开发人员版本解决此问题。实际上,它的工作原理是:

enter image description here


问题似乎出在数据列“利润”:

devtools::install_github("mages/googleVis")

出于某些原因,我看不到此列被定义为var datajson = [ ["Apples", 98, 78, "20"], ["Oranges", 96, 81, "15"], ["Bananas", 85, 76, "9"] ]; data.addColumn('string','Fruit'); data.addColumn('number','Sales'); data.addColumn('number','Expenses'); data.addColumn('string','Profit'); 类型的列。当您将相关行更改为

string

将渐变色标应用于气泡。

这可能是var datajson = [ ["Apples", 98, 78, 20], ["Oranges", 96, 81, 15], ["Bananas", 85, 76, 9] ]; data.addColumn('number','Profit'); 实现中的错误,因为googleVis数据将Profit列定义为数字列。

相关问题