Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 尝试将google图表与css对齐_Javascript_Html_Css_Charts - Fatal编程技术网

Javascript 尝试将google图表与css对齐

Javascript 尝试将google图表与css对齐,javascript,html,css,charts,Javascript,Html,Css,Charts,我试图将谷歌提供的示例图表放在中心: 我使用了我知道的基本css居中(marginright:auto;marginleft:auto;),但似乎没有任何效果。到目前为止,我只处理文本和图像,因此非常感谢您的帮助 下面是我正在使用的基本代码(包括GoogleCharts javascript) 分区图表{ 左边距:自动; 右边距:自动; 宽度:800px;} //加载可视化API和piechart包。 load('visualization','1.0',{'packages':['corec

我试图将谷歌提供的示例图表放在中心: 我使用了我知道的基本css居中(
marginright:auto;marginleft:auto;
),但似乎没有任何效果。到目前为止,我只处理文本和图像,因此非常感谢您的帮助

下面是我正在使用的基本代码(包括GoogleCharts javascript)


分区图表{
左边距:自动;
右边距:自动;
宽度:800px;}
//加载可视化API和piechart包。
load('visualization','1.0',{'packages':['corechart']});
//将回调设置为在加载Google Visualization API时运行。
setOnLoadCallback(drawChart);
//创建并填充数据表的回调,
//实例化饼图,传入数据并
//画它。
函数绘图图(){
//创建数据表。
var data=new google.visualization.DataTable();
data.addColumn('string','Topping');
data.addColumn('number','Slices');
data.addRows([
[‘蘑菇’,3],
[‘洋葱’,1],
[Olives',1],
[‘西葫芦’,1],
[意大利香肠,2]
]);
//设置图表选项
var options={'title':'我昨晚吃了多少比萨饼',
“宽度”:400,
‘高度’:300};
//实例化并绘制图表,传入一些选项。
var chart=new google.visualization.PieChart(document.getElementById('chart_div');
图表绘制(数据、选项);
}

您的CSS
div.chart\u div
的目标是类的div=“chart\u div”,但您的div为id=“chart\u div”。在CSS中使用#来定位ID,即div#chart#u div

Stovroz完全正确

在CSS中,您将
div.chart\u div
定义为一个类;但在HTML中定义为
div#chart\u div
ID

以下CSS代码通常用于将页面中的所有内容居中

<style> 
body{ text-align: center;}
#chart_div{width: 800px; margin: 0 auto; text-align: left;}
</style>

正文{文本对齐:居中;}
#图表分割{宽度:800px;边距:0自动;文本对齐:左;}
<style> 
body{ text-align: center;}
#chart_div{width: 800px; margin: 0 auto; text-align: left;}
</style>