gpt4 book ai didi

javascript - 显示来自 Meteor.users 的用户信息,并使用 Highcharts 显示

转载 作者:行者123 更新时间:2023-12-03 02:56:58 24 4
gpt4 key购买 nike

我是 Meteor 的新手,这就是我想做的:我有一些用户会回答不同类型的问题:感受答案是我将为每个用户存储在 mongoDB 中的答案。现在这是我的 HTML:

<p>Select a user to see infos, see answers' progress</p>
{{#each allUsers}}

<div class="patinf">
<br>
<h5><i class="fa fa-user"></i> {{lastName}} {{firstName}}</h5>
<label>
<input type="radio" class="radio-inline" name="{{this.id}}" id="show" value="show" required>
<span><i class="fa fa-bar-chart" aria-hidden="true"></i> Show answers</span>
</label>
<label>
<input type="radio" class="radio-inline" name="{{this.id}}" id="hide" value="hide" checked>
<span><i class="fa fa-times" aria-hidden="true"></i> Hide</span
</label>
</div>
{{#if show}}
<div class="form-group">
<label for="something" class="control-label">Answers' Progress</label>
<div id="something">
<p>Feelings:</p>
<ul>
{{#each allFeelings}}
<li>{{feel}}</li>
{{/each}}
</ul>
<p>Answers:</p>
<ul>
{{#each allAnswers}}
<li>{{answer}}</li>
{{/each}}
</ul>
<br>
</div>
<div id="something" style=" min-width: 310px; height: 400px; margin: 0auto">
{{> highchartsHelper chartId="feels" chartWidth="100%" charHeight="100%" chartObject=topGenresChart}}
<br>
{{> highchartsHelper chartId="answers" chartWidth="100%" charHeight="100%" chartObject=topGenresChart}}
</div>
</div>
{{/if}}
{{/each}}

这是我的 js 文件:

Meteor.subscribe('patientInfos');

Template.patients.helpers({
allAnswers:function(){
return Quests.find({"answer": {$ne:null}});
},
answer: function(){
return this.answer;
}
});

Template.patients.helpers({
allFeelings:function(){
return Quests.find({"feel": {$ne:null}});
},
feel: function(){
return this.feel;
}
});

Template.patients.helpers({
allUsers: function() {
return Meteor.users.find({});
},
id: function(){
ret
},
firstName: function() {
return this.profile.firstName;
},
lastName: function() {
return this.profile.lastName;
}
});


Template.patients.onRendered(function () {
Session.set('show', false);
});

Template.patients.events({
'change #hide': function (event) {
Session.set('show', false);
},
'change #show': function (event) {
Session.set('show', true);
}
});

Template.patients.helpers({
show: function() {
return Session.get('show');
},
});

Template.patients.topGenresChart = function() {
return {
chart: {
type: 'areaspline'
},
title: {
text: 'Answers Progress'
},
legend: {
layout: 'vertical',
align: 'left',
verticalAlign: 'top',
x: 150,
y: 100,
floating: true,
borderWidth: 1,
backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'
},
xAxis: {
categories: [
'W1',
'W2',
'W3',
'W4',
'W5',
'W6',
'W7'
],
plotBands: [{ // last week
from: 5.5,
to: 7,
color: 'rgba(68, 170, 213, .2)'
}]
},
yAxis: {
title: {
text: 'Answers'
},
categories: [
'0',
'1',
'2',
'3',
'4',
'5',
'6'
],
},
tooltip: {
shared: true,
valueSuffix: ' points'
},
credits: {
enabled: false
},
plotOptions: {
areaspline: {
fillOpacity: 0.5
}
},
series: [{
name: 'Question 1 Progress',
data: [3, 4, 3, 5, 1, 5, 6]
}, {
name: 'Question 2 Progress',
data: [1, 3, 2, 3, 2, 5, 4]
}]}
};

现在的问题是,考虑到答案是一个由 10 个数字组成的数组,如何将从 Quests.answer 中获取的数据放入 series.data 中。如何使用#each函数一次显示一个用户的答案数据:实际上,如果我选择显示,我将看到每个用户下的所有用户答案。

任务就像:

Schemas.Quests = new SimpleSchema
createdAt:
type: Date
autoValue: ->
if this.isInsert
new Date()
answer:
type: [Number]
optional:true

feel:
type: Number
optional:true

userId:
type: String

patient:
type: String
optional:true

感觉可以是一个数字:0 1 2。答案是一个包含 10 项的数组,数字从 0 到 6。

编辑:

MongoDB 元素示例:- Meteor.users

createdAt: Tue Dec 05 2017 10:56:24 GMT+0100 
__proto__: Object
emails : Array(1)
0 : {address: "denise@test.it", verified: false}
length : 1
__proto__ : Array(0)
profile :
firstName : "Denise"
lastName : "Blabla"
__proto__ : Object
services :
password: {bcrypt: "$2a$10$ddJ8F.k2uJ2lZaDfvMNEdObxdMXwAdxSSQRYtHRG6Juoh8HVtC8Ju"}
resume : {loginTokens: Array(0)}
__proto__ : Object
_id: "RTS2LR2jaBjidEiB7"
__proto__:Object
length : 4
__proto__: Array(0)

这是任务的示例:

0 : 
answer : (10) ["1", "5", "6", "5", "1", "5", "5", "6", "0", "2"]
patient : "Denise Blabla"
userId : "RTS2LR2jaBjidEiB7"
_id : "7NwjGmGyz7zjbzBqC"
__proto__ : Object
1 :
feel : "0"
patient : "Denise Blabla"
userId : "RTS2LR2jaBjidEiB7"
_id : "5KtDQof3o9gt8CYJg"
__proto__ : Object
2 :
answer : (10) ["0", "4", "4", "0", "4", "5", "0", "1", "3", "6"]
patient : "Denise Blabla"
userId : "RTS2LR2jaBjidEiB7"
_id : "7t46pAihMBNWwmYpN"
__proto__ : Object

我想要的是在表格中显示这样的内容:

Denise Blabla
Week || Q1 || Q2 || ... || Q10 || Feel
Week 1 || 6 || 4 || ... || 1 || 0
Week 2 || 3 || 1 || ... || 5 || 2

Anne Smith
Week || Q1 || Q2 || ... || Q10 || Feel
Week 1 || 5 || 5 || ... || 1 || 1
Week 2 || 3 || 2 || ... || 3 || 0

最佳答案

问题的第一部分,显示相关集合中的数据 Quests在您的模板中:

Template.patients.helpers({
allAnswers() {
return Quests.find({ userId: this._id, answer: { $exists: true }}).map((el) => el.answer);
},
allFeelings() {
return Quests.find({ userId: this._id, feel: { $exists: true }}).map((el) => el.feel);
}
});

这基本上是使用 userId 在相关集合上执行内联加入作为匹配键。

您的 Highcharts 将以类似的方式完成:

Template.patients.topGenresChart = function() {
return {
... chart parameters as you had them before

series: [{
name: 'Question 1 Progress',
data: () => { Quests.find({ userId: this._id, answer: { $exists: true }}).map((el) => el.answer)}
}, {
name: 'Question 2 Progress',
data: () => { Quests.find({ userId: this._id, feel: { $exists: true }}).map((el) => el.feel)}
}]}
};

但是:

  1. 在你的问题中你说answer是一个由 10 个数字组成的数组,但您的架构将其定义为 String 。您是说 [String]
  2. 你说的是feel是一个数字0 1 2但您的模板正在使用 {{#each}} 对其进行迭代.
  3. 根本不清楚您想在两个系列中绘制什么图表。您的示例数据有每个包含 7 个元素的数组,但是来自 Quests 的数据是什么?应该进去吗?
  4. 您引用的是相同的图表数据:chartObject=topGenresChart两次来自 {{> highchartsHelper ...}} - 这意味着您将显示完全相同的图表两次,即使您为每个图表提供了不同的 ID。你的意图是什么?

无论如何,答案应该足以让您继续前进。

另请注意,您的 feelanswer助手是多余的。您可以使用{{feel}}{{answer}}直接在模板中,无需通过助手,因为这些助手只是返回 this.feelthis.answer分别。

关于javascript - 显示来自 Meteor.users 的用户信息,并使用 Highcharts 显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47575013/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com