gpt4 book ai didi

javascript - angular-dc 条形图未呈现

转载 作者:太空宇宙 更新时间:2023-11-04 03:06:26 24 4
gpt4 key购买 nike

我正在尝试使用 crossfilter、dc.js 和 angular-dc 绘制一个简单的条形图。行图工作正常。条形图不呈现条形。在 Chrome 中,如果我检查,我会看到值在那里。如果我集中注意力,我确实会看到图表。我已经尝试了所有的建议,但似乎有 3 个问题:

所有条形都从 x 轴上的 0 开始。每个条形的宽度为 1 px。条形图未在屏幕上呈现。

您能为我提供上述问题的解决方案吗?我使用以下链接创建了我的条形图:https://github.com/TomNeyland/angular-dc/blob/master/example/stocks/nasdaq.html

是否有任何其他链接与使用 angular-dc 的条形图相关。

示例代码如下:

<!DOCTYPE html>
<html lang="en">
<head>
<title>dc.js - Pie Chart Example</title>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="public/lib/dcjs/web/css/dc.css"/>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.min.js"></script>
<script type="text/javascript" src="public/lib/d3/d3.js"></script>
<script type="text/javascript" src="public/lib/crossfilter/crossfilter.js"></script>
<script type="text/javascript" src="public/lib/dcjs/dc.js"></script>
<script type="text/javascript" src="public/lib/angular/angular.js"></script>
<script type="text/javascript" src="public/lib/angular-dc/dist/angular-dc.js"></script>
</head>
<body ng-app="app">
<!-- we nicely separate the view and the data. Here, all information concerning the way to display the data
is in the template -->
<div ng-controller="myController">
<div dc-chart="pieChart"
dc-chart-group="1"
dc-width="780"
dc-height="480"
dc-inner-radius="100"
dc-dimension="fruit"
dc-group="fruitSales"
dc-legend="dc.legend()">
</div>
<div dc-chart="barChart"
dc-width="780"
dc-height="480"
dc-dimension="fruit"
dc-group="fruitSales"
dc-x="d3.scale.ordinal().domain(['','Apple','Banana'])"
dc-xUnits ="dc-units-ordinal"
dc-elastic-y="true"
dc-center-bar="true"
dc-gap="1"
dc-bar-padding="0.5"
dc-xAxisPadding="50"
dc-legend="dc.legend()">
</div>
</div>
</div>
<script type="text/javascript">
angular.module("app", ["angularDc"]);
myController = function($scope) {
var fruitCf = crossfilter([
{Name: 'Apple', Sales: 40},
{Name: 'Apple', Sales: 40},
{Name: 'Banana', Sales: 20}]);
$scope.fruit = fruitCf.dimension(function(d) {return d.Name;});
$scope.fruitSales = $scope.fruit.group().reduceSum(function(d) {return d.Sales;});
//$scope.$apply()
};
</script>
</body>
</html>

最佳答案

就在几天前,我尝试做同样的事情。我什至尝试了以下链接提供的解决方案:

Angular dc.js filter issue

dc.js x axis ordinal chart issue

但这对我不起作用。然后就在今天,我尝试在我的 Controller 中使用 dc.js Plain Javascript,它运行良好。您甚至不必在您的应用中注入(inject)“angularDc”依赖项。

以下是我建议您应该尝试的方法:

<body ng-app="app">
<div id="England_batting" ng-controller="myController"></div>
<script>
var app = angular.module("app", []);
app.controller('myController', function($scope) {

d3.json('New.json', function(error, data) {
var data = data.Cricket;

var ndx = crossfilter(data);
dateDim = ndx.dimension(function(d) {
return d.Date;
});
var a = dateDim.filter("abdul");
var b = a.top(Infinity);
var c = crossfilter(b);

inningDim = c.dimension(function(d) {

return d.Inning;

});
var d = inningDim.filter("Australia bowling");
var e = d.top(Infinity);
var f = crossfilter(e);

nameDim = f.dimension(function(d) {

return d.Name;


});

runName = nameDim.group().reduceSum(function(d) {

return d.Runs;


});


var England_batting = dc.barChart("#England_batting");
England_batting.width(700)
.height(480)
.gap(30)
.yAxisLabel(".", 50)
.xAxisLabel("U", 50)
.dimension(nameDim)
.group(runName)
.x(d3.scale.ordinal().domain(nameDim))
.xUnits(dc.units.ordinal)
.y(d3.scale.linear().domain([0, 200]))
.elasticY(true)
.renderHorizontalGridLines(true)
.renderTitle(true)
.brushOn(true);
dc.renderAll();

});

});
</script>

希望对您有所帮助。干杯! :)

关于javascript - angular-dc 条形图未呈现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30371935/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com