Is there a z-index property for keys?
Posted by Joachim at 08:26 on Wednesday 30th October 2024 [link]
If you have a key within a (e.g.) line chart I may be ovelayed by part of the chart.
I tried to find out a way (like using a css z-index value) to place keys ontop of chart. Do you have a solution for this?
I tried to find out a way (like using a css z-index value) to place keys ontop of chart. Do you have a solution for this?
Posted by Richard at 10:26 on Wednesday 30th October 2024 [link]
How is your chart created? The keys are by default placed above the chart. Like this example shows:
<script>
new RGraph.Line({
id: 'cvs',
data: [4,8,6,4,5,2,1,3,6,4,10,9],
options: {
key: ['Freddy','Killian', 'Charles'],
keyBackground: '#fffa'
}
}).draw();
</script>
If you have two charts drawn on the same canvas then the second will be drawn over the first. So if you have a key on the first chart it will appear below the second chart.
The solution here would be to move the key and its configuration properties to the second chart. Like this:
<script>
new RGraph.Bar({
id: 'cvs',
data: [4,8,6,4,5,2,1,3,6,4,10,9],
options: {
colors: ['black']
}
}).draw();
new RGraph.Line({
id: 'cvs',
data: [4,8,6,4,5,2,1,3,6,4,10,9],
options: {
colors: ['red','black'],
backgroundGrid: false,
yaxisScale: false,
xaxis: false,
yaxis: false,
key: ['Freddy','Killian'],
keyBackground: '#fffa',
marginInner: 25,
linewidth: 5
}
}).draw();
</script>
<script>
new RGraph.Line({
id: 'cvs',
data: [4,8,6,4,5,2,1,3,6,4,10,9],
options: {
key: ['Freddy','Killian', 'Charles'],
keyBackground: '#fffa'
}
}).draw();
</script>
If you have two charts drawn on the same canvas then the second will be drawn over the first. So if you have a key on the first chart it will appear below the second chart.
The solution here would be to move the key and its configuration properties to the second chart. Like this:
<script>
new RGraph.Bar({
id: 'cvs',
data: [4,8,6,4,5,2,1,3,6,4,10,9],
options: {
colors: ['black']
}
}).draw();
new RGraph.Line({
id: 'cvs',
data: [4,8,6,4,5,2,1,3,6,4,10,9],
options: {
colors: ['red','black'],
backgroundGrid: false,
yaxisScale: false,
xaxis: false,
yaxis: false,
key: ['Freddy','Killian'],
keyBackground: '#fffa',
marginInner: 25,
linewidth: 5
}
}).draw();
</script>
Posted by Joachim at 10:27 on Wednesday 30th October 2024 [link]
hi,
Problem happens only if using option "filledRange" with line chart (line will overlay key)
Problem happens only if using option "filledRange" with line chart (line will overlay key)
Posted by Richard at 12:10 on Wednesday 30th October 2024 [link]
In that case you could try using a second Line chart which is drawn after your main chart which has similar settings except that axes, the scale and the background grid have been turned off and the data for the line is just [0]. Then add the key to this chart.
Because it's drawn after the main chart the key will be drawn on top as well - thus making it appear over the first chart. Here's some example code:
<script>
// The main Line chart object
new RGraph.Line({
id: 'cvs',
data: [
[4,8,6,4,5,2,1,3,6,4,10,9],
[1,2,3,2,3,1,0,0,2,1,2,1]
],
options: {
colors: ['red','red'],
marginInner: 25,
linewidth: 5,
shadow: false,
filled: true,
filledRange: true,
filledColors: ['pink']
}
}).draw();
// The second Line chart object that just draws the key
new RGraph.Line({
id: 'cvs',
data: [0],
options: {
colors: ['#0000'],
key: ['Freddy','Killian'],
keyColors: ['red','black'],
keyBackground: '#fffa',
marginInner: 25,
linewidth: 1,
shadow: false,
backgroundGrid: false,
xaxis: false,
yaxis: false,
yaxisScale: false
}
}).draw();
</script>
Because it's drawn after the main chart the key will be drawn on top as well - thus making it appear over the first chart. Here's some example code:
<script>
// The main Line chart object
new RGraph.Line({
id: 'cvs',
data: [
[4,8,6,4,5,2,1,3,6,4,10,9],
[1,2,3,2,3,1,0,0,2,1,2,1]
],
options: {
colors: ['red','red'],
marginInner: 25,
linewidth: 5,
shadow: false,
filled: true,
filledRange: true,
filledColors: ['pink']
}
}).draw();
// The second Line chart object that just draws the key
new RGraph.Line({
id: 'cvs',
data: [0],
options: {
colors: ['#0000'],
key: ['Freddy','Killian'],
keyColors: ['red','black'],
keyBackground: '#fffa',
marginInner: 25,
linewidth: 1,
shadow: false,
backgroundGrid: false,
xaxis: false,
yaxis: false,
yaxisScale: false
}
}).draw();
</script>
[Replies are closed]