【问题标题】:ZingChart bar chart is not generating correctlyZingChart 条形图未正确生成
【发布时间】:2016-11-18 08:39:09
【问题描述】:

html文件

<zingchart id="timesheet-bar-chart" zc-json="myObj"></zingchart>

在 controller.js 中

$scope.myObj = {
  "type": "bar",
  "utc": true,
  "plotarea":{
      "margin":'dynamic'
    },
  "plot":{
    "stacked":true,
    "stack-type":"normal" /* Optional specification */
  },
 "scaleX":{
      "transform":{
        "type":"date",
        "all":"%d %M",
        "item": {
          "visible":false
        }
      },
    },
  "series":[{ 
      "values": $scope.barValues,
      "backgroundColor":"#f15662"
    }]
  };
zingchart.render({ 
id : 'timesheet-bar-chart', 
height: 400, 
width: "100%"
});

$scope.barValues 中的数据以以下格式动态添加

[[[1478025000000,10],[1477938600000,20],[1478889000000,30]]]

我没有找到我犯任何错误的地方。生成的条形图格式不正确。请帮助我,我是第一次使用 ZingChart 库。

【问题讨论】:

  • “非格式”对您意味着什么?绘制的数据?酒吧尺寸?刻度标签?请提供更多详细信息,因为我无法告诉您要修复什么。
  • 条形尺寸和 x 轴刻度标签。

标签: angularjs charts zingchart


【解决方案1】:

您的条形图生成得很好。条形图从标签上看是因为您正在绘制 [[]](数组数组)。如果您查看绘制的时间戳,这些条形图实际上并未准确绘制在 11 月 4 日。如果您指的是标签本身,您可以通过all 属性确定标签显示的内容。您可以将step 属性设置为更线性或使用缩放。

scale docs

token docs

条形偏移是非线性数据的乘积。由于非线性数据,条形尺寸现在被压缩得更小了。这是由于随着时间的推移大小。您可以通过添加zooming(单击并拖动以缩放)来查看条形将增加大小。

zooming docs

var myConfig = {
  "type": "bar",
  "utc": true,
  "plotarea":{
      "margin":'dynamic'
    },
  "plot":{
    "stacked":true,
    "stack-type":"normal" /* Optional specification */
  },
 "scaleX":{
   "zooming":true,
      "transform":{
        "type":"date",
        "all":"%d %M %Y<br> %h:%i:%s",
      },
    },
  "series":[{ 
      "values": [[1478025000000,10],[1477938600000,20],[1478889000000,30]],
      "backgroundColor":"#f15662"
    }]
  };

zingchart.render({ 
	id: 'myChart', 
	data: myConfig, 
	height: '100%', 
	width: '100%' 
});
html, body {
	height:100%;
	width:100%;
	margin:0;
	padding:0;
}
#myChart {
	height:100%;
	width:100%;
	min-height:150px;
}
<!DOCTYPE html>
<html>
	<head>
		<script src= "https://cdn.zingchart.com/zingchart.min.js"></script>
	</head>
	<body>
		<div id="myChart"></div>
	</body>
</html>

您可以通过使用bar-width 属性设置固定大小来避免这种情况。

plot docs

var myConfig = {
  "type": "bar",
  "utc": true,
  "plotarea":{
      "margin":'dynamic'
    },
  "plot":{
    "bar-width": 30,
    "stacked":true,
    "stack-type":"normal" /* Optional specification */
  },
 "scaleX":{
   "zooming":true,
      "transform":{
        "type":"date",
         "all":"%d %M %Y<br> %h:%i:%s",
      },
    },
  "series":[{ 
      "values": [[1478025000000,10],[1477938600000,20],[1478889000000,30]],
      "backgroundColor":"#f15662"
    }]
  };

zingchart.render({ 
	id: 'myChart', 
	data: myConfig, 
	height: '100%', 
	width: '100%' 
});
html, body {
	height:100%;
	width:100%;
	margin:0;
	padding:0;
}
#myChart {
	height:100%;
	width:100%;
	min-height:150px;
}
<!DOCTYPE html>
<html>
	<head>
	<!--Assets will be injected here on compile. Use the assets button above-->
		<script src= "https://cdn.zingchart.com/zingchart.min.js"></script>
	</head>
	<body>
		<div id="myChart"></div>
	</body>
</html>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多