javascripthtmlplottable

Why is Plottable not showing the full chart?


I have no errors (finally) but all I get is an x-axis without any data. What am I missing? I am running this from the Live Server plugin in vsCode. Also, there are two tags for plottable: plottable and plottable.js. Is there a way to get rid of one and only use the other? So when there are more Plottable questions, they aren't spread out.

You can find the image here: https://i.sstatic.net/QiHFp.jpg

HTML

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Testing Plottable</title>
  <script src="//cdnjs.cloudflare.com/ajax/libs/d3/4.5.0/d3.js" charset="utf-8"></script>
  <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
  <script src="//unpkg.com/plottable/plottable.js" charset="utf-8"></script>
  <script src="index.js"></script>
  <link rel="stylesheet" type="text/css" href="//unpkg.com/plottable/plottable.css">
</head>
<body>
  <p>testing plottable.js</p>
  <div id="example"></div>
</body>
</html>

JavaScript

function makeBasicChart() {

  var xScale = new Plottable.Scales.Linear();
  var yScale = new Plottable.Scales.Linear();

  var xAxis = new Plottable.Axes.Numeric(xScale, "bottom");
  var yAxis = new Plottable.Axes.Numeric(yScale, "left");

  var plot = new Plottable.Plots.Line();
  plot.x(function(d) { return d.x; }, xScale);
  plot.y(function(d) { return d.y; }, yScale);

  var data = [
    { "x": 0, "y": 1 },
    { "x": 1, "y": 2 },
    { "x": 2, "y": 4 },
    { "x": 3, "y": 8 }
  ];

  var dataset = new Plottable.Dataset(data);
  plot.addDataset(dataset);

  var chart = new Plottable.Components.Table([
    [yAxis, plot],
    [null, xAxis]
  ]);

  chart.renderTo("div#example");

}

$(document).ready(function() {
  makeBasicChart();
});

Solution

  • The plottable.css is affecting the rendering. I tried inspecting elements. div with class="component table" and class="component axis y-axis" has styles for top, height and width that needs to be changed according to your requirement.