Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Sascha Herzinger
AdaCharts
Commits
fdc67ef1
Commit
fdc67ef1
authored
Mar 20, 2019
by
Sascha Herzinger
Browse files
added random data method
parent
cfb97ced
Changes
1
Hide whitespace changes
Inline
Side-by-side
examples/test-barplot.html
View file @
fdc67ef1
...
...
@@ -22,6 +22,46 @@
* Helper function. Do not copy
*/
function
generateRandomData
()
{
const
rng
=
Math
.
random
();
const
numCategories
=
Math
.
floor
(
Math
.
random
()
*
9
+
1
);
const
numGroups
=
Math
.
floor
(
Math
.
random
()
*
9
+
1
);
const
categories
=
[];
for
(
let
i
=
0
;
i
<
numCategories
;
i
+=
1
)
{
categories
.
push
(
String
.
fromCharCode
(
65
+
i
));
}
const
groups
=
[];
for
(
let
i
=
0
;
i
<
numGroups
;
i
+=
1
)
{
groups
.
push
(
String
.
fromCharCode
(
97
+
i
));
}
const
series
=
[];
groups
.
forEach
(
group
=>
{
series
.
push
({
name
:
group
,
data
:
categories
.
map
(
category
=>
{
return
{
name
:
category
,
y
:
Math
.
floor
(
Math
.
random
()
*
10000
)
}
})
});
});
// if (rng
<
0.33
)
{
// contains only negative
//
// } else if (rng >= 0.33 && rng
<
0.66
)
{
// contains only positive
//
// } else { // contains negative and positive
//
// }
return
{
groups
,
categories
,
series
};
}
/**
* API Documentation below this point
...
...
@@ -30,71 +70,12 @@
const
barplot
=
AdaCharts
.
chart
({
chartType
:
'
barplot
'
,
container
});
function
update
()
{
const
randomData
=
generateRandomData
();
barplot
.
update
({
title
:
"
Gender by Site ID
"
,
categories
:
[
"
Undefined
"
,
"
Female
"
,
"
Male
"
]
,
title
:
"
Random generated example
"
,
categories
:
randomData
.
categories
,
barClickCallback
:
d
=>
console
.
log
(
d
),
series
:
[
{
"
name
"
:
"
CHEM
"
,
"
data
"
:
[
{
"
name
"
:
"
Undefined
"
,
"
y
"
:
0
},
{
"
name
"
:
"
Female
"
,
"
y
"
:
27
,
"
key
"
:
"
2
"
},
{
"
name
"
:
"
Male
"
,
"
y
"
:
40
,
"
key
"
:
"
1
"
}
],
"
colorByPoint
"
:
false
},
{
"
name
"
:
"
CHL
"
,
"
data
"
:
[
{
"
name
"
:
"
Undefined
"
,
"
y
"
:
0
},
{
"
name
"
:
"
Female
"
,
"
y
"
:
437
,
"
key
"
:
"
2
"
},
{
"
name
"
:
"
Male
"
,
"
y
"
:
710
,
"
key
"
:
"
1
"
}
],
"
colorByPoint
"
:
false
},
{
"
name
"
:
"
Flying Team
"
,
"
data
"
:
[
{
"
name
"
:
"
Undefined
"
,
"
y
"
:
0
},
{
"
name
"
:
"
Female
"
,
"
y
"
:
15
,
"
key
"
:
"
2
"
},
{
"
name
"
:
"
Male
"
,
"
y
"
:
26
,
"
key
"
:
"
1
"
}
],
"
colorByPoint
"
:
false
},
{
"
name
"
:
"
La Tulipe
"
,
"
data
"
:
[
{
"
name
"
:
"
Undefined
"
,
"
y
"
:
0
},
{
"
name
"
:
"
Female
"
,
"
y
"
:
3
,
"
key
"
:
"
2
"
},
{
"
name
"
:
"
Male
"
,
"
y
"
:
30
,
"
key
"
:
"
1
"
}
],
"
colorByPoint
"
:
false
},
{
"
name
"
:
"
CIEC (discontinued; use CHL instead)
"
,
"
data
"
:
[
{
"
name
"
:
"
Undefined
"
,
"
y
"
:
0
},
{
"
name
"
:
"
Female
"
,
"
y
"
:
435
,
"
key
"
:
"
2
"
},
{
"
name
"
:
"
Male
"
,
"
y
"
:
394
,
"
key
"
:
"
1
"
}
],
"
colorByPoint
"
:
false
},
{
"
name
"
:
"
Undefined
"
,
"
data
"
:
[
{
"
name
"
:
"
Undefined
"
,
"
y
"
:
9
},
{
"
name
"
:
"
Female
"
,
"
y
"
:
3
,
"
key
"
:
"
2
"
},
{
"
name
"
:
"
Male
"
,
"
y
"
:
0
,
"
key
"
:
"
1
"
}
],
"
colorByPoint
"
:
false
}
],
inverted
:
false
,
xAxisCaption
:
null
,
yAxisCaption
:
"
Count
"
,
showLabels
:
true
,
showLegend
:
true
series
:
randomData
.
series
,
});
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment