简体   繁体   English

当绘制2个甜甜圈时,D3JS图形甜甜圈没有显示一些楔形

[英]D3JS graph donuts not showing some wedges when 2 donuts plotted

We are displaying donut pie chart using d3js in asp.net. 我们正在asp.net中使用d3js显示甜甜圈饼图。 We are using d3.json for passing json data to display wheel level1. 我们正在使用d3.json传递json数据以显示转轮level1。 Wheel level1 is display as per the data. 根据数据显示车轮等级1。 We are using another d3.json for passing json data to display wheel level2. 我们使用另一个d3.json传递json数据以显示转轮level2。 But starting wedges of wheel level2 are not display in pie chart. 但是,在饼图中未显示车轮level2的起始楔形。

I observed that if I plot the DoNut of Level1 and Level2 independently it shows all wedges of both Level 1, Level2 respectively. 我观察到,如果我分别绘制Level1和Level2的DoNut,它将分别显示Level 1和Level2的所有楔形。 When I changed the inner , out radius of Level1 and Level2 and displayed Level2 donut outside wiht Level1 donut inside, getting same problem of some wedges not displayed. 当我更改Level1和Level2的inner半径,out半径并在Level1甜甜圈内部显示了Level2甜甜圈的外部时,出现了一些楔子未显示的相同问题。 The data of angles is stored in MySQL database, using the same the graph is plotted. 角度数据存储在MySQL数据库中,使用相同的图形绘制。 I checked the sum of angles of all wedges for the Level 2 is 360. 我检查了级别2的所有楔形的角度总和为360。

here is the graph 这是图 在此处输入图片说明

Sample code that is being used to plot Level1 DoNut 用于绘制Level1 DoNut的示例代码

 d3.json("http://localhost:50025/SportsWheelServices.asmx/WheelLevel1", function (error, data) {

        data.forEach(function (d) {
            d.SectionId = d.SectionId;
            d.SectionLevel1 = d.SectionLevel1;
            d.GroupName = d.GroupName;
            d.SectionUpColor = d.SectionUpColor;
            d.Rotation = d.Rotation;
      });

        var label = d3.arc()
          .outerRadius(radius - 20)
          .innerRadius(400);

        var pie = d3.pie()
                       .sort(null)
                       .value(function (d) { return d.SectionLevel1; });

        var arc = d3.arc()         
           .outerRadius(radius - 20)
           .innerRadius(400);        

        var arcs = g.selectAll(".arc")
          .data(pie(data))
          .enter().append("g")
            .attr("class", "arc");

        arcs.append("path")
            .attr("d", arc)       
        .attr("fill", function (d, i) { return colors(data[i].SectionUpColor); });

        arcs.append("text")
         .attr("transform", function (d) {          
             var rotation = d.endAngle < Math.PI ? (d.startAngle / 2 + d.endAngle / 2) * 180 / Math.PI : (d.startAngle / 2 + d.endAngle / 2 + Math.PI) * 180 / Math.PI;
             return "translate(" + label.centroid(d) + ") rotate("+ d.data.Rotation+") rotate(" + rotation + ")";
         })         
            .attr("dy", "0.35em")
            .text(function (d) { return d.data.GroupName; });

});

Code for Level2 DoNut Level2 DoNut的代码

d3.json("http://localhost:50025/SportsWheelServices.asmx/WheelLevel2", function (error, data) {

        data.forEach(function(d)
        {
            d.SectionId = d.SectionId;
            d.SectionLevel2 = d.SectionLevel2;          
        });


        var label = d3.arc()
        .outerRadius(radius - 20)
        .innerRadius(300);

        var pie = d3.pie()
                       .sort(null)            
                       .value(function (d) { return d.SectionLevel2; });

        var arc = d3.arc()
           .outerRadius(radius - 20)
           .innerRadius(300);

        var arcs = g.selectAll(".arc")
          .data(pie(data))
          .enter().append("g")
          .attr("class", "arc");

        arcs.append("path")            
           .attr("d", arc)
             .attr("fill", function (d, i) { return colors(i); });        
    });

代替了var arcs = g.selectAll(“。arc”),我添加了以下代码var arcs = g.selectAll(“。arc” + index),这解决了我的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM