试图创建一个堆叠的酒吧

时间:2019-02-07 09:44:07

标签: stacked-chart

这是我的代码:

 const express = require('express')
const app = express()
var mongoose = require("mongoose")
var path = require('path');
var cors = require("cors");
users=[];
app.use(cors())
'use strict';
var jwt = require('jsonwebtoken');
var iss = "Blitzkrieg Software";
var sub = "joe@user.org";
var aud = "http://blitzkriegsoftware.net";



const fs = require('fs');
var privateKey = `-----BEGIN RSA PRIVATE KEY-----
MIICXAIBAAKBgQCETEqGDNQQKnHp1HV3VNmbp30LP2ErB7b4BMQEbMN1YMSAVwll
jhVvxEs0fI6vax0vFUNLSbSPG4o4Kkrunc+tODUvYJbN7Ejv5lZptVvcfvyUJKBQ
N8NYTucxGyVhS8jiYbev7no5ZHoAGDlzTYunzfWiPJ+81lHVjgsEVwHIqwIDAQAB
AoGAbm17uv6UN9Yl9Uaose16IcmgvzWs9oze9ZCMySC72YrnGjUMG9+IFx2ipHHf
a56d4oH+BKbF9rnHGnB60UeaY0lQN/dYMk+s3xzyHAW1eKYfIaRyJujtG329VJii
Y5JK5Avfctn9/nP8za2Ncxl6qPrWxIQ+fE2/kSHTxsFJB3kCQQC/oQyjpmSH2p6c
aAO9H0p0ikjknEidPMxKnpGxqnpevR17OCKPFcKIXkZST23caG7iUhuLLw4B6DV6
KnvFJR2NAkEAsL0f+WzLIE5U/Jii2t0fupTs+iWkpgYX6BHlNi9HqffO4i+SHt4r
kizkjxqBexaHThgMF1txf+jl7T7hanHlFwJBAKll5tRr7QajXf8Je/SdSqZG8DUX
aqGE81srXcPe3hoNt5gLgZFXPQZrwGJW0Nk8gHkU+EBLsmhBK7T5BTy7mKkCQBej
I6ybNUt7znf9/gHhgwXUNyF5eVzPAdGC2zH0/tOnld7AV/2S3ybspCDTfa+1oqD6
LFvPWg2uW1nwh/tRgj8CQH8wTj5Nn0srrSeW4WUj90aJY4Ec0PQLdzAW8fSr/jdj
hYCQv/Cz9xxCyeTfZC37sahbyc5UbXNtsRH7saYxogQ=
-----END RSA PRIVATE KEY-----`;
var publicKey = `-----BEGIN RSA PRIVATE KEY-----
MIICXAIBAAKBgQCETEqGDNQQKnHp1HV3VNmbp30LP2ErB7b4BMQEbMN1YMSAVwll
jhVvxEs0fI6vax0vFUNLSbSPG4o4Kkrunc+tODUvYJbN7Ejv5lZptVvcfvyUJKBQ
N8NYTucxGyVhS8jiYbev7no5ZHoAGDlzTYunzfWiPJ+81lHVjgsEVwHIqwIDAQAB
AoGAbm17uv6UN9Yl9Uaose16IcmgvzWs9oze9ZCMySC72YrnGjUMG9+IFx2ipHHf
a56d4oH+BKbF9rnHGnB60UeaY0lQN/dYMk+s3xzyHAW1eKYfIaRyJujtG329VJii
Y5JK5Avfctn9/nP8za2Ncxl6qPrWxIQ+fE2/kSHTxsFJB3kCQQC/oQyjpmSH2p6c
aAO9H0p0ikjknEidPMxKnpGxqnpevR17OCKPFcKIXkZST23caG7iUhuLLw4B6DV6
KnvFJR2NAkEAsL0f+WzLIE5U/Jii2t0fupTs+iWkpgYX6BHlNi9HqffO4i+SHt4r
kizkjxqBexaHThgMF1txf+jl7T7hanHlFwJBAKll5tRr7QajXf8Je/SdSqZG8DUX
aqGE81srXcPe3hoNt5gLgZFXPQZrwGJW0Nk8gHkU+EBLsmhBK7T5BTy7mKkCQBej
I6ybNUt7znf9/gHhgwXUNyF5eVzPAdGC2zH0/tOnld7AV/2S3ybspCDTfa+1oqD6
LFvPWg2uW1nwh/tRgj8CQH8wTj5Nn0srrSeW4WUj90aJY4Ec0PQLdzAW8fSr/jdj
hYCQv/Cz9xxCyeTfZC37sahbyc5UbXNtsRH7saYxogQ=
-----END RSA PRIVATE KEY-----`;
var exp = 24;
var signOptions = {
    issuer : iss,
    subject: sub,
    audience: aud,
    expiresIn: exp,
    algorithm: "RS256"
};

var payload = { };

// Populate with fields and data
payload.field01 = "Data 01";
payload.field02 = "Data 02";
payload.field03 = "Data 03";
var token = jwt.sign(payload, publicKey, signOptions);
console.log("Token: " + token);
var decoded = jwt.decode(token, {complete: true});
console.log("Docoded Header: " + JSON.stringify( decoded.header));
console.log("Docoded Payload: " +  JSON.stringify(decoded.payload));

app.use(express.static('public'))
app.use(cors());
app.get('/',(req,res)=>{

    res.render('index')
    res.status=600;

})





server = app.listen(3000,"0.0.0.0");




// app.get('/', function (req, res) { 
//     res.header("Access-Control-Allow-Origin", "*");
//     res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); 
//     res.writeHead(200, {'Content-Type': 'text/plain'});
//     contents = fs.readFileSync("sliderImages.json", "utf8");
//     console.log(path.join(__dirname, '/sliderImages.json'));
//     res.end(contents);
//  });
const io= require('socket.io')(server)
io.on('connection', (socket) => {
    var dbUrl = 'mongodb://brad:1234@localhost:27017/bawa'
    mongoose.connect(dbUrl ,{ useNewUrlParser: true }, (err,db) => { 
        // db.collection("customers").insertOne({"first_name":"gahsat","last_name":"assdf"}, function(err, res) {
        //     if (err) throw err;
        //     console.log("1 document inserted");
        //     db.close();
        //   });

        //   db.collection("customers").find({}, { projection: { _id: 0, first_name: 1, last_name: 1 } }).toArray(function(err, result) {
        //     if (err) throw err;
        //     console.log(result);
        //     db.close();
        //   });
        console.log('Db connected',err);
     })

    console.info('New user connected'+socket.id)

    //default username
    socket.userId = "Anonymous"

    //listen on change_username
    socket.on('change_userId', (data) => {
        console.info('change_userId: ' + data);
        socket.userId = data.userId
    })
    socket.on('register', (data) => {
        console.info('New user cregonnected '+socket.id)
        console.info('register: ' + data);
        socket.userId = data.userId
    })

    socket.on('disconnect', (data) => {
        console.info('change_userId: ' + data);
        socket.userId = data.userId
    })

    socket.on('send message', (data) => {
        console.info('New user sen '+socket.id)
        //var a=JSON.parse(data)
        console.info('messasge: ' + data["kk"]);
        io.sockets.emit('get user','sdfgsdfgsdf')
    })

    //listen on new_message
    socket.on('new_message', async (data) => {
        //broadcast the new message
        let chat = chatDb.chats.find(_chat => _chat.id === data.chatId);
        chat.dialog = [
            ...chat.dialog,
            data.message
        ];
        let userId = data.message.who;
        let contactId = data.contactId;
        const user = chatDb.user.find(_user => _user.id === userId);
        console.info('new_message User: ' + JSON.stringify(user));
        const contact = chatDb.user.find(_user => _user.id === contactId);
        console.info('new_message Contact: ' + JSON.stringify(contact));
        user.chatList.find(_contact => _contact.contactId === contactId).lastMessageTime = data.message.time;
        contact.chatList.find(_contact => _contact.contactId === userId).lastMessageTime = data.message.time;
        console.info('new_message: ' + JSON.stringify(data));
        io.sockets.emit('new_message', {userId: userId, contactId: contactId, chatId: data.chatId, message: data.message});
    })

    //listen on typing
    socket.on('typing', (data) => {
        socket.broadcast.emit('typing', {userId : socket.userId, chatId: data.chatId})
    })
});



console.log('Server Started')

结果

a=df['Case Status'].value_counts()
a.plot(kind = 'bar', stacked = True)

enter image description here

我希望将这些条形物堆叠起来。我可以知道如何实现吗?

0 个答案:

没有答案