問題描述
如何從 Google 的 Visualization API 生成的條形圖中刪除 x 軸? (How do you remove the x‑axis from a bar chart produced by Google's Visualization API?)
Referring to the kind of chart shown here: http://code.google.com/apis/visualization/documentation/gallery/barchart.html
There doesn't seem to be a simple switch, and changing the axis color to white (on a white background) didn't seem to do anything. I even tried jquery to hide the selectors produced by the api output but no dice.
‑‑‑‑‑
參考解法
方法 1:
You can set hAxis.textPosition
to the value of 'none
'
For example:
var options = {
hAxis: { textPosition: 'none' },
};
chart.draw(data, options);
See https://developers.google.com/chart/interactive/docs/gallery/barchart#Configuration_Options
方法 2:
let options = {legend: { position: 'none' }};
方法 3:
Their API has no function for this indeed, but:
chart.draw( data,
{
width: 400,
height: 240,
is3D: true,
legend :'none',
axisFontSize : 0
});
Setting axisFontSize to 0 will remove your x‑axis data. :)
方法 4:
I was able to remove the label in the material version of the chart by removing the string in my datatable.
Before:
data.addColumn('string', 'Date');
After:
data.addColumn('string', '');
方法 5:
Google changes the API so fast, this is what works today:
chart.draw(daily, {
hAxis : {textColor: '#ffffff'},
[... your other options here ...]
});
(by Dan、Dan Diplo、AtyulyaKadam、Elzo Valugi、Tony Schmidt、KKovacs)