Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/470.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 dc传单js如何使用来自新ajax调用的数据更新Chloreth?_Javascript_Leaflet_Dc.js_Dc.leaflet.js - Fatal编程技术网

Javascript dc传单js如何使用来自新ajax调用的数据更新Chloreth?

Javascript dc传单js如何使用来自新ajax调用的数据更新Chloreth?,javascript,leaflet,dc.js,dc.leaflet.js,Javascript,Leaflet,Dc.js,Dc.leaflet.js,我正试图用dc传单js画一张叶绿体图。我的代码如下: (function yieldvisualization() { var stateMap = dc.leafletChoroplethChart("#yieldcountymap"); var centroidofState = yielddata.centroid; var dataforViz = yielddata.data;

我正试图用dc传单js画一张叶绿体图。我的代码如下:

(function yieldvisualization() {

               var stateMap = dc.leafletChoroplethChart("#yieldcountymap");


                var centroidofState = yielddata.centroid;
                var dataforViz = yielddata.data;
                var numberFormat = d3.format(".2f");
                var yearformat = d3.time.format("%Y");



                dataforViz.forEach(function(d) { 
                d.productionPractice = d["Production practice"];
                parseYear = d3.time.format("%Y").parse;
                d.Year = parseYear(d["Year"])
                d.countyCode = d["Countycode"];
                d.countyName = d["County"];
                d.classDescription = d["Class Description"];
                d.utilizationPractice = d["Utilization"];
                d.measureValue = parseFloat(d["Value"]);    
                }); 

                var crossDataforviz = crossfilter(dataforViz);

                var counties = crossDataforviz.dimension(function (d) {
                    return d.countyCode;
                        });
                var valueDim = crossDataforviz.dimension(function (d) {
                    return d.measureValue;
                        });

                var minusvalue = valueDim.bottom(1)[0].measureValue;
                var maxusvalue = valueDim.top(1)[0].measureValue;

                var countyGroup = counties.group().reduce(
                                function (p, v) {
                                ++p.count;
                                p.sumValue += v.measureValue;
                                p.avgValue = p.sumValue / p.count;
                                return p;},
                            /* callback for when data is removed from the current filter results */
                            function (p, v) {
                                --p.count;
                                p.sumValue -= v.measureValue;
                                p.avgValue = p.count ? p.sumValue / p.count : 0;
                                return p;
                            },
                            /* initialize p */
                            function () {
                                return {count: 0,sumValue: 0,avgValue: 0}});
                console.log(countyGroup.all())

                var groupreturn = countyGroup.all();

                var avgValuelist = [];

                for (i=0; i< groupreturn.length; i++){
                        avgValuelist.push(groupreturn[i].value.avgValue);

                    }
                var sortedavgValuelist = avgValuelist.sort(function(a, b){return a-b});

                var sortedavgValuelistfirst = 0;
                var sortedavgValuelistlast = 0;
                if (sortedavgValuelist.length == 0){
                    sortedavgValuelistfirst = 0;
                    sortedavgValuelistlast = 0;
                } else {
                    sortedavgValuelistfirst = sortedavgValuelist[0];
                    sortedavgValuelistlast = sortedavgValuelist[sortedavgValuelist.length - 1]
                }

                console.log(sortedavgValuelistfirst,sortedavgValuelistlast)

                var statefiletoLoad = "static/" + valueState + ".json"

                d3.json(statefiletoLoad, function (countyJson) {                
                    stateMap
                        .width(500)
                        .height(400)
                        .center(centroidofState)
                        .zoom(6)
                        .dimension(counties)
                        .group(countyGroup)
                        .colors(d3.scale.quantize().range(["#ffffe5", "#f7fcb9", "#d9f0a3", "#addd8e", "#78c679", "#41ab5d", "#238443", "#006837", "#004529"]))
                        .colorDomain([sortedavgValuelistfirst, sortedavgValuelistlast])
                        .colorCalculator(function (d) { return d ? stateMap.colors()(d.value.avgValue) : '#4863A0'; })
                        .geojson(countyJson.features)
                        .featureKeyAccessor(function(feature) {
                        return feature.properties.COUNTY;
                        })
                        .renderPopup(true)
                        .popup(function(d,feature) {
                            return "County: " + feature.properties.NAME + ";     " +"Average Yield: "+numberFormat(d.value.avgValue ? d.value.avgValue : 0) + " "+unitMeasure;
                        });





                dc.renderAll();

                }); 


                }());
(函数yieldvisualization(){
var stateMap=dc.CholoplethChart(“yieldcountymap”);
var centroidof state=yielddata.centroid;
var dataforViz=yielddata.data;
var numberFormat=d3.format(“.2f”);
var yearformat=d3.time.format(“%Y”);
dataforViz.forEach(函数(d){
d、 生产实践=d[“生产实践”];
parseYear=d3.time.format(“%Y”).parse;
d、 年份=分析年份(d[“年份”])
d、 countyCode=d[“countyCode”];
d、 countyName=d[“县”];
d、 classDescription=d[“类描述”];
d、 实用性实践=d[“实用性”];
d、 measureValue=parseFloat(d[“Value”]);
}); 
var crossDataforviz=交叉过滤器(dataforViz);
var countries=crossDataforviz.维度(函数(d){
返回d.countyCode;
});
var VALUEMDIM=crossDataforviz.维度(函数(d){
返回d.measureValue;
});
var minusvalue=valueDim.bottom(1)[0].measureValue;
var maxusvalue=valueDim.top(1)[0].measureValue;
var countyGroup=countries.group().reduce(
功能(p,v){
++p、 计数;
p、 sumValue+=v.measureValue;
p、 avgValue=p.sumValue/p.count;
返回p;},
/*从当前筛选结果中删除数据时的回调*/
功能(p,v){
--p、 计数;
p、 sumValue-=v.measureValue;
p、 avgValue=p.count?p.sumValue/p.count:0;
返回p;
},
/*初始化p*/
函数(){
返回{count:0,sumValue:0,avgValue:0}});
console.log(countyGroup.all())
var groupreturn=countyGroup.all();
var avgValuelist=[];
对于(i=0;i
当我从ajax调用接收到新数据时,将重新绘制此图表。初始绘制工作正常,但在重画时,我收到传单错误:“地图容器已初始化”。请告诉我是否有map.remove()方法,我可以使用它在新的ajax调用中重新绘制映射。任何关于这方面的指导都将不胜感激

dc.lapper.js第二次渲染失败,我即将合并

但是,我认为在这种情况下,您可能希望第二次重新绘制,而不是渲染。这样,您应该可以在数据更改时获得转换

您只需添加一个标志
isRendered
,然后将代码更改为

var isRendered = false;
if(isRendered)
    dc.redrawAll();
else {
    dc.renderAll();
    isRendered = true;
}

非常感谢戈登:)合并修复程序时,请在此发表评论。ThanksJust将其合并到0.2.3中-如前所述,我认为您需要的是重画而不是渲染。谢谢您…您得到了:)