首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AnyChart火库

AnyChart火库
EN

Stack Overflow用户
提问于 2018-05-16 16:09:57
回答 1查看 222关注 0票数 0

我是AnyChart图表库的新手。我想使用AnyChart来绘制从火库中拉出的数据。我现在面临着在AnyChart上绘制数组数据的问题。我现在遇到了使用以下代码从Firebase拉取数组数据集的问题:

代码语言:javascript
复制
dbRef2.limitToLast(20).on('child_added',function(snap) {

var Time2 = snap.val().timestamp;
var Humidex2 = snap.val().Humidex;

dataSetFirebaseHumidex2.push({x: Time2 ,y: Humidex2});
console.log(dataSetFirebaseHumidex2);
});

anychart.onDocumentReady(function () {

// create a data set
var data = anychart.data.set();

data.data([dataSetFirebaseHumidex2]);

// map the data
var seriesData_1 = data.mapAs({x: 0, y: 1});

// create a chart
var chart = anychart.area();

// create the first series, set the data and name
var series1 = chart.spline(data);
series1.name("S1");

// configure the visual settings of the first series
series1.normal().stroke("#00cc99", 1, "10 5", "round");
series1.hovered().stroke("#00cc99", 2, "10 5", "round");
series1.selected().stroke("#00cc99", 4, "10 5", "round");

// set the chart title
chart.title("Humidex Index");

// set the titles of the axes
chart.xAxis().title("Time");
chart.yAxis().title("Humidex");

// set the container id
chart.container("container");

// initiate drawing the chart
chart.draw();
});

有没有人能给点建议?非常感谢您的帮助。

EN

回答 1

Stack Overflow用户

发布于 2018-05-17 15:38:16

这段代码应该修改如下:

代码语言:javascript
复制
anychart.onDocumentReady(function () {
// create a data set 
var data = anychart.data.set(dataSetFirebaseHumidex2);
// map the data
var seriesData_1 = data.mapAs({x: 'x', value: 'y'});
// create a chart 
var chart = anychart.area(); 
// create the first series, set the data and name
//var series1 = chart.splineArea(data); 
var series1 = chart.spline(data);
series1.name("Meter 1"); 
// configure the visual settings of the first series 
series1.normal().stroke("#00cc99", 1, "10 5", "round"); 
series1.hovered().stroke("#00cc99", 2, "10 5", "round"); 
series1.selected().stroke("#00cc99", 4, "10 5", "round"); 
// set the chart title 
chart.title("Total Active Power Consumption (ShellKK)"); 
// set the titles of the axes 
chart.xAxis().title("Time"); 
chart.yAxis().title("Total Active Power, kWh");
//enable dateTime xScale
chart.xScale(anychart.scales.dateTime());
// set the container id 
chart.container("container").draw(); 
});

但是,请确保在执行此代码之前,dataSetFirebaseHumidex2变量应该已经包含以下格式的数据(对象数组):

代码语言:javascript
复制
[
    {x: 1526446204973, y: 12},
    {x: 1526456204973, y: 14},
    ....
    ......
    {x: 1526466204973, y: 15}
  ]
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50365538

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档