ZingCharts 水平堆叠条形图 X 轴标签被截断
ZingCharts horizontal stacked bar chart X-Axis labels being cut off
我创建了一个简单的水平条形图。 X 轴上的标签被切断,如下面的代码片段所示。我需要显示 'X Axis Row A' 的完整标签。我试过更改图表的宽度,但这没有用。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>ZingChart</title>
</head>
<body>
<div id="chartDiv"></div>
<script src='http://cdn.zingchart.com/zingchart.min.js'></script>
<script>
var chartData={
"type":"hbar",
"stacked":true,
"stack-type":"normal", // Also accepts "100%"
"title":{
"text":"X-Axis Row Label Cut Off Example"
},
"scale-x":{
"values":["X Axis Row B","X Axis Row A"],
},
"scale-y":{
"format":"%v%",
},
"series":[{
"background-color":"rgb(248,51,45)",
"text":"Negative",
"values":[-11,-22]
},{
"background-color":"rgb(120,152,55)",
"text":"Positive",
"values":[35,45]
}]
};
window.onload=function(){
var x = zingchart.render({
id:'chartDiv',
height:200,
width:600,
data:chartData
});
}
</script>
</body>
</html>
所以我终于想通了。如果使用 'plotarea' 键,则可以指定边距。例如:
"plotarea":{
"margin":"40px 20px 50px 100px"
}
更新了以下示例:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>ZingChart</title>
</head>
<body>
<div id="chartDiv"></div>
<script src='http://cdn.zingchart.com/zingchart.min.js'></script>
<script>
var chartData={
"type":"hbar",
"stacked":true,
"stack-type":"normal", // Also accepts "100%"
"title":{
"text":"Add Margin Example"
},
"plotarea": {
"margin":"40px 20px 50px 100px"
},
"scale-x":{
"values":["X Axis Row B","X Axis Row A"],
},
"scale-y":{
"format":"%v%",
},
"series":[{
"background-color":"rgb(248,51,45)",
"text":"Negative",
"values":[-11,-22]
},{
"background-color":"rgb(120,152,55)",
"text":"Positive",
"values":[35,45]
}]
};
window.onload=function(){
var x = zingchart.render({
id:'chartDiv',
height:200,
width:600,
data:chartData
});
}
</script>
</body>
</html>
设置边距绝对有效。您还可以在 "plotarea" 对象中使用 "margin":"dynamic"。文档中有一个演示,显示了此属性容纳的一些长标签。 http://www.zingchart.com/docs/json-attributes-syntax/graph-objects/plotarea/
我是 ZingChart 团队的一员,如果您对此有任何其他问题,请随时与我们联系。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>ZingChart</title>
</head>
<body>
<div id="chartDiv"></div>
<script src='http://cdn.zingchart.com/zingchart.min.js'></script>
<script>
var chartData={
"type":"hbar",
"stacked":true,
"stack-type":"normal", // Also accepts "100%"
"title":{
"text":"Add Margin Example",
"adjust-layout":1
},
"plotarea": {
"margin":"dynamic"
},
"scale-x":{
"values":["X Axis Row B","X Axis Row A"],
},
"scale-y":{
"format":"%v%",
},
"series":[{
"background-color":"rgb(248,51,45)",
"text":"Negative",
"values":[-11,-22]
},{
"background-color":"rgb(120,152,55)",
"text":"Positive",
"values":[35,45]
}]
};
window.onload=function(){
var x = zingchart.render({
id:'chartDiv',
height:200,
width:600,
data:chartData
});
}
</script>
</body>
</html>
我创建了一个简单的水平条形图。 X 轴上的标签被切断,如下面的代码片段所示。我需要显示 'X Axis Row A' 的完整标签。我试过更改图表的宽度,但这没有用。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>ZingChart</title>
</head>
<body>
<div id="chartDiv"></div>
<script src='http://cdn.zingchart.com/zingchart.min.js'></script>
<script>
var chartData={
"type":"hbar",
"stacked":true,
"stack-type":"normal", // Also accepts "100%"
"title":{
"text":"X-Axis Row Label Cut Off Example"
},
"scale-x":{
"values":["X Axis Row B","X Axis Row A"],
},
"scale-y":{
"format":"%v%",
},
"series":[{
"background-color":"rgb(248,51,45)",
"text":"Negative",
"values":[-11,-22]
},{
"background-color":"rgb(120,152,55)",
"text":"Positive",
"values":[35,45]
}]
};
window.onload=function(){
var x = zingchart.render({
id:'chartDiv',
height:200,
width:600,
data:chartData
});
}
</script>
</body>
</html>
所以我终于想通了。如果使用 'plotarea' 键,则可以指定边距。例如:
"plotarea":{
"margin":"40px 20px 50px 100px"
}
更新了以下示例:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>ZingChart</title>
</head>
<body>
<div id="chartDiv"></div>
<script src='http://cdn.zingchart.com/zingchart.min.js'></script>
<script>
var chartData={
"type":"hbar",
"stacked":true,
"stack-type":"normal", // Also accepts "100%"
"title":{
"text":"Add Margin Example"
},
"plotarea": {
"margin":"40px 20px 50px 100px"
},
"scale-x":{
"values":["X Axis Row B","X Axis Row A"],
},
"scale-y":{
"format":"%v%",
},
"series":[{
"background-color":"rgb(248,51,45)",
"text":"Negative",
"values":[-11,-22]
},{
"background-color":"rgb(120,152,55)",
"text":"Positive",
"values":[35,45]
}]
};
window.onload=function(){
var x = zingchart.render({
id:'chartDiv',
height:200,
width:600,
data:chartData
});
}
</script>
</body>
</html>
设置边距绝对有效。您还可以在 "plotarea" 对象中使用 "margin":"dynamic"。文档中有一个演示,显示了此属性容纳的一些长标签。 http://www.zingchart.com/docs/json-attributes-syntax/graph-objects/plotarea/
我是 ZingChart 团队的一员,如果您对此有任何其他问题,请随时与我们联系。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>ZingChart</title>
</head>
<body>
<div id="chartDiv"></div>
<script src='http://cdn.zingchart.com/zingchart.min.js'></script>
<script>
var chartData={
"type":"hbar",
"stacked":true,
"stack-type":"normal", // Also accepts "100%"
"title":{
"text":"Add Margin Example",
"adjust-layout":1
},
"plotarea": {
"margin":"dynamic"
},
"scale-x":{
"values":["X Axis Row B","X Axis Row A"],
},
"scale-y":{
"format":"%v%",
},
"series":[{
"background-color":"rgb(248,51,45)",
"text":"Negative",
"values":[-11,-22]
},{
"background-color":"rgb(120,152,55)",
"text":"Positive",
"values":[35,45]
}]
};
window.onload=function(){
var x = zingchart.render({
id:'chartDiv',
height:200,
width:600,
data:chartData
});
}
</script>
</body>
</html>