Javascript 如何在meteor js中使用mysql为动态highchart准备数据?

Javascript 如何在meteor js中使用mysql为动态highchart准备数据?,javascript,meteor,highcharts,Javascript,Meteor,Highcharts,我正在MeteorJS中创建我的第一个highchart。我正在使用mysql。 我添加了highchart和numtel包 下面是我使用过的代码 server.js var liveDb = new LiveMysql({ host: 'localhost', user: 'root', password: 'password', database: 'database_name' }); var closeAndExit = function () {

我正在MeteorJS中创建我的第一个highchart。我正在使用mysql。 我添加了highchart和numtel包

下面是我使用过的代码

server.js

var liveDb = new LiveMysql({
    host: 'localhost',
    user: 'root',
    password: 'password',
    database: 'database_name'
});

var closeAndExit = function () {
    liveDb.end();
    process.exit();
};

// Close connections on hot code push
process.on('SIGTERM', closeAndExit);
// Close connections on exit (ctrl + c)
process.on('SIGINT', closeAndExit);

Meteor.publish('getAllUsers', function () {
    return liveDb.select(
        'SELECT name,total FROM table_name ORDER BY total DESC',
        [{table: 'table_name'}]
    );
});
allUsers = new MysqlSubscription('getAllUsers');

function createHighChart() {
  $('#container').highcharts({
    chart: {
      type: 'column'
    },
    title: {
      text: 'All Users'
    },
    xAxis: {
      type: "category"
    },
    series: [{
        data: **?????** // What should be here to display data.?
      }]
  });
}

/*Template.allUsersTemp.onCreated(function() {
});*/


Template.allUsersTemp.onRendered(function() {
  this.autorun(() => {
    createHighChart();
  });
});
client.js

var liveDb = new LiveMysql({
    host: 'localhost',
    user: 'root',
    password: 'password',
    database: 'database_name'
});

var closeAndExit = function () {
    liveDb.end();
    process.exit();
};

// Close connections on hot code push
process.on('SIGTERM', closeAndExit);
// Close connections on exit (ctrl + c)
process.on('SIGINT', closeAndExit);

Meteor.publish('getAllUsers', function () {
    return liveDb.select(
        'SELECT name,total FROM table_name ORDER BY total DESC',
        [{table: 'table_name'}]
    );
});
allUsers = new MysqlSubscription('getAllUsers');

function createHighChart() {
  $('#container').highcharts({
    chart: {
      type: 'column'
    },
    title: {
      text: 'All Users'
    },
    xAxis: {
      type: "category"
    },
    series: [{
        data: **?????** // What should be here to display data.?
      }]
  });
}

/*Template.allUsersTemp.onCreated(function() {
});*/


Template.allUsersTemp.onRendered(function() {
  this.autorun(() => {
    createHighChart();
  });
});

我想准备json数据并绑定到series。请帮我做这个。

我认为应该有空数据,您可以监听更改:

series: [{
    data: []
  }]
以及:


注意:
数据
应为Highcharts()要求的格式,因此您可能需要预处理数据。

谢谢Pawel。你引导我改变事件的方向。我可以按照以下var json=[{“name”:“A”,“total”:“40”},{“name”:“B”,“total”:“70”},{“name”:“C”,“toatal”:“90”}提取name和total吗;我不确定你想要实现什么。在高位图表中,应该有“
y:value
”,而不是“total”。此外,数字实际上应该是一个数字,而不是字符串。例如:
var json=[{“name”:“A”,“total”:“40”},{“name”:“B”,“total”:“70”},{“name”:“C”,“toatal”:“90”}).map(函数(点){point.y=parseFloat(point.total);返回点;})ohk。。好的,谢谢你,波威尔。。它对我有用。。谢谢。