Graph not rendering correct scale with NVD3 - javascript

I haven't been able to make the line chart render with a correct scale and the documentation is practically non existent for nvd3. It renders ok if I only use the first set of values (with the key Success).
I have a sample demo here: http://jsfiddle.net/LBqk3/1/
And the code / attached sample data:
nv.addGraph(function () {
var chart = nv.models.lineChart();
chart.xAxis.axisLabel('Requests')
.tickFormat(function (d) {
return d3.time.format('%d %b')(new Date(d));
});
var y = d3.scale.linear()
.range([400, 400]);
chart.yAxis.axisLabel('Amount')
.scale(y)
.tickFormat(d3.format('.2f'));
d3.select('#chart svg')
.datum([{
"values": [{
"x": 1387893600000,
"y": "170"
}, {
"x": 1387980000000,
"y": "416"
}, {
"x": 1388066400000,
"y": "743"
}, {
"x": 1388152800000,
"y": "633"
}, {
"x": 1388239200000,
"y": "500"
}, {
"x": 1388325600000,
"y": "604"
}, {
"x": 1388412000000,
"y": "683"
}, {
"x": 1388498400000,
"y": "485"
}, {
"x": 1388584800000,
"y": "509"
}, {
"x": 1388671200000,
"y": "677"
}, {
"x": 1388757600000,
"y": "610"
}, {
"x": 1388844000000,
"y": "607"
}, {
"x": 1388930400000,
"y": "538"
}, {
"x": 1389016800000,
"y": "596"
}, {
"x": 1389103200000,
"y": "609"
}, {
"x": 1389189600000,
"y": "581"
}, {
"x": 1389276000000,
"y": "503"
}, {
"x": 1389362400000,
"y": "524"
}, {
"x": 1389448800000,
"y": "515"
}, {
"x": 1389535200000,
"y": "580"
}, {
"x": 1389621600000,
"y": "592"
}, {
"x": 1389708000000,
"y": "573"
}, {
"x": 1389794400000,
"y": "597"
}, {
"x": 1389880800000,
"y": "717"
}, {
"x": 1389967200000,
"y": "2760"
}],
"key": "Missed"
}])
.transition()
.duration(500)
.call(chart);
nv.utils.windowResize(chart.update);
return chart;
});

The problem is that your y values are strings and you're treating them like numbers. Replacing
"y": "604"
with
"y": 604
and so on for all values should fix the issue.

Related

TensorFlow.js PoseNet model keypoints animation

I'm using TensorFlow.js pre-trained PoseNet model to collect and store pose data from my web app. I already have some chunk of JSON with keypoints data I want to analyze to use it as training set for another neural network. Here's the keypoints data example:
"keypoints": [
{
"position": {
"y": 76.291801452637,
"x": 253.36747741699
},
"part": "nose",
"score": 0.99539834260941
},
{
"position": {
"y": 71.10383605957,
"x": 253.54365539551
},
"part": "leftEye",
"score": 0.98781454563141
},
{
"position": {
"y": 71.839515686035,
"x": 246.00454711914
},
"part": "rightEye",
"score": 0.99528175592422
},
{
"position": {
"y": 72.848854064941,
"x": 263.08151245117
},
"part": "leftEar",
"score": 0.84029853343964
},
{
"position": {
"y": 79.956565856934,
"x": 234.26812744141
},
"part": "rightEar",
"score": 0.92544466257095
},
{
"position": {
"y": 98.34538269043,
"x": 399.64068603516
},
"part": "leftShoulder",
"score": 0.99559044837952
},
{
"position": {
"y": 95.082359313965,
"x": 458.21868896484
},
"part": "rightShoulder",
"score": 0.99583911895752
},
{
"position": {
"y": 94.626205444336,
"x": 163.94561767578
},
"part": "leftElbow",
"score": 0.9518963098526
},
{
"position": {
"y": 150.2349395752,
"x": 245.06030273438
},
"part": "rightElbow",
"score": 0.98052614927292
},
{
"position": {
"y": 113.9603729248,
"x": 393.19735717773
},
"part": "leftWrist",
"score": 0.94009721279144
},
{
"position": {
"y": 186.47859191895,
"x": 257.98034667969
},
"part": "rightWrist",
"score": 0.98029226064682
},
{
"position": {
"y": 208.5266418457,
"x": 284.46710205078
},
"part": "leftHip",
"score": 0.97870296239853
},
{
"position": {
"y": 209.9910736084,
"x": 243.31219482422
},
"part": "rightHip",
"score": 0.97424703836441
},
{
"position": {
"y": 281.61965942383,
"x": 310.93188476562
},
"part": "leftKnee",
"score": 0.98368924856186
},
{
"position": {
"y": 282.80120849609,
"x": 203.81164550781
},
"part": "rightKnee",
"score": 0.96947449445724
},
{
"position": {
"y": 360.62716674805,
"x": 292.21047973633
},
"part": "leftAnkle",
"score": 0.8883239030838
},
{
"position": {
"y": 347.41177368164,
"x": 203.88229370117
},
"part": "rightAnkle",
"score": 0.8255187869072
}
]
The problem is that I need an interface to display that data, perfectly if it would be a web app interface. I've only found Google's demo app using PoseNet model with the keypoints attached on top of webcam video that is displayed in a <canvas/>, but it seems that it uses some manual canvas drawing.
So I'm interested, are there some libraries or non-JS tools for viewing the keypoints data as animated keyframes or maybe manually sliding between them? Or do I have to implement that myself? Thanks in advance.
Check this repo: https://github.com/ajaichemmanam/Posenet-ReactWebapp. It uses react to make a webapp for displaying posenet keypoints.

Display gaps between the timestamps having no data in ChartJS time series

In short, I have events that have data (y) and timestamp (t) and I want to show them on the chart.
Currently, if I have three events:
10:00 AM: 42
11:00 AM: 43
11:20 AM: 44
The chart won't show there is a gap (I refer to the gap of one hour) of data but will simply connect them.
For example, there is a gap between 10PM and 5AM in the following example.
Is there an option to automatically display 0 values if the gap between two points is more than X seconds?
var ctx = document.getElementById('chart').getContext("2d");
var data = [
{
"y": "0.58",
"t": 1565665819571
},
{
"y": "0.84",
"t": 1565665218436
},
{
"y": "1.69",
"t": 1565664625228
},
{
"y": "0.24",
"t": 1565640019245
},
{
"y": "0.24",
"t": 1565639418937
},
{
"y": "0.25",
"t": 1565638819713
},
{
"y": "0.25",
"t": 1565638219190
},
{
"y": "0.23",
"t": 1565637619961
},
{
"y": "0.24",
"t": 1565637018574
},
{
"y": "0.24",
"t": 1565636426432
},
{
"y": "0.24",
"t": 1565635825187
},
{
"y": "0.25",
"t": 1565635218607
},
{
"y": "0.25",
"t": 1565634618853
},
{
"y": "0.26",
"t": 1565634020604
},
{
"y": "0.26",
"t": 1565633419088
},
{
"y": "0.27",
"t": 1565632819216
},
{
"y": "0.27",
"t": 1565632218830
},
{
"y": "0.28",
"t": 1565631620692
},
{
"y": "0.29",
"t": 1565631019620
},
{
"y": "0.29",
"t": 1565630418738
},
{
"y": "0.30",
"t": 1565629818050
},
{
"y": "0.31",
"t": 1565629218872
},
{
"y": "0.33",
"t": 1565628126871
}
]
var chart = new Chart(ctx, {
"type": "line",
"data": {
"datasets": [
{
"label": "Foo",
"backgroundColor": "lightblue",
"borderColor": "blue",
"data": data,
"type": "line",
"pointRadius": 0,
"fill": false,
"lineTension": 0,
"borderWidth": 2,
"spanGaps": false
}
]
},
"options": {
"scales": {
"xAxes": [
{
"type": "time",
"distribution": "series",
"ticks": {
"source": "data",
"autoSkip": true
}
}
],
"yAxes": [
{
"scaleLabel": {
"display": true,
"labelString": "Y"
}
}
]
},
"tooltips": {
"intersect": false,
"mode": "index",
"callbacks": {}
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/Chart.bundle.min.js"></script>
<canvas id="chart"></canvas>
Since v3 chart.js has an ability to set spanGap as a number, determining the maximum gap to span. So in this case, 1 hour gap can be used in order to keep the data points connected, but at the same time have a gap between 11pm and 5 am
Docs: https://www.chartjs.org/docs/latest/charts/line.html#line-styling
Official example: https://www.chartjs.org/docs/latest/samples/scales/time-max-span.html
Here's the adjusted code:
const ctx = document.getElementById('chart');
const data = [{
"y": "0.58",
"x": 1565665819571,
},
{
"y": "0.84",
"x": 1565665218436,
},
{
"y": "1.69",
"x": 1565664625228
},
{
"y": "0.24",
"x": 1565640019245
},
{
"y": "0.24",
"x": 1565639418937
},
{
"y": "0.25",
"x": 1565638819713
},
{
"y": "0.25",
"x": 1565638219190
},
{
"y": "0.23",
"x": 1565637619961
},
{
"y": "0.24",
"x": 1565637018574
},
{
"y": "0.24",
"x": 1565636426432
},
{
"y": "0.24",
"x": 1565635825187
},
{
"y": "0.25",
"x": 1565635218607
},
{
"y": "0.25",
"x": 1565634618853
},
{
"y": "0.26",
"x": 1565634020604
},
{
"y": "0.26",
"x": 1565633419088
},
{
"y": "0.27",
"x": 1565632819216
},
{
"y": "0.27",
"x": 1565632218830
},
{
"y": "0.28",
"x": 1565631620692
},
{
"y": "0.29",
"x": 1565631019620
},
{
"y": "0.29",
"x": 1565630418738
},
{
"y": "0.30",
"x": 1565629818050
},
{
"y": "0.31",
"x": 1565629218872
},
{
"y": "0.33",
"x": 1565628126871
}
]
const chart = new Chart(ctx, {
"type": "line",
"data": {
datasets: [{
label: 'Foo',
backgroundColor: "lightblue",
borderColor: "blue",
fill: false,
data: data,
pointRadius: 0,
spanGaps: 1000 * 60 * 60, // 1 hour
}]
},
options: {
responsive: true,
scales: {
xAxis: {
type: "time"
}
},
"tooltips": {
"intersect": false,
"mode": "index",
"callbacks": {}
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/4.2.0/chart.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/luxon#^2"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-luxon#^1"></script>
<canvas id="chart"></canvas>

Heatmap js min value 0

I am trying to plot the heatmap using 'heatmap js' library .
For some value of inputs if the min value is 0 and max value is 1 then whole heatmap will be red instead of plotting actual values.
It works fine if the max value is other than 1 (ex. min: 0, max 2 or min:0 , max: 3) but only for this case the heatmap fails to map the data.
var data = null;
/* this set of data works fine though */
values = [{
"uid": "1",
"x": 100,
"y": 200,
"value": 0
},
{
"uid": "2",
"x": 100,
"y": 220,
"value": 0
},
{
"uid": "22",
"x": 100,
"y": 240,
"value": 0
},
{
"uid": "30",
"x": 100,
"y": 260,
"value": 0
},
{
"uid": "39",
"x": 100,
"y": 280,
"value": 0
},
{
"uid": "70",
"x": 100,
"y": 300,
"value": 1
},
{
"uid": "75",
"x": 120,
"y": 200,
"value": 0
},
{
"uid": "84",
"x": 140,
"y": 200,
"value": 1
},
{
"uid": "85",
"x": 160,
"y": 200,
"value": 1
},
{
"uid": "104",
"x": 180,
"y": 200,
"value": 0
},
{
"uid": "105",
"x": 200,
"y": 200,
"value": 0
}
];
var heatmap = h337.create({
container: $("#testcanvas").get(0)
});
data = {
max: 1,
min: 0,
data: values
}
heatmap.setData(data);
heatmap.repaint();
#testcanvas {
width: 600px;
height: 600px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://rawgit.com/pa7/heatmap.js/master/build/heatmap.js"></script>
<div id="testcanvas"></div>
If I understand correctly your problem then I guess Script understand 0 = false and 1 = true so you need to pass 0 as "0" and 1 as "1"
var data = null;
/* this set of data works fine though */
values = [{
"uid": "1",
"x": 100,
"y": 200,
"value": "0"
},
{
"uid": "2",
"x": 100,
"y": 220,
"value": "0"
},
{
"uid": "22",
"x": 100,
"y": 240,
"value": "0"
},
{
"uid": "30",
"x": 100,
"y": 260,
"value": "0"
},
{
"uid": "39",
"x": 100,
"y": 280,
"value": "0"
},
{
"uid": "70",
"x": 100,
"y": 300,
"value": "1"
},
{
"uid": "75",
"x": 120,
"y": 200,
"value": "0"
},
{
"uid": "84",
"x": 140,
"y": 200,
"value": "1"
},
{
"uid": "85",
"x": 160,
"y": 200,
"value": "1"
},
{
"uid": "104",
"x": 180,
"y": 200,
"value": "0"
},
{
"uid": "105",
"x": 200,
"y": 200,
"value": "0"
}
];
var heatmap = h337.create({
container: $("#testcanvas").get(0)
});
data = {
max: "1",
min: "0",
data: values
}
heatmap.setData(data);
heatmap.repaint();
#testcanvas {
width: 600px;
height: 600px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://rawgit.com/pa7/heatmap.js/master/build/heatmap.js"></script>
<div id="testcanvas"></div>

Highcharts min and max xAxis

I have a problem with Hightcharts.
I want to display my graph in a complete day (between 08/12/2012 0:00 and 08/12/2012 23:59)
So I use the xAxis.min and xAxis.max of the Highcharts documentation.
But when I display my graph I don't see the min and max value.
"ic": "images/ciblerouge.png",
"icTrack": "",
"color": "255,0,0,0.5",
"title": "skywaveUnitTest - 08/10/2012",
"xAxis": {
"min": 1349661600000,
"max": 1349747999000,
"startOnTick": false
},
"aData": [{
"name": "Vitesse (Km/h)",
"data": [{
"x": 1349711130233,
"y": 10,
"l": 16789
},
{
"x": 1349711388379,
"y": 10,
"l": null
},
{
"x": 1349711388380,
"y": 290,
"l": 16790
},
{
"x": 1349711861797,
"y": 290,
"l": 16791
},
{
"x": 1349717896097,
"y": 290,
"l": 16792
},
{
"x": 1349718759813,
"y": 290,
"l": 16793
},
{
"x": 1349719132107,
"y": 290,
"l": 16794
}],
"visible": true,
"yAxis": 1,
"marker": {
"enabled": false,
"radius": 0
}
},
{
"name": "Altitude",
"data": [{
"x": 1349711130233,
"y": 0,
"l": 16789
},
{
"x": 1349711388379,
"y": 0,
"l": null
},
{
"x": 1349711388380,
"y": -800,
"l": 16790
},
{
"x": 1349711861797,
"y": -800,
"l": 16791
},
{
"x": 1349717896096,
"y": -800,
"l": null
},
{
"x": 1349717896097,
"y": 0,
"l": 16792
},
{
"x": 1349718759812,
"y": 0,
"l": null
},
{
"x": 1349718759813,
"y": 2400,
"l": 16793
},
{
"x": 1349719132107,
"y": 2400,
"l": 16794
}],
"visible": false,
"yAxis": 1,
"marker": {
"enabled": false,
"radius": 0
}
}],

D3 - Help Required in d3.nest

I've got a d3.nest function which gives me the data in the following format.
[
{
"key": "Level1",
"values": [
{
"x": 118,
"y": 106,
"size": 1.113207547
},
{
"x": 111,
"y": 137,
"size": 0.810218978
},
{
"x": 144,
"y": 195,
"size": 0.738461538
},
{
"x": 116,
"y": 129,
"size": 0.899224806
},
{
"x": 117,
"y": 119,
"size": 0.983193277
},
{
"x": 145,
"y": 122,
"size": 1.18852459
}
],
"slope": 0.52289599949494,
"intercept": 0.2795214697252959
},
{
"key": "Level2",
"values": [
{
"x": 172,
"y": 193,
"size": 0.89119171
},
{
"x": 138,
"y": 114,
"size": 1.210526316
},
{
"x": 106,
"y": 189,
"size": 0.560846561
},
{
"x": 123,
"y": 141,
"size": 0.872340426
},
{
"x": 129,
"y": 110,
"size": 1.172727273
},
{
"x": 162,
"y": 198,
"size": 0.818181818
}
],
"slope": 0.52289599949494,
"intercept": 0.2795214697252959
},
{
"key": "Level3",
"values": [
{
"x": 191,
"y": 104,
"size": 1.836538462
},
{
"x": 177,
"y": 186,
"size": 0.951612903
},
{
"x": 106,
"y": 140,
"size": 0.757142857
},
{
"x": 131,
"y": 161,
"size": 0.813664596
},
{
"x": 111,
"y": 128,
"size": 0.8671875
},
{
"x": 149,
"y": 122,
"size": 1.221311475
},
{
"x": 200,
"y": 126,
"size": 1.587301587
}
],
"slope": 0.52289599949494,
"intercept": 0.2795214697252959
}
]
I'd want to exclude only the "type" from the values. Somebody help me on how to do it.
Function i used to get that data is below.
d3.csv("data.csv", function(data) {
data.forEach(function(d) {
d.x = +d.x
d.y = +d.y
d.size = +d.size
})
var nest = d3.nest()
.key(function(d) {return d.type;})
.rollup(function(v) {return v.map(function(d) {return d})})
.entries(data);
d3.select('body').append('pre')
.text(JSON.stringify(nest, null, ' '));
})
If you do not want type to be present in returned array, you can delete it while doing the rollUp:
.rollUp(function (v) { return v.map(function (d) { delete d.type; return d; })
Do note that it will referentially delete 'type' from the original data set as well. If you do not want that to happen, then $.extend or otherwise clone the data in the rollUp function.

Categories