Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/386.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 <;的值无效;路径>;属性d3.js_Javascript_D3.js - Fatal编程技术网

Javascript <;的值无效;路径>;属性d3.js

Javascript <;的值无效;路径>;属性d3.js,javascript,d3.js,Javascript,D3.js,我是d3.js中的一个完全的新手,我正在处理一些代码,但它无法创建路径。请检查小提琴: 请告诉我哪里出了问题 /* */ var setChartDimensions = function(l,r,t,b,w,h) { /* Set the dimensions of the graph */ margin = { left : l || 60, right : r || 110,

我是d3.js中的一个完全的新手,我正在处理一些代码,但它无法创建路径。请检查小提琴:

请告诉我哪里出了问题

/*  */
    var setChartDimensions = function(l,r,t,b,w,h) {   
        /* Set the dimensions of the graph */
        margin = {
                left : l || 60,
                right : r || 110,
                top : t || 20,
                bottom : b || 40

        };
        getDimensions(w,h); //
        width = width - 100 - margin.left - margin.right;
        height = height - margin.top - margin.bottom;
    };

    /*  */
    var setChartContainer = function(){
        svg = d3.select("#container")
        .append("svg")
        .attr("width",width + margin.left + margin.right)
        .attr("height", height + margin.top + margin.bottom)
        .append("g")
        .attr("transform","translate(" + margin.left + "," + margin.top + ")");

        graph = svg.append("svg")
        .attr("width", width)
        .attr("height", height + margin.top + margin.bottom);
    };

    var xAxis_true= 0, yAxisRight_true= 0, yAxisLeft_true= 0, array = [], width, height, svg, graph;
    var jsonArray=[], path, axis, time, noOfPoints = 20, tracker = 0;
    var color = d3.scale.category10();
    // Set the ranges
    var x = d3.scale.linear().range([ 0, width ]);
    var y1 = d3.scale.linear().range([ height, 0 ]);
    var y2 = d3.scale.linear().range([ height, 0 ]);
    var xAxis = d3.svg.axis().scale(x).orient("bottom").ticks(5);
    var yAxisRight = d3.svg.axis().scale(y2).orient("right").ticks(5);
    var yAxisLeft = d3.svg.axis().scale(y1).orient("left").ticks(5);

    /*  */
    var getDimensions = function(w,h) {
        width = w || $(window).innerWidth()/0.93;
        height = h || screen.height/2.7;
        $('#container').css('min-width', width);
        $('#container').css('min-height', height);
    };

    /*  */
    $(window).resize(function() {
        getDimensions();
    });



    /* Sets the points (x,y) for the path */
    var valueline = d3.svg.line()
    .interpolate('monotone')
    .x(function(d) {
        return x(d.xValue);
    }).y(function(d) {
        return y1(d.yValue);
    });


    /*  */
    var setXdomain = function(data) {
        x.domain(d3.extent(data, function(d) {
            return d.xValue;
        }));
    }

    /*  */
    var setYdomain = function(data) {
        y1.domain([ 0, d3.max(data, function(d) {
            return d.yValue * 1.31;
        }) ]);

        y2.domain([ 0, d3.max(data, function(d) {
            return d.yValue * 0.9;
        }) ]);
    }

    /*  */
    var createPath = function(data) {
        path = graph.append("g")
        .append("path") // Add the valueline path.
        .attr("class", "line")
        .attr("d", valueline(data));    
    }

    /*  */
    var addXAxis = function() {
        axis = graph.append("g") // Add the X Axis
        .attr("class", "xAxis")
        .attr("transform","translate(0," + height + ")")
        .call(xAxis);

    }

    /*  */
    var addYAxis = function(i) {
        makeY = svg.append("g") // Add the Y Axis
        .attr("class", "yAxis")   
        .style("fill", "steelblue");

        if(i==0)
            makeY.call(yAxisLeft);
        else {
            makeY.attr("transform", "translate(" + width + " ,0)");
            makeY.call(yAxisRight);
        }
    }

    /*  */
    var makeXGrid = function (n) {
        xGrid = svg.selectAll("line.verticalGrid").data(x.ticks(n)).enter()
        .append("line")
        .attr({
            "class":"verticalGrid",
            "x1" : function(d){ return x(d);},
            "x2" : function(d){ return x(d);},
            "y1" : height,
            "y2" : 0,
            "fill" : "none",
            "shape-rendering" : "geometricPrecision",
            "stroke" : "#C8C8C8 ",
            "stroke-width" : "1px"
        });

    }

    /*  */
    var makeYGrid = function (a) {
        svg.selectAll("line.horizontalGrid").data(y1.ticks(10)).enter()
        .append("line")
        .attr({
            "class":"horizontalGrid",
            "x1" : 0,
            "x2" : width,
            "y1" : function(d){ if(a==0) return y1(d); else return y2(d);},
            "y2" : function(d){ if(a==0) return y1(d); else return y2(d);},
            "fill" : "none",
            "shape-rendering" : "geometricPrecision",
            "stroke" : "#C8C8C8 ",
            "stroke-width" : "1px"
        });
    }

    /*  */
    var addTitle = function(title) {
        svg.append("text") // Add the title shadow
        .attr("x", (width / 2))
        .attr("y", margin.top / 2)
        .attr("text-anchor", "middle")
        .attr("class", "shadow")
        .style("font-size", "16px")
        .text(title);

        svg.append("text") // Add the title
        .attr("class", "stock")
        .attr("x", (width / 2))
        .attr("y", margin.top / 2)
        .attr("text-anchor", "middle")
        .style("font-size", "16px")
        .text(title);

    }

    /* Add the text label for the X axis */
    var xAxisLabel = function(text) {
        svg.append("text")      // Add the text label for the x axis
        .attr("transform", "translate(" + (width / 2) + " ," + (height + margin.bottom) + ")")
        .style("text-anchor", "middle")
        .style("font-size", "14px")
        .text(text);
    }

    /* Add the text label for the Y axis */
    var yAxisLabel = function(text) {
        svg.append("text")
            .attr("transform", "rotate(-90)")
            .attr("y", 0 - margin.left)
            .attr("x",0 - (height / 2))
            .attr("dy", "1em")
            .style("font-size", "14px")
            .style("text-anchor", "middle")
            .text(text);
    }

    /* Function to insert Random points into the JSON */
    var makeRandomPoints = function(t) {
        time += 1000;
        return {
            "xValue" : Math.floor((Math.random() * 100)),
            "yValue" : Math.floor((Math.random() * 100))
        }
    }

    /* Function to create the chart */
    var createChart = function(title, xLabel, yLabel, data, realtime, gridX, xG, gridY, yG) {
        setChartDimensions(left=null, right=null, top=null, bottom=null, width=null, height=null); /* Pass values in the order left right top bottom */
        setChartContainer();

        setXdomain(data);       /* Set the domain of X Axis */
        setYdomain(data);       /* Set the domain of Y Axes */
        createPath(data);       /* create the line (path) for the data */
        addXAxis();
        addYAxis(0);
        if(gridX) {
            makeXGrid(xG);
        }
        if(gridY) {
            makeYGrid(yG);
        }
        addTitle(title);
        xAxisLabel(xLabel);
        yAxisLabel(yLabel);
    }

    /*  */
    var init = function () {

        for(var i=0; i<noOfPoints; i++) {
            array.push(makeRandomPoints());
        }
        console.log(array.length);
        // createChart("XYZ", "X Value", "Y Value", data, 1, 5);
        createChart("XYZ", "X Value", "Y Value", array, 0, true, 5, true, 5);

    }

    init();
/**/
var setChartDimensions=函数(l,r,t,b,w,h){
/*设置图形的尺寸*/
保证金={
左:l | | 60,
右:r | | 110,
上图:t | | 20,
底部:b | | 40
};
尺寸(w,h)//
宽度=宽度-100-边距。左侧-边距。右侧;
高度=高度-margin.top-margin.bottom;
};
/*  */
var setChartContainer=函数(){
svg=d3。选择(“容器”)
.append(“svg”)
.attr(“宽度”,宽度+边距。左侧+边距。右侧)
.attr(“高度”,高度+边距。顶部+边距。底部)
.附加(“g”)
.attr(“转换”、“平移”(+margin.left+)、“+margin.top+”);
graph=svg.append(“svg”)
.attr(“宽度”,宽度)
.attr(“高度”,高度+边距。顶部+边距。底部);
};
var xAxis_true=0,yAxisRight_true=0,yaxislight_true=0,数组=[],宽度,高度,svg,图形;
var jsonArray=[],路径,轴,时间,noOfPoints=20,tracker=0;
var color=d3.scale.category10();
//设定范围
var x=d3.scale.linear()范围([0,宽度]);
变量y1=d3.scale.linear().范围([height,0]);
变量y2=d3.scale.linear().range([height,0]);
var xAxis=d3.svg.axis().scale(x)、orient(“bottom”)、ticks(5);
var yAxisRight=d3.svg.axis().scale(y2.orient(“right”).ticks(5);
var yaxisleet=d3.svg.axis().scale(y1.oriented(“left”).ticks(5);
/*  */
var getDimensions=函数(w,h){
宽度=w | |$(窗口).innerWidth()/0.93;
高度=h | |屏幕高度/2.7;
$('#container').css('min-width',width);
$('#container').css('min-height',height);
};
/*  */
$(窗口)。调整大小(函数(){
getDimensions();
});
/*设置路径的点(x,y)*/
var valueline=d3.svg.line()
.插值('单调')
.x(功能(d){
返回x(d.xValue);
}).y(功能(d){
返回y1(d.y值);
});
/*  */
var setXdomain=函数(数据){
x、 域(d3)。范围(数据,函数(d){
返回d.xValue;
}));
}
/*  */
var setYdomain=函数(数据){
y1.域([0,d3.最大值(数据,函数(d)){
返回d.Y值*1.31;
}) ]);
y2.域([0,d3.max(数据,函数(d)){
返回d.y值*0.9;
}) ]);
}
/*  */
var createPath=函数(数据){
path=graph.append(“g”)
.append(“path”)//添加valueline路径。
.attr(“类”、“行”)
.attr(“d”,valueline(数据));
}
/*  */
var addXAxis=函数(){
axis=graph.append(“g”)//添加X轴
.attr(“类”、“xAxis”)
.attr(“变换”、“平移(0)”、“高度+”)
.呼叫(xAxis);
}
/*  */
var addYAxis=函数(i){
makeY=svg.append(“g”)//添加Y轴
.attr(“类”、“亚克斯”)
.样式(“填充”、“钢蓝”);
如果(i==0)
makeY.call(左);
否则{
attr(“transform”,“translate”(+width+”,0)”);
makeY.call(右);
}
}
/*  */
var makeXGrid=函数(n){
xGrid=svg.selectAll(“line.verticalGrid”).data(x.ticks(n)).enter()
.附加(“行”)
艾特先生({
“类”:“垂直网格”,
“x1”:函数(d){返回x(d);},
“x2”:函数(d){返回x(d);},
“y1”:高度,
“y2”:0,
“填充”:“无”,
“形状渲染”:“几何精度”,
“笔划”:“#C8C8C8”,
“笔划宽度”:“1px”
});
}
/*  */
var makeYGrid=函数(a){
svg.selectAll(“line.horizontalGrid”).data(y1.ticks(10)).enter()
.附加(“行”)
艾特先生({
“类”:“水平网格”,
“x1”:0,
“x2”:宽度,
“y1”:函数(d){if(a==0)返回y1(d);else返回y2(d);},
“y2”:函数(d){if(a==0)返回y1(d);else返回y2(d);},
“填充”:“无”,
“形状渲染”:“几何精度”,
“笔划”:“#C8C8C8”,
“笔划宽度”:“1px”
});
}
/*  */
var addTitle=函数(标题){
append(“text”)//添加标题阴影
.attr(“x”,(宽度/2))
.attr(“y”,margin.top/2)
.attr(“文本锚定”、“中间”)
.attr(“类”、“阴影”)
.style(“字体大小”、“16px”)
.文本(标题);
append(“text”)//添加标题
.attr(“类别”、“股票”)
.attr(“x”,(宽度/2))
.attr(“y”,margin.top/2)
.attr(“文本锚定”、“中间”)
.style(“字体大小”、“16px”)
.文本(标题);
}
/*添加X轴的文本标签*/
var xAxisLabel=函数(文本){
append(“text”)//为x轴添加文本标签
.attr(“变换”、“平移”(+(宽度/2)+)、“+(高度+边距.底部)+”)
.style(“文本锚定”、“中间”)
.style(“字体大小”、“14px”)
.文本(文本);
}
/*添加Y轴的文本标签*/
var yAxisLabel=函数(文本){
svg.append(“文本”)
.attr(“变换”、“旋转(-90)”)
.attr(“y”,0-页边距。左)
.attr(“x”,0-(高度/2))
.attr(“dy”、“1em”)
.style(“字体大小”、“14px”)
.style(“文本锚定”、“中间”)
.文本(文本);
}
/*函数将随机点插入JSON*/
var makeRandomPoints=函数(t){
时间+=1000;
返回{
“xValue”:数学地板((数学随机()*100)),
    console.log(width);
    console.log(height);
    var x = d3.scale.linear().range([ 0, width ]);
    var y1 = d3.scale.linear().range([ height, 0 ]);
    var y2 = d3.scale.linear().range([ height, 0 ]);

    > undefined
    > undefined