Jump to content
JChartFX Community
  • 0

Group bars


zeebaah
 Share

Question

Hello, how ive been making some charts, and such using jChart and it looks great, how ever now i need to make some grouped bars...

Ive got a few games where i need a bar for each users procentage correct answers

Heres my json

[
{
"1": {
"user": [
{
"name": "Morten 123",
"procent": 40
},
{
"name": "Spiller 13",
"procent": 40
}
],
"game": "1"
},
"2": {
"user": [
{
"name": "Morten 123",
"procent": 40
},
{
"name": "Spiller 13",
"procent": 40
}
],
"game": "2"
},
"3": {
"user": [
{
"name": "Spiller 13",
"procent": 40
},
{
"name": "Morten 123",
"procent": 40
}
],
"game": "3"
}

] 

5lD68Jm.png Thats by the var data = [{"Game":"Game1", "John":50, "Mark":60}, {"Game":"Game2", "John":20, "Mark":10}];
How ever id like 4 bars here, here they are grouped by game...
So a label called game 1, with 2 bars 1 for mark and one for john.
and the same for game 2.

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

You have 2 options, this will give you users in the X axis, and 2 bars (per each game) for each user, each series will represent one of the games.

    chart1.setGallery(cfx.Bar);

    var data = [{"Name":"John", "Game1":50, "Game2":20}, {"Name":"Mark", "Game1":60, "Game2":10}];

    chart1.setDataSource(data);

Or you can have games in the X axis each series representing a user
 
    var data = [{"Game":"Game1", "John":50, "Mark":60}, {"Game":"Game2", "John":20, "Mark":10}];
    chart1.setDataSource(data);
 
JuanC 
 
 
Link to comment
Share on other sites

  • 0

my json looks like this

[

{

"1": {

"user": [

{

"name": "Morten 123",

"procent": 40

},

{

"name": "Spiller 13",

"procent": 40

}

],

"game": "1"

},

"2": {

"user": [

{

"name": "Morten 123",

"procent": 40

},

{

"name": "Spiller 13",

"procent": 40

}

],

"game": "2"

},

"3": {

"user": [

{

"name": "Spiller 13",

"procent": 40

},

{

"name": "Morten 123",

"procent": 40

}

],

"game": "3"

}

}

]

Can i do it this way, or do i need to change it?

I'm getting the data from my database using php and json...some games might be with 3 users while others is with 10..

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...