So i have a bar chart set up to display two different datasets that take place at more or less the same time, but have some missing data from hour to hour:
The data in this graph is stored in the format {x:timestamp, y:value}, and bars are all located at the correct positions, however some of the tooltips are wrong:
In this example, my mouse is highlighted over the "1AM" bar for dataset "0", yet the timestamp says it is at 9:00 AM, and the 9:00 bar for dataset "1" is highlighted. Also, the data displayed in the tooltip (1.279) is actually correct for 1AM, not 9.
From what I can tell, this seems to happen because there is a different number of data points in each dataset, and the "index" mode for tooltips doesn't handle this correctly. The data for this chart is below:
{
backgroundColor: "rgba(240, 80, 45, 0.63)",
borderColor: "#f0502d",
label: "1",
data:[
{
"x": 1589497200000,
"y": 0.014
},
{
"x": 1589500800000,
"y": 0.003
},
{
"x": 1589504400000,
"y": 0
},
{
"x": 1589536800000,
"y": 0
},
{
"x": 1589540400000,
"y": 0.023
},
{
"x": 1589544000000,
"y": 0.251
},
{
"x": 1589547600000,
"y": 0.599
},
{
"x": 1589551200000,
"y": 0.896
},
{
"x": 1589554800000,
"y": 1.582
},
{
"x": 1589558400000,
"y": 2.335
},
{
"x": 1589562000000,
"y": 1.302
},
{
"x": 1589565600000,
"y": 2.774
},
{
"x": 1589569200000,
"y": 2.432
},
{
"x": 1589572800000,
"y": 1.257
},
{
"x": 1589576400000,
"y": 0.056
}
]},
{
[
label:"0",
backgroundColor: "rgba(217, 217, 216, 0.63)",
borderColor: "#d9d9d8",
data:{
"x": 1589497200000,
"y": 0.014
},
{
"x": 1589500800000,
"y": 0.003
},
{
"x": 1589504400000,
"y": 0
},
{
"x": 1589536800000,
"y": 0
},
{
"x": 1589540400000,
"y": 0.023
},
{
"x": 1589544000000,
"y": 0.251
},
{
"x": 1589547600000,
"y": 0.599
},
{
"x": 1589551200000,
"y": 0.896
},
{
"x": 1589554800000,
"y": 1.582
},
{
"x": 1589558400000,
"y": 2.335
},
{
"x": 1589562000000,
"y": 1.302
},
{
"x": 1589565600000,
"y": 2.774
},
{
"x": 1589569200000,
"y": 2.432
},
{
"x": 1589572800000,
"y": 1.257
},
{
"x": 1589576400000,
"y": 0.056
}
]}
And the options for this chart: (note that CustomTooltips is just
{
tooltips: {
enabled: true,
intersect: true,
mode: 'index',
position: 'nearest',
},
maintainAspectRatio: false,
legend: {
display: true,
position: 'bottom'
},
scales: {
xAxes: [
{
type:"time",
distribution:"series",
offset:true,
time:{
},
scaleLabel: {
display: true
},
ticks: {
maxRotation: 0,
maxTicksLimit: 12,
}
}],
yAxes: [
{
ticks: {
beginAtZero: true,
maxTicksLimit: 8,
}
}],
},
elements: {
point: {
radius: 0,
hitRadius: 10,
hoverRadius: 4,
hoverBorderWidth: 5,
},
},
}
So my question is: how can I get the tooltips displaying the correct times and correct values?
I could switch the tooltip mode to "x", but then the tooltip only displays for one bar at a time, rather than the bars for both datasets that happen at the same time, so I'd rather not do this.
The cause of your problem may be related to a buggy version of Chart.js. Therefore makek sure to use the latest stable version of the library (currently v2.9.3).
Your code looks fine to me. Nevertheless I made the following slight changes to it.
...removed the elements object from the chart options.
...defined xAxis.time as follows to make sure, the hours in the tick labels and in the tooltip are of the same format.
xAxes: [{
type: "time",
...
time: {
unit: 'hour',
tooltipFormat: 'hA'
},
Please have a look at your amended runnable code below.
const datasets = [{
backgroundColor: "rgba(240, 80, 45, 0.63)",
borderColor: "#f0502d",
label: "1",
data: [{
"x": 1589497200000,
"y": 0.014
},
{
"x": 1589500800000,
"y": 0.003
},
{
"x": 1589504400000,
"y": 0
},
{
"x": 1589536800000,
"y": 0
},
{
"x": 1589540400000,
"y": 0.023
},
{
"x": 1589544000000,
"y": 0.251
},
{
"x": 1589547600000,
"y": 0.599
},
{
"x": 1589551200000,
"y": 0.896
},
{
"x": 1589554800000,
"y": 1.582
},
{
"x": 1589558400000,
"y": 2.335
},
{
"x": 1589562000000,
"y": 1.302
},
{
"x": 1589565600000,
"y": 2.774
},
{
"x": 1589569200000,
"y": 2.432
},
{
"x": 1589572800000,
"y": 1.257
},
{
"x": 1589576400000,
"y": 0.056
}
]
},
{
label: "0",
backgroundColor: "rgba(217, 217, 216, 0.63)",
borderColor: "#d9d9d8",
data: [{
"x": 1589497200000,
"y": 0.014
},
{
"x": 1589500800000,
"y": 0.003
},
{
"x": 1589504400000,
"y": 0
},
{
"x": 1589536800000,
"y": 0
},
{
"x": 1589540400000,
"y": 0.023
},
{
"x": 1589544000000,
"y": 0.251
},
{
"x": 1589547600000,
"y": 0.599
},
{
"x": 1589551200000,
"y": 0.896
},
{
"x": 1589554800000,
"y": 1.582
},
{
"x": 1589558400000,
"y": 2.335
},
{
"x": 1589562000000,
"y": 1.302
},
{
"x": 1589565600000,
"y": 2.774
},
{
"x": 1589569200000,
"y": 2.432
},
{
"x": 1589572800000,
"y": 1.257
},
{
"x": 1589576400000,
"y": 0.056
}
]
}
];
const options = {
tooltips: {
enabled: true,
intersect: true,
mode: 'index',
position: 'nearest',
},
maintainAspectRatio: false,
legend: {
display: true,
position: 'bottom'
},
scales: {
xAxes: [{
type: "time",
distribution: "series",
offset: true,
time: {
unit: 'hour',
tooltipFormat: 'hA'
},
scaleLabel: {
display: true
},
ticks: {
maxRotation: 0,
maxTicksLimit: 12,
}
}],
yAxes: [{
ticks: {
beginAtZero: true,
maxTicksLimit: 8,
}
}],
}
};
new Chart("barChart", {
type: 'bar',
data: {
datasets: datasets
},
options: options
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.bundle.min.js"></script>
<canvas id="barChart" height="200"></canvas>
Related
How to display two rectangles, on inside the other in a Power BI visual? Of course, given rectangle coordinates and sizes. Preferably using native visuals.
Example:
Bigger rectangle (frame) size is width:10 hight:8
Inside Rectangle size is width:3, hight:2, x:4, y:5
I do not care about the display of the numbers or axes. Just the blue and red rectangles.
In case you change your mind, here is a Vega-Lite version. You can literally just drop the code into Deneb and don't need to do anything else.
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"width": 300,
"height": 240,
"background": "#9bc2e6",
"data": {"values": [{"x": 3, "x2": 6, "y": 4, "y2": 6}]},
"mark": {"type": "rect", "color": "#c00000"},
"encoding": {
"x": {
"field": "x",
"type": "quantitative",
"scale": {"domain": [0, 10]},
"axis": {
"gridColor": "white",
"gridWidth": 1,
"domain": false,
"title": "x",
"orient": "top"
}
},
"x2": {"field": "x2"},
"y": {
"field": "y",
"type": "quantitative",
"scale": {"domain": [8, 0]},
"axis": {
"gridColor": "white",
"gridWidth": 1,
"domain": false,
"title": "y"
}
},
"y2": {"field": "y2"}
}
}
Edit:
You mean like this?
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"width": 300,
"height": 240,
"background": "white",
"layer": [
{
"data": {"values": [{"rect":1,"x": 0, "x2": 10, "y": 0, "y2": 8}]},
"mark": {"type": "rect", "color": "#9bc2e6"}
},
{
"data": {"values": [{"rect":2, "x": 3, "x2": 6, "y": 4, "y2": 6}]},
"mark": {"type": "rect", "color": "#c00000"}
}
],
"encoding": {
"x": {
"field": "x",
"type": "quantitative",
"scale": {"domain": [0, 10]},
"axis": null
},
"x2": {"field": "x2"},
"y": {
"field": "y",
"type": "quantitative",
"scale": {"domain": [8, 0]},
"axis": null
},
"y2": {"field": "y2"}
}
}
I have a Vue.JS project getting data from a REST API (mine, so I can modify it if needed). This data is formatted for Chart.JS.
I am supposed to display a graph with 3 datasets, 2 of type line with the same X values, but 1 of type bar with different X values (that's why I don't want to specify labels). Whatever, all the X values are dates, so I would like only 1 X axis for all the curves.
I am using datasets with (x,y) data format :
x is an ISO8601 date
y is a float
My problem is that NOTHING is displayed at all...could anyone help me please, I don't understand why. I feel like having done things right. I saw somewhere that I needed to include momentjs, but in the official documentation they say that it is not the case. I bet that the problems come from the dates because I tried changing the y values, and the 2 y axis bounds are modified (so y values are understood). I also tried addind the "xAxisID" option, nothing changed.
Here is a sample of my data (normally hundreds of values) :
{
"type": "line",
"data": {
"datasets": [
{
"label": "Température",
"borderColor": "red",
"backgroundColor": "red",
"fill": false,
"data": [
{
"x": "2020-07-05T15:38:47.933711",
"y": 2.8224692
},
{
"x": "2020-07-05T15:48:47.490669",
"y": 33.63129
},
{
"x": "2020-07-05T15:58:48.182698",
"y": 40.540405
},
{
"x": "2020-07-05T16:08:47.829882",
"y": 3.0312533
},
{
"x": "2020-07-05T16:18:47.489026",
"y": 49.145626
}
],
"yAxisID": "yAxeTemperature"
},
{
"label": "Humidité",
"borderColor": "blue",
"backgroundColor": "blue",
"fill": false,
"data": [
{
"x": "2020-07-05T15:38:47.933711",
"y": 33.980587
},
{
"x": "2020-07-05T15:48:47.490669",
"y": 2.0313625
},
{
"x": "2020-07-05T15:58:48.182698",
"y": 24.249685
},
{
"x": "2020-07-05T16:08:47.829882",
"y": 7.4426904
},
{
"x": "2020-07-05T16:18:47.489026",
"y": 2.6335742
},
{
"x": "2020-07-05T16:28:48.175547",
"y": 25.92827
}
],
"yAxisID": "yAxeHumidite"
}
]
},
"options": {
"responsive": true,
"hoverMode": "index",
"stacked": false,
"title": null,
"scales": {
"xAxes": [
{
"type": "time",
"display": true,
"position": "bottom",
"id": "xAxeTime",
"scaleLabel": {
"display": true,
"labelString": "Temps",
"fontColor": "black"
},
"time": {
"unit": "minute",
"parser": "moment.ISO_8601",
"tooltipFormat": "ll"
}
}
],
"yAxes": [
{
"type": "linear",
"display": true,
"position": "left",
"id": "yAxeTemperature",
"scaleLabel": {
"display": true,
"labelString": "Température",
"fontColor": "red"
}
},
{
"type": "linear",
"display": true,
"position": "left",
"id": "yAxeHumidite",
"scaleLabel": {
"display": true,
"labelString": "Humidité",
"fontColor": "blue"
}
}
]
}
}
}
Here is how my chart is created (using vue-chartjs and chart.js) :
createChart(chartId : string, chartData : GrapheBean) {
const ctx = document.getElementById(chartId);
// #ts-ignore
const myChart = new Chart(ctx, {
type: chartData.type,
data: chartData.data,
options: chartData.options,
});
}
Here is the result :
I am stuck now, even if still trying things with little hope. Thanks a lot in advance for the ones who could help me.
First you should remove the option xAxes.time.parser. It is not needed when the dates are of ISO8601 format.
Further Chart.js effectively internally uses Moment.js for the functionality of the time axis. Therefore you should use the bundled version of Chart.js that includes Moment.js in a single file.
Please have a look at your amended code in a pure JavaScript version.
const chartData = {
"type": "line",
"data": {
"datasets": [{
"label": "Température",
"borderColor": "red",
"backgroundColor": "red",
"fill": false,
"data": [{
"x": "2020-07-05T15:38:47.933711",
"y": 2.8224692
},
{
"x": "2020-07-05T15:48:47.490669",
"y": 33.63129
},
{
"x": "2020-07-05T15:58:48.182698",
"y": 40.540405
},
{
"x": "2020-07-05T16:08:47.829882",
"y": 3.0312533
},
{
"x": "2020-07-05T16:18:47.489026",
"y": 49.145626
}
],
"yAxisID": "yAxeTemperature"
},
{
"label": "Humidité",
"borderColor": "blue",
"backgroundColor": "blue",
"fill": false,
"data": [{
"x": "2020-07-05T15:38:47.933711",
"y": 33.980587
},
{
"x": "2020-07-05T15:48:47.490669",
"y": 2.0313625
},
{
"x": "2020-07-05T15:58:48.182698",
"y": 24.249685
},
{
"x": "2020-07-05T16:08:47.829882",
"y": 7.4426904
},
{
"x": "2020-07-05T16:18:47.489026",
"y": 2.6335742
},
{
"x": "2020-07-05T16:28:48.175547",
"y": 25.92827
}
],
"yAxisID": "yAxeHumidite"
}
]
},
"options": {
"responsive": true,
"hoverMode": "index",
"stacked": false,
"title": null,
"scales": {
"xAxes": [{
"type": "time",
"display": true,
"position": "bottom",
"id": "xAxeTime",
"scaleLabel": {
"display": true,
"labelString": "Temps",
"fontColor": "black"
},
"time": {
"unit": "minute",
// "parser": "moment.ISO_8601", -> remove this line
"tooltipFormat": "ll"
}
}],
"yAxes": [{
"type": "linear",
"display": true,
"position": "left",
"id": "yAxeTemperature",
"scaleLabel": {
"display": true,
"labelString": "Température",
"fontColor": "red"
}
},
{
"type": "linear",
"display": true,
"position": "left",
"id": "yAxeHumidite",
"scaleLabel": {
"display": true,
"labelString": "Humidité",
"fontColor": "blue"
}
}
]
}
}
}
const ctx = document.getElementById('myChart');
const myChart = new Chart(ctx, {
type: chartData.type,
data: chartData.data,
options: chartData.options,
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.bundle.min.js"></script>
<canvas id="myChart" height="120"></canvas>
In your question you also wrote "I am supposed to display a graph with 3 datasets, 2 of type line with the same X values, but 1 of type bar with different X values". Your code however only defines 2 datasets. In case you're also facing problems with this point, please post a new question for this separate issue.
I am calling the Amazon Rekognition Detect faces API from Post man. I pass the image as base64 and pass the "Attributes" as ["ALL"].
{
"Image": {
"Attributes": ["ALL"],
"Bytes": <base64 image>
}
}
The response I get is as below. You can see that it has only a few attributes and does not include age range, beard, glasses etc. Same set of attributes are returned irrespective of whether I pass the value as "ALL", or "DEFAULT" or "ALL","DEFAULT" in the Attributes parameter.
Am I missing something here? Any pointers would be much appreciated.
{
"FaceDetails": [
{
"BoundingBox": {
"Height": 0.49429410696029663,
"Left": 0.35876789689064026,
"Top": 0.15820752084255219,
"Width": 0.3210359811782837
},
"Confidence": 100.0,
"Landmarks": [
{
"Type": "eyeLeft",
"X": 0.4103875756263733,
"Y": 0.35949569940567017
},
{
"Type": "eyeRight",
"X": 0.5616039037704468,
"Y": 0.3441786468029022
},
{
"Type": "mouthLeft",
"X": 0.4385274350643158,
"Y": 0.5330458879470825
},
{
"Type": "mouthRight",
"X": 0.5625125169754028,
"Y": 0.5202205181121826
},
{
"Type": "nose",
"X": 0.48630291223526,
"Y": 0.436920166015625
}
],
"Pose": {
"Pitch": 8.636483192443848,
"Roll": -5.8078813552856445,
"Yaw": -3.338975429534912
},
"Quality": {
"Brightness": 82.37736511230469,
"Sharpness": 83.14741516113281
}
}
]
}
I’m new using Amazon Rekognition to analyze faces on a video.
I’m using startFaceSearch to start my analysis. After the job is completed successfully, I’m using the JobId generated to call getFaceSearch.
On my first video analyzed, the results were as expected. But when I analyze the second example some strange behavior occurs and I can’t understand why.
Viewing the JSON generated as results for my second video, completely different faces are identified with the same index number.
Please see the results below.
{
"Timestamp": 35960,
"Person": {
"Index": 11,
"BoundingBox": {
"Width": 0.09375,
"Height": 0.24583333730698,
"Left": 0.1875,
"Top": 0.375
},
"Face": {
"BoundingBox": {
"Width": 0.06993006914854,
"Height": 0.10256410390139,
"Left": 0.24475525319576,
"Top": 0.375
},
"Landmarks": [
{
"Type": "eyeLeft",
"X": 0.26899611949921,
"Y": 0.40649232268333
},
{
"Type": "eyeRight",
"X": 0.28330621123314,
"Y": 0.41610333323479
},
{
"Type": "nose",
"X": 0.27063181996346,
"Y": 0.43293061852455
},
{
"Type": "mouthLeft",
"X": 0.25983560085297,
"Y": 0.44362303614616
},
{
"Type": "mouthRight",
"X": 0.27296212315559,
"Y": 0.44758656620979
}
],
"Pose": {
"Roll": 22.106262207031,
"Yaw": 6.3516845703125,
"Pitch": -6.2676968574524
},
"Quality": {
"Brightness": 41.875026702881,
"Sharpness": 65.948883056641
},
"Confidence": 90.114051818848
}
}
}
{
"Timestamp": 46520,
"Person": {
"Index": 11,
"BoundingBox": {
"Width": 0.19034090638161,
"Height": 0.42083331942558,
"Left": 0.30681818723679,
"Top": 0.17916665971279
},
"Face": {
"BoundingBox": {
"Width": 0.076486013829708,
"Height": 0.11217948794365,
"Left": 0.38680067658424,
"Top": 0.26923078298569
},
"Landmarks": [
{
"Type": "eyeLeft",
"X": 0.40642243623734,
"Y": 0.32347011566162
},
{
"Type": "eyeRight",
"X": 0.43237379193306,
"Y": 0.32369664311409
},
{
"Type": "nose",
"X": 0.42121160030365,
"Y": 0.34618207812309
},
{
"Type": "mouthLeft",
"X": 0.41044121980667,
"Y": 0.36520344018936
},
{
"Type": "mouthRight",
"X": 0.43202903866768,
"Y": 0.36483728885651
}
],
"Pose": {
"Roll": 0.3165397644043,
"Yaw": 2.038902759552,
"Pitch": -1.9931464195251
},
"Quality": {
"Brightness": 54.697460174561,
"Sharpness": 53.806159973145
},
"Confidence": 95.216400146484
}
}
}
In fact, in this video, all faces have the same index number, regardless of they are different. Any suggestions?
PersonDetail object is the result of the API . "index" is the identifier for the person detected in the video. So the index doesn't span across videos. It is just an internal reference.
Link below which details Index
https://docs.aws.amazon.com/rekognition/latest/dg/API_PersonDetail.html
I'm trying to create a stacked bar chart with chartjs. I have time series with discrepencies in time, this means some series can have value for a time but others don't. For this reason I chose to include directly the x values in the dataset and not as a label array, but the chart does not render correctly.
Here is my code:
var config = {
type:'bar',
data:{
datasets:datasets
},
options: {
responsive: true,
title:{
display:true,
text:"MyChart"
},
tooltips: {
mode: 'index'
},
hover: {
mode: 'index'
},
legend: {
position: 'bottom'
},
elements: { point: { radius: 0 }},
scales: {
xAxes: [{
stacked: true,
type: 'time',
time: {
unit: 'minutes',
unitStepSize: 5,
displayFormats:{
minutes:'HH:mm'
}
},
scaleLabel: {
display: true,
labelString: 'Date'
}
}],
yAxes: [{
stacked:true,
scaleLabel: {
display: true,
labelString: 'Resources Consumed'
}
}]
}
}
};
var ctx = document.getElementById('session-sql-activity').getContext("2d");
ctx.canvas.height = 300;
ctx.canvas.width = 800;
new Chart(ctx,config);
I think the issue is with the x axis stacking.
Here is a JSFiddle illustrating the problem.
https://jsfiddle.net/1kLyyjfp/
I think a solution is to specify a value for the y axis anyway.
{
"y": 0,
"x": "2017-12-22 08:59"
}
The resulting dataset is:
[{
"data": [{
"y": 2,
"x": "2017-12-22 08:59"
}, {
"y": 18,
"x": "2017-12-22 09:00"
}],
"backgroundColor": "#32AA09",
"label": "7726bj0dhtnmt"
}, {
"data": [{
"y": 0,
"x": "2017-12-22 08:59"
}, {
"y": 2,
"x": "2017-12-22 09:00"
}],
"backgroundColor": "#CF5A26",
"label": "0ks4u5nywjbdj"
}, {
"data": [{
"y": 0,
"x": "2017-12-22 08:59"
}, {
"y": 4,
"x": "2017-12-22 09:00"
}],
"backgroundColor": "#DA43AA",
"label": "1mnbsygj75jvx"
}, {
"data": [{
"y": 0,
"x": "2017-12-22 08:59"
}, {
"y": 2,
"x": "2017-12-22 09:00"
}],
"backgroundColor": "#5200A0",
"label": "39ymdt11ybwhz"
}, {
"data": [{
"y": 0,
"x": "2017-12-22 08:59"
}, {
"y": 2,
"x": "2017-12-22 09:00"
}],
"backgroundColor": "#925E44",
"label": "4v1whmzv76j2z"
}, {
"data": [{
"y": 0,
"x": "2017-12-22 08:59"
}, {
"y": 2,
"x": "2017-12-22 09:00"
}],
"backgroundColor": "#477BD4",
"label": "5sfyujuhwbj9n"
}, {
"data": [{
"y": 0,
"x": "2017-12-22 08:59"
}, {
"y": 4,
"x": "2017-12-22 09:00"
}],
"backgroundColor": "#272755",
"label": "6x0zvf2mw8t6g"
}, {
"data": [{
"y": 0,
"x": "2017-12-22 08:59"
}, {
"y": 2,
"x": "2017-12-22 09:00"
}],
"backgroundColor": "#F581E0",
"label": "7kpk62m5n8j9q"
}, {
"data": [{
"y": 0,
"x": "2017-12-22 08:59"
}, {
"y": 20,
"x": "2017-12-22 09:00"
}],
"backgroundColor": "#4128A8",
"label": "7mwz4m103nn1k"
}];