在 Google 个图表中设置条形图的基线和范围
Setting baseline and range of barchart in Google Charts
我正在绘制代表 U.S.A 中凶杀率的条形图。
我试图通过将基线设置为 > 0 来截断此图表,但代码:
var options = {
chart: {
title: 'Intentional homicide rate per 100,000 population, by country/territory (2000-2013) in the US',
subtitle: 'Intentional homicide is defined as unlawful death purposefully inflicted on a person by another person',
hAxis: {title: 'Year'},
vAxis: {
title: 'Rate per 100,000',
viewWindow:{
max:20,
min:2
},
// ticks: [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
},
}
};
没有完成它的工作并且显示了与我的目标相反的整个范围。
This是图表的完整代码。
我做错了什么?
相同的过程适用于面积图 (Pluckr example)...怎么会这样呢?
如其他答案中所述,您的代码不正确。
在使用 material 图表时,您需要使用函数 google.charts.Bar.convertOptions
。 Source(向下滚动一点,或按 ctrl + f 选择转换选项)。
您目前正在使用
绘制图表
chart.draw(data, options);
而正确的方法是
chart.draw(data, google.charts.Bar.convertOptions(options));
(这也是它使用面积图的原因。那不是 material 图表)。
我正在绘制代表 U.S.A 中凶杀率的条形图。 我试图通过将基线设置为 > 0 来截断此图表,但代码:
var options = {
chart: {
title: 'Intentional homicide rate per 100,000 population, by country/territory (2000-2013) in the US',
subtitle: 'Intentional homicide is defined as unlawful death purposefully inflicted on a person by another person',
hAxis: {title: 'Year'},
vAxis: {
title: 'Rate per 100,000',
viewWindow:{
max:20,
min:2
},
// ticks: [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
},
}
};
没有完成它的工作并且显示了与我的目标相反的整个范围。
This是图表的完整代码。 我做错了什么?
相同的过程适用于面积图 (Pluckr example)...怎么会这样呢?
如其他答案中所述,您的代码不正确。
在使用 material 图表时,您需要使用函数 google.charts.Bar.convertOptions
。 Source(向下滚动一点,或按 ctrl + f 选择转换选项)。
您目前正在使用
绘制图表chart.draw(data, options);
而正确的方法是
chart.draw(data, google.charts.Bar.convertOptions(options));
(这也是它使用面积图的原因。那不是 material 图表)。