图表 beginAtZero: true, min:0 和 title:“分钟”不起作用

发布于 2025-01-09 18:50:58 字数 2282 浏览 1 评论 0 原文

我希望我的反应图表中的 Y 轴从 0 开始,我一直在尝试很多解决方案,例如 beginAtZero: true 和 min:0 但不起作用。

import React, { Component } from 'react';

// Documentation https://www.npmjs.com/package/react-charts
import { Chart } from 'react-charts';

我还想向 X 轴添加标题标题:分钟也不起作用,这是代码:

MyChart = () => {
    this.componentRef = React.createRef();
    if (this.state.selectedDocumentContent !== undefined) {
        const content = this.state.selectedDocumentContent;
        const firstTimeStamp = this.toTimestampSeconds(content.time);
        const metricKeys = Object.keys(content.metrics);
        var data = [];
        for (var i = 1; i < metricKeys.length-1; i++) {
            const entries = content.metrics[metricKeys[i]];
            var metricData = [];
            for (var j = 0; j < entries.length; j++) {
                let entry = entries[j];
                let timestamp = this.toTimestampSeconds(entry.time);
                metricData.push([timestamp - firstTimeStamp, entry.value]);
            }
            data.push({ label: metricKeys[i], data: metricData })
        }

        const axes = [
            { primary: true, type: 'linear', position: 'bottom', title: 'minutes' }, //x
            { type: 'linear', position: 'left', options: {
                scales: {
                    yAxes: [{
                        display: true,
                        ticks: {
                            beginAtZero: true,
                            min:0
                        }
                    }]
                }} //y
            }
        ];


        const lineChart = (
            // A react-chart hyper-responsively and continuously fills the available
            // space of its parent element automatically
            
            <div
                style={{
                    margin: '30px',
                    width: '600px',
                    height: '400px'
                }}
            >
                <Chart data={data} axes={axes} tooltip/>
            </div>
        )
        return lineChart;
    }
}

我正在使用此图表: https://www.npmjs.com/package/react-charts “反应图表”:“^2.0.0-beta.7”。

I want the axis Y from my react-chart starts from 0, I have been trying many solutions, like beginAtZero: true and min:0 but is doesn't work.

import React, { Component } from 'react';

// Documentation https://www.npmjs.com/package/react-charts
import { Chart } from 'react-charts';

I would like also to add title to axis X title:minutes doesn't work either, here is the code:

MyChart = () => {
    this.componentRef = React.createRef();
    if (this.state.selectedDocumentContent !== undefined) {
        const content = this.state.selectedDocumentContent;
        const firstTimeStamp = this.toTimestampSeconds(content.time);
        const metricKeys = Object.keys(content.metrics);
        var data = [];
        for (var i = 1; i < metricKeys.length-1; i++) {
            const entries = content.metrics[metricKeys[i]];
            var metricData = [];
            for (var j = 0; j < entries.length; j++) {
                let entry = entries[j];
                let timestamp = this.toTimestampSeconds(entry.time);
                metricData.push([timestamp - firstTimeStamp, entry.value]);
            }
            data.push({ label: metricKeys[i], data: metricData })
        }

        const axes = [
            { primary: true, type: 'linear', position: 'bottom', title: 'minutes' }, //x
            { type: 'linear', position: 'left', options: {
                scales: {
                    yAxes: [{
                        display: true,
                        ticks: {
                            beginAtZero: true,
                            min:0
                        }
                    }]
                }} //y
            }
        ];


        const lineChart = (
            // A react-chart hyper-responsively and continuously fills the available
            // space of its parent element automatically
            
            <div
                style={{
                    margin: '30px',
                    width: '600px',
                    height: '400px'
                }}
            >
                <Chart data={data} axes={axes} tooltip/>
            </div>
        )
        return lineChart;
    }
}

I am using this chart: https://www.npmjs.com/package/react-charts
"react-charts": "^2.0.0-beta.7".

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

那些过往 2025-01-16 18:50:58

固定的!我几乎对此感到疯狂,我用 base:0 解决了它。

 const axes = [
            { primary: true, type: 'linear', position: 'bottom'}, //x
            { type: 'linear', position: 'left', base: 0}  //y
        ];

仍然没有解决标题问题......继续调查......
有人知道如何设置最大值吗? (最大:X,不起作用)

Fixed! I almost got crazy about this, I solved it with base:0.

 const axes = [
            { primary: true, type: 'linear', position: 'bottom'}, //x
            { type: 'linear', position: 'left', base: 0}  //y
        ];

Still did not fix the issue with the title... continuing the investigation....
Does anybody knows about how to set a maximum value? (max: X, does not work)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文