简体   繁体   English

具有时间序列和附加 y 轴 c3.js 的数据 arrays

[英]data arrays with timeseries and additional y axis c3.js

I want a timeseries plot with a second y axis with data from 3 arrays:我想要一个时间序列 plot 和第二个 y 轴,数据来自 3 arrays:

var DATE = ['2020-08-14 09:04:12','2020-08-14 09:04:13','2020-08-14 09:04:14'];
var TEMPIN = [12,6,14];
var PRESS = [2000,1988,2002];

But it plots both datasets on y1 and y2 is empty I want array "DATE" is x and "TEMPIN" data on y1 and "PRESS" data on y2.但它在 y1 和 y2 上绘制两个数据集为空我想要数组“DATE”是 x,y1 上的“TEMPIN”数据和 y2 上的“PRESS”数据。 What I am doing wrong?我做错了什么?

Full code:完整代码:

var DATE = ['2020-08-14 09:04:12','2020-08-14 09:04:13','2020-08-14 09:04:14'];
var TEMPIN = [12,6,14];
var PRESS = [2000,1988,2002];

DATE.unshift('x');
TEMPIN.unshift('data1');
PRESS.unshift('data2');

          var chart = c3.generate({
                bindto: '#graph',
                data: {
                    x: 'x',
                    xFormat: '%Y-%m-%d %H:%M:%S',
                    columns: [
                        DATE,
                        TEMPIN,
                        PRESS
                    ]
                },
                axes: {
                    data1: 'y1',
                    data2: 'y2'
                },
                axis: {
                    y2: {
                        show:true
                    },
                    x: {
                        type: 'timeseries',
                        tick: {
                            format: '%H:%M:%S'
                        }
                    }
                }
            })

Solved by moving the "axes:" part into the "data:" and changing通过将“axes:”部分移动到“data:”并更改来解决

data1: 'y1'

to

data1: 'y'

Full code:完整代码:

            var DATE = ['2020-08-14 09:04:12', '2020-08-14 09:04:13', '2020-08-14 09:04:14'];
            var TEMPIN = [12, 6, 14];
            var PRESS = [2000, 1988, 2002];

            DATE.unshift('x');
            TEMPIN.unshift('data1');
            PRESS.unshift('data2');

            var chart = c3.generate({
                bindto: '#graph',
                data: {
                    x: 'x',
                    xFormat: '%Y-%m-%d %H:%M:%S',
                    columns: [
                        DATE,
                        TEMPIN,
                        PRESS
                    ],
                    axes: {
                        data1: 'y',
                        data2: 'y2'
                    }
                },
                axis: {
                    y2: {
                        show: true
                    },
                    x: {
                        type: 'timeseries',
                        tick: {
                            format: '%H:%M:%S'
                        }
                    }
                }
            });

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

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