简体   繁体   中英

D3.js,after loading data success,i can't see any data in view

As title.
After I successful loading data, I can't see any data in view. But in DevTool, I can see the data was load success.

Update:
If i add some attribute like: transform="translate(350,165) in <g> then i can find the <circle>

Database:MySQL

Javascript:

    $.ajax({
        method: "POST",
        url: "data2.php",
        success: function(data) {
            json_data = JSON.parse(data);
            console.log(json_data);
            console.log(json_data.length);
            for(var x = 0; x < json_data.length; x++){
              console.log(json_data[x].Circles)
              $("svg > g").append(json_data[x].Circles);
              $("svg > g").append(json_data[x].arrows);
              console.log(json_data[x].arrows);
              $("svg > g").append(json_data[x].Links);
              console.log(json_data[x].Links)
            }
        },
        error: function(err, f) {
            console.log(err);
        }
    });

PHP:

<?php 
    $myquery = "
SELECT A1.circles Circles, A2.arrow arrows, A2.link Links from  `d3-map`.nodes A1, `d3-map`.links A2 
GROUP BY A1.id;
";
    $query = mysql_query($myquery);

    if ( ! $query ) {
        echo mysql_error();
        die;
    }

    $data = array();
    $query_row = mysql_num_rows($query);
    $data[] = mysql_fetch_assoc($query);

    for ($x = 0; $x < $query_row; $x++) {
        $data[] = mysql_fetch_assoc($query);
    }
    echo json_encode($data);  
    mysql_close($server);

Here is the dev tool (print screen on my PC): DevTool

Hey Guys i think i found the problem!

It's seem use d3.js try to get php data must follow d3.js ways to go.
so,i fixed my ajax code use d3.json .

Here's my Code:
JSBin

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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