javascript - 为什么看不到宽度 50px 和高度 25px 的图表

标签 javascript chartist.js

我在一页上需要很多非常小的图表,但如果我设置宽度 50px 和高度 25px,我就看不到图表。此外,我将感谢其他库在页面上创建 200 多个图表而没有性能问题的建议。

我尝试在父 div 上通过 css 设置宽度和高度。

https://codesandbox.io/s/m5pl96l8op

import React from "react";
import ReactDOM from "react-dom";
import Chart from "react-chartist";

import "./styles.css";

function App() {
  return (
    <div className="App">
      <Chart
        className="chart"
        data={{
          series: [[1, 3, 2, 8, 4, 12, 27, 16]]
    }}
    type="Line"
    options={{
      fullWidth: true,
      width: "50px",
      height: "25px",
      showPoint: false,
      axisY: {
        showGrid: false,
        showLabel: false
      },
      axisX: {
        showGrid: false,
        showLabel: false
      }
    }}
  />
    </div>);
}

我希望图表非常小,但我没有看到任何图表。

最佳答案

Chartist's docs ,您会找到所有可用选项及其默认值。

这里的问题是默认情况下到处都有边距和填充,这为您的数据留下的空间非常小。以下是您可以用来删除任何额外空间的选项:

https://codesandbox.io/s/4lxl0qvly9

function App() {
  // We'll use this multiple times, so declare it here
  const series = [1, 3, 2, 8, 4, 12, 27, 16];
  return (
    <div className="App">
      <Chart
        className="chart"
        data={{
          series: [series]
        }}
        type="Line"
        options={{
          fullWidth: true,
          width: "50px",
          height: "25px",
          low: Math.min(...series), // Remove space around min and max values
          high: Math.max(...series), // Remove space around min and max values
          chartPadding: {
            // Remove all padding
            top: 0,
            right: 0,
            bottom: 0,
            left: 0
          },
          showPoint: false,
          axisY: {
            offset: 0, // Remove any offset
            position: "start", // Remove any bottom margin
            showGrid: false,
            showLabel: false
          },
          axisX: {
            offset: 0, // Remove any offset
            position: "start", // Remove any left margin
            showGrid: false,
            showLabel: false
          }
        }}
      />
    </div>
  );
}

关于javascript - 为什么看不到宽度 50px 和高度 25px 的图表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53925173/

相关文章:

javascript - 如何根据数据更改线条颜色 - Chartist 或 Chart.js

javascript - 如何让 D3 数据驱动文档在正确的时区显示 moment.js 日期时间?

javascript - if(window.jQuery) 加载 jQuery 后返回 false

javascript,html onclick更改变量

chartist.js - Chartist 插件工具提示 : Adding the label in the tooltip

javascript - Chartist.js 在 vue.js 中显示工具提示

javascript - 使用带有时间序列数据的three.js

javascript - 如何重新绑定(bind)具有相同名称的方法

javascript - Chartist.js - 为什么圆环图的中心是黑色的?