简体   繁体   English

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

[英]Why don't see chart of width 50px & height 25px

I need many very small charts on one page, but if I set width 50px and height 25px I do not see chart. 我在一页上需要很多非常小的图表,但是如果我将宽度设置为50px,将高度设置为25px,则看不到图表。 Also I will thanks of suggestions other libraries to create more than 200 charts on page without performance problem. 另外,我还要感谢其他库在页面上创建200多个图表而没有性能问题的建议。

I tried set width and height via css on parent div. 我尝试通过父div上的CSS设置宽度和高度。

https://codesandbox.io/s/m5pl96l8op 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>);
}

I expect very small chart, but I does not see any chart. 我希望图表很小,但看不到任何图表。

In Chartist's docs , you'll find all the options available and their default values. Chartist的文档中 ,您将找到所有可用的选项及其默认值。

Your issue here is that there are margins and paddings everywhere by default, which leaves very little space for your data. 您的问题是默认情况下到处都有边距和填充,这为您的数据留出了很少的空间。 Here are the options you can use to remove any extra space: 您可以使用以下选项来删除任何多余的空间:

https://codesandbox.io/s/4lxl0qvly9 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>
  );
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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