React-d3 diagram not showing

I followed the step by step instructions to get the diagram in react-d3 :

http://www.reactd3.org/get_start/

I added this to my code and I can't see anything.

However, if I check, I can see an SVG tag with some things in it.

enter image description here

Was some element squished or do you need to tweak something to render the SVG in the browser?

My exact code looks like this:

import React from 'react';

var Chart = require('react-d3-core').Chart;
var LineChart = require('react-d3-basic').LineChart;

class WelcomeView extends React.Component {

  render() {

    var chartData = [
      {"name":"Darron Weissnat IV","BMI":20.72,"age":39,"birthday":"2005-01-03T00:00:00.000Z","city":"East Russel","married":false,"index":0},
      {"name":"Guido Conroy","BMI":25.17,"age":39,"birthday":"1977-04-20T00:00:00.000Z","city":"Scarlettland","married":true,"index":20},
      {"name":"Miss Demond Weissnat V","BMI":21.44,"age":19,"birthday":"2007-06-09T00:00:00.000Z","city":"Savionberg","married":false,"index":21},
      {"name":"Easton Mante","BMI":20.61,"age":43,"birthday":"2007-01-29T00:00:00.000Z","city":"Kutchberg","married":false,"index":22},
      {"name":"Dayton Ebert","BMI":29.88,"age":20,"birthday":"1978-04-27T00:00:00.000Z","city":"West Wiley","married":true,"index":23}
    ]

    var width = 700,
      height = 300,
      margins = {left: 100, right: 100, top: 50, bottom: 50},
      title = "User sample",
      chartSeries = [
        {
          field: 'BMI',
          name: 'BMI',
          color: '#ff7f0e'
        }
      ],
      // your x accessor
      x = function(d) {
        return d.index;
      }

    return (
      <div>
          <div>
            <Chart
              title={title}
              width={width}
              height={height}
              margins= {margins}
            >
              <LineChart
                margins= {margins}
                title={title}
                data={chartData}
                width={width}
                height={height}
                chartSeries={chartSeries}
                x={x}
              />
            </Chart>
          </div>
      </div>
    );
  }
}

export default WelcomeView;

      

I think I followed correctly, so I'm not sure what I am doing wrong.

UPDATE:

If I dynamically add another SVG element above the chart element, like a circle:

<svg height="100" width="100">
  <circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red" />
</svg>

      

Then a circle appears, and magically adding an SVG element starts the diagram rendering process.

It is very vague why this will happen :(

+3


source to share


1 answer


I followed the same steps and was initially unable to display it.

However, I noticed that in the example code they are listed from gitHub they did not insert LineChart inside the chart (as in the instructions). As soon as I removed the enclosing "graph" my graph appeared.



return (
      <LineChart
        //showXGrid={false}
        //showYGrid={false}
        margins= {margins}
        title={title}
        data={chartData}
        width={width}
        height={height}
        chartSeries={chartSeries}
        x={x}
      />
    );
      

Run codeHide result


+8


source







All Articles