0

我没有错误(最终),但我得到的只是没有任何数据的 x 轴。我错过了什么?我从 vsCode 中的 Live Server 插件运行它。此外,plottable 有两个标签:plottable 和 plottable.js。有没有办法摆脱一个而只使用另一个?因此,当有更多 Plottable 问题时,它们不会分散开来。

你可以在这里找到图片:https ://imgur.com/a/ATiF3tU

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();
});
4

1 回答 1

2

plottable.css 正在影响渲染。我尝试检查元素。具有 class="component table" 和 class="component axis y-axis" 的 div 具有顶部、高度和宽度的样式,需要根据您的要求进行更改。

于 2018-08-24T13:48:39.180 回答