Related
I have a small Wordpress site that I build statically using Gatsby, using the excellent gatsby-source-wordpress and WPGraphQL. Recently I have been doing some data science training and I want to embed my data visualisations into my Wordpress site. I'm using Vega Lite for the visualisations. Each viz is 'described' as an inline block of JS, which I'm adding to Wordpress using an HTML block.
Once I've included the three necessary scripts to the head of my Wordpress theme, the visualisations render properly in my non-Gatsby Wordpress theme pages. However, when Gatsby pulls the data from Wordpress using WPGraphQL, the visualisations don't render in the Gatsby pages (I have added the same three scripts to the head of the Gatsby pages using React Helmet).
I think I understand Gatsby enough to understand why this doesn't work but I don't know which route I should be trying to make work... I could import the Vega libraries into Gatsby but I don't know how Gatsby would interpret the could from GraphQL. Alternatively, I could try to make it work in the browser – possibly using SSR – but that would mean losing the static benefit on many pages.
Below are the relevant bits of the page as rendered by Gatsby...
<head>
<script src="https://cdn.jsdelivr.net/npm//vega#5" type="text/javascript" data-react-helmet="true"></script>
<script src="https://cdn.jsdelivr.net/npm//vega-lite#4.17.0" type="text/javascript" data-react-helmet="true"></script>
<script src="https://cdn.jsdelivr.net/npm//vega-embed#6" type="text/javascript" data-react-helmet="true"></script>
<head>
and
<div id="vis"></div>
<script>
(function(vegaEmbed) {
var spec = {"config": {"padding": 20, "title": {"anchor": "start", "align": "left", "fontSize": 20, "font": "Lato", "color": "#ffffff", "frame": "group", "subtitleColor": "#ffffff", "subtitleFontSize": 16}, "axisX": {"domain": true, "domainColor": "#ffffff", "domainWidth": 1, "grid": true, "gridColor": "#999999", "gridWidth": 1, "labelColor": "#ffffff", "labelFont": "Lato", "labelFontSize": 13, "labelAngle": 0, "tickColor": "#ffffff", "tickSize": 3, "titleColor": "#ffffff", "titleFont": "Lato", "titleFontSize": 16, "titlePadding": 10, "title": "X Axis Title (units)"}, "axisY": {"domain": true, "domainColor": "#ffffff", "domainWidth": 1, "grid": true, "gridColor": "#999999", "gridWidth": 1, "labelColor": "#ffffff", "labelFont": "Lato", "labelFontSize": 13, "labelAngle": 0, "ticks": true, "tickColor": "#ffffff", "tickSize": 3, "titleColor": "#ffffff", "titleFont": "Lato", "titleFontSize": 16, "titlePadding": 10, "title": "Y Axis Title (units)", "titleAngle": 270}, "legend": {"labelColor": "#ffffff", "labelFont": "Lato", "labelFontSize": 13, "symbolSize": 100, "titleColor": "#ffffff", "titleFont": "Lato", "titleFontSize": 14}, "tooltip": {"labelFontSize": 13}, "view": {"stroke": "transparent"}}, "layer": [{"mark": {"type": "rect", "color": "black", "opacity": 0.2}, "encoding": {"x": {"field": "startYear", "type": "temporal"}, "x2": {"field": "endYear"}}}, {"mark": {"type": "text", "align": "center", "angle": 270, "baseline": "middle", "fontSize": 16, "opacity": 0.5}, "encoding": {"text": {"field": "text", "type": "nominal"}, "x": {"field": "x", "type": "temporal"}, "x2": {"field": "endYear"}}, "transform": [{"calculate": "datum.startYear + (datum.endYear - datum.startYear)/2", "as": "x"}]}, {"data": {"name": "data-c042860487113da4c09c3ea7e1e3f6cf"}, "mark": {"type": "circle", "opacity": 0.9, "stroke": "#121212", "strokeWidth": 0.5}, "encoding": {"color": {"field": "type", "legend": {"rowPadding": 5, "title": "Type of win"}, "scale": {"domain": ["Standard", "Min", "Max", "Points"], "range": ["#ffff3f", "#fa0149", "#8cd3fe", "#00e000"]}, "type": "nominal"}, "opacity": {"condition": {"value": 1, "selection": "selector003"}, "value": 0.2}, "size": {"field": "Stages won", "legend": {"title": "Stages won"}, "scale": {"domain": [0, 8], "range": [20, 120]}, "type": "quantitative"}, "tooltip": [{"field": "Year", "type": "quantitative"}, {"field": "Cyclist", "title": "Winner"}, {"field": "Country", "type": "nominal"}, {"field": "Team", "type": "nominal"}, {"field": "Stages won", "type": "quantitative"}, {"field": "Winning margin", "type": "nominal"}], "x": {"axis": {"tickCount": 10, "title": "Year"}, "field": "datetime", "scale": {"domain": [1902, 2022], "zero": false}, "timeUnit": "year", "title": "Year", "type": "temporal"}, "y": {"axis": {"grid": false}, "field": "Stages leading", "scale": {"domain": [0, 23]}, "title": "Stages in lead", "type": "quantitative"}}, "height": 400, "selection": {"selector003": {"type": "multi", "fields": ["type"], "bind": "legend"}}, "title": {"text": "Tour de France winners, 1903 - 2022", "subtitle": "Number of winners: 65"}, "width": 800}], "background": "#586b6e", "data": {"name": "data-945424ea27149582e05915ea3c6ba826"}, "$schema": "https://vega.github.io/schema/vega-lite/v4.17.0.json", "datasets": {"data-945424ea27149582e05915ea3c6ba826": [{"startYear": "1914-06-28T00:00:00.000", "endYear": "1918-11-11T00:00:00.000", "text": "World War I"}, {"startYear": "1939-09-01T00:00:00.000", "endYear": "1945-08-14T00:00:00.000", "text": "World War II"}], "data-c042860487113da4c09c3ea7e1e3f6cf": [{"Year": 1903, "Cyclist": "Maurice Garin", "Country": "France", "Team": "La Fran\u00e7aise", "Kilometres": 2428, "Miles": 1509, "Time total": 340394, "Time margin": 10761.0, "Stages won": 3, "Stages leading": 6, "datetime": "1903-05-01T00:00:00", "Winning margin": "2h 59m 21s", "Team (Country)": "La Fran\u00e7aise (FRANCE)", "type": "Max"}, {"Year": 1904, "Cyclist": "Henri Cornet", "Country": "France", "Team": "Conte", "Kilometres": 2428, "Miles": 1509, "Time total": 345955, "Time margin": 8174.0, "Stages won": 1, "Stages leading": 3, "datetime": "1904-05-01T00:00:00", "Winning margin": "2h 16m 14s", "Team (Country)": "Conte (FRANCE)", "type": "Standard"}, {"Year": 1905, "Cyclist": "Louis Trousselier", "Country": "France", "Team": "Peugeot\u2013Wolber", "Kilometres": 2994, "Miles": 1860, "Time total": 0, "Time margin": 0.0, "Stages won": 5, "Stages leading": 10, "datetime": "1905-05-01T00:00:00", "Winning margin": "0h 00m 00s", "Team (Country)": "Peugeot\u2013Wolber (FRANCE)", "type": "Points"}}]}};
var embedOpt = {"mode": "vega-lite"};
function showError(el, error){
el.innerHTML = ('<div class="error" style="color:red;">'
+ '<p>JavaScript Error: ' + error.message + '</p>'
+ "<p>This usually means there's a typo in your chart specification. "
+ "See the javascript console for the full traceback.</p>"
+ '</div>');
throw error;
}
const el = document.getElementById('vis');
vegaEmbed("#vis", spec, embedOpt)
.catch(error => showError(el, error));
})(vegaEmbed);
</script>
I got a below object from the API
let response = {
"id": 301344576,
"quantity": 92,
"unlimited": false,
"inStock": true,
"name": "Virgin Coconut Oil",
"price": 328.47,
"isShippingRequired": true,
"weight": 0.5,
"url": "https://subhikshaf2c.company.site/Virgin-Coconut-Oil-p301344576",
"options": [
{
"type": "SELECT",
"name": "Weight",
"nameTranslated": {
"en": "Weight"
},
"choices": [
{
"text": "500 gm",
"textTranslated": {
"en": "500 gm"
},
"priceModifier": 0,
"priceModifierType": "ABSOLUTE"
},
{
"text": "1 kg",
"textTranslated": {
"en": "1 kg"
},
"priceModifier": 317.03,
"priceModifierType": "ABSOLUTE"
}
],
"defaultChoice": 0,
"required": false
}
],
"combinations": [
{
"id": 161026822,
"combinationNumber": 1,
"options": [
{
"name": "Weight",
"nameTranslated": {
"en": "Weight"
},
"value": "1 kg",
"valueTranslated": {
"en": "1 kg"
}
}
],
"sku": "OL002-001592-1kg",
"quantity": 36,
"inStock": true,
"unlimited": false,
"weight": 1,
"warningLimit": 20,
"attributes": [],
"defaultDisplayedPrice": 677.78,
"defaultDisplayedPriceFormatted": "₹677.78"
}
]
}
and the weight info of this. Suppose i got 1KG so i'm creating JSON like
{
"Id":301344576,
"weight":"1 kg",
"quantity":1
}
In another page again I'm calling the same API and need to create json format like
[
{
"stock": 92,
"quantity": 1,
"productId": 301344576,
"basePrice": 328.47,
"productPrice": 344.89,
"weight": "500 gm",
"productName": "Virgin Coconut Oil",
}
]
The problem is if the weight: '1KG' i need to look into the combinations and need to update the quantity. So my json will become like
{
"stock": 36,
"quantity": 1,
"productId": 301344576,
"basePrice": 645.5,
"productPrice": 344.89,
"weight": "1 kg",
"productName": "Virgin Coconut Oil",
}
for the basePrice, I'm doing price+priceModifier value of selected weight from the options.
How can i achieve the desired result.
I need help with increments in Node Red (on Raspberry Pi). I am trying to make a smart thermostat with a LCD touchscreen and an app for remote access (ex. coming home on a cold winter day and want to start heating your apartment).
Some suggestions on how to connect to the Raspberry Pi over the Internet (not local network) with an android and a link on a tutorial or example would be much appreciated.
P.S. I am doing this for a friend and I promised him some good results.
Sorry for messy code... => cleaned it up in the edit
I have tried everything I could think of to make my code work as I am not very experienced with NodeRed nor JS.
Global variables May just do the trick... I haven't figured it out yet...
Another barrier I have encountered is the ability to access and interact with the code outside the local network.
[
{
"id": "9f63513b.e227a",
"type": "ui_slider",
"z": "f216bae9.be3b68",
"name": "",
"label": "",
"group": "b344cd03.40f29",
"order": 2,
"width": "0",
"height": "0",
"passthru": true,
"topic": "slide",
"min": "10",
"max": "45",
"step": 1,
"x": 650,
"y": 140,
"wires": [
[
"4e35591.c5466a8",
"ef681f9b.17845"
]
]
},
{
"id": "4e35591.c5466a8",
"type": "delay",
"z": "f216bae9.be3b68",
"name": "Buffer",
"pauseType": "queue",
"timeout": "5",
"timeoutUnits": "seconds",
"rate": "1",
"nbRateUnits": "1",
"rateUnits": "second",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": true,
"x": 810,
"y": 60,
"wires": [
[
"eec05221.3091e"
]
]
},
{
"id": "82848cf2.b33d1",
"type": "function",
"z": "f216bae9.be3b68",
"name": "delete payload",
"func": "msg.buton = msg.payload;\ndelete msg.payload;\nmsg.incalzire=msg.buton;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 480,
"y": 240,
"wires": [
[
"9f63513b.e227a"
]
]
},
{
"id": "ef681f9b.17845",
"type": "ui_gauge",
"z": "f216bae9.be3b68",
"name": "",
"group": "b344cd03.40f29",
"order": 1,
"width": 0,
"height": 0,
"gtype": "gage",
"title": "",
"label": "",
"format": "{{value}}",
"min": "0",
"max": "60",
"colors": [
"#00b500",
"#e6e600",
"#ca3838"
],
"seg1": "",
"seg2": "",
"x": 810,
"y": 220,
"wires": []
},
{
"id": "eec05221.3091e",
"type": "function",
"z": "f216bae9.be3b68",
"name": "delete payload",
"func": "msg.tempslide=msg.payload;\ndelete msg.payload;\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 1000,
"y": 60,
"wires": [
[
"f5853672.5fe148"
]
]
},
{
"id": "6b57c137.8c136",
"type": "function",
"z": "f216bae9.be3b68",
"name": "Switch",
"func": "if(msg.payload===0){\n msg.payload=1;\n}\nelse if (msg.payload==1){\n msg.payload=0;\n}\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 310,
"y": 460,
"wires": [
[
"82848cf2.b33d1"
]
]
},
{
"id": "f5853672.5fe148",
"type": "function",
"z": "f216bae9.be3b68",
"name": "working mess",
"func": "if (msg.incalzire===0||msg.payload===0){\n\nif (msg.temp<=msg.tempslide){\n msg.payload=0;\n}\n\nelse if (msg.temp>msg.tempslide){\n msg.payload=1;\n}\n\nelse{\n msg.payload=1;}\n \n}\n\n\nelse{\n msg.payload=1;\n \n}\n\n\n\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 1058,
"y": 140,
"wires": [
[
"3f6977e5.b44158",
"ee3a7840.808ad8",
"7726596c.b74228"
]
]
},
{
"id": "d34a3234.79712",
"type": "ui_switch",
"z": "f216bae9.be3b68",
"name": "",
"label": "Override Window",
"group": "b344cd03.40f29",
"order": 4,
"width": 0,
"height": 0,
"passthru": true,
"decouple": "false",
"topic": "",
"style": "",
"onvalue": "1",
"onvalueType": "num",
"onicon": "",
"oncolor": "",
"offvalue": "0",
"offvalueType": "num",
"officon": "",
"offcolor": "",
"x": 250,
"y": 420,
"wires": [
[
"6b57c137.8c136"
]
]
},
{
"id": "3f6977e5.b44158",
"type": "debug",
"z": "f216bae9.be3b68",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"x": 1293,
"y": 140,
"wires": []
},
{
"id": "ee3a7840.808ad8",
"type": "function",
"z": "f216bae9.be3b68",
"name": "Message",
"func": "if(msg.payload===0){\n msg.payload='PORNITA'; //ON\n}\nelse if (msg.payload==1){\n msg.payload='OPRITA'; //OFF\n}\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 1183,
"y": 340,
"wires": [
[
"eaeac5fb.c27728"
]
]
},
{
"id": "7726596c.b74228",
"type": "rpi-gpio out",
"z": "f216bae9.be3b68",
"name": "Rel1",
"pin": "22",
"set": "",
"level": "0",
"freq": "",
"out": "out",
"x": 1233,
"y": 220,
"wires": []
},
{
"id": "c0784b3b.c1fcb8",
"type": "function",
"z": "f216bae9.be3b68",
"name": "Switch",
"func": "if(msg.payload===0){\n msg.payload=1;\n}\nelse if (msg.payload==1){\n msg.payload=0;\n}\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 250,
"y": 380,
"wires": [
[
"d34a3234.79712"
]
]
},
{
"id": "eaeac5fb.c27728",
"type": "ui_text",
"z": "f216bae9.be3b68",
"group": "b344cd03.40f29",
"order": 3,
"width": 0,
"height": 0,
"name": "",
"label": "Incalzirea este",
"format": "{{msg.payload}}",
"layout": "row-right",
"x": 1220,
"y": 380,
"wires": []
},
{
"id": "248c4825.00c018",
"type": "rpi-gpio in",
"z": "f216bae9.be3b68",
"name": "",
"pin": "40",
"intype": "tri",
"debounce": "25",
"read": false,
"x": 90,
"y": 300,
"wires": [
[
"c0784b3b.c1fcb8"
]
]
},
{
"id": "afb8009a.49841",
"type": "function",
"z": "f216bae9.be3b68",
"name": "delete payload",
"func": "//nu umbla la asta\nmsg.temp=msg.payload;\ndelete msg.payload;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 320,
"y": 140,
"wires": [
[
"c0784b3b.c1fcb8"
]
]
},
{
"id": "c696dbbc.58ee98",
"type": "rpi-dht22",
"z": "f216bae9.be3b68",
"name": "",
"topic": "Interior",
"dht": "22",
"pintype": "1",
"pin": "29",
"x": 140,
"y": 180,
"wires": [
[
"afb8009a.49841",
"33ec6fb6.fda7f"
]
]
},
{
"id": "33ec6fb6.fda7f",
"type": "ui_gauge",
"z": "f216bae9.be3b68",
"name": "",
"group": "d2bfb34b.1c943",
"order": 1,
"width": 0,
"height": 0,
"gtype": "gage",
"title": "",
"label": "° C",
"format": "{{value}}",
"min": 0,
"max": "60",
"colors": [
"#00b500",
"#e6e600",
"#ca3838"
],
"seg1": "",
"seg2": "",
"x": 150,
"y": 220,
"wires": []
},
{
"id": "d3a6bff.b99a44",
"type": "inject",
"z": "f216bae9.be3b68",
"name": "",
"topic": "",
"payload": "",
"payloadType": "date",
"repeat": "50",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 110,
"y": 120,
"wires": [
[
"c696dbbc.58ee98"
]
]
},
{
"id": "b344cd03.40f29",
"type": "ui_group",
"z": "",
"name": "Reglarea Incalzirii",
"tab": "af80de11.bfd15",
"order": 2,
"disp": true,
"width": "6",
"collapse": true
},
{
"id": "d2bfb34b.1c943",
"type": "ui_group",
"z": "",
"name": "Temperatura Curenta",
"tab": "af80de11.bfd15",
"order": 1,
"disp": true,
"width": "6",
"collapse": true
},
{
"id": "af80de11.bfd15",
"type": "ui_tab",
"z": "",
"name": "Sergiu",
"icon": "fa-thermometer-full",
"order": 4
}
]
The old thermostat was basically an automated relay switch. I have to make it smart and my best bet is a raspberry pi.
The increment part can replace the slider(I have Backups) and has to be triggered by a button in the Dashboard UI.
Everything except of what I mentioned works corectly.
Thank you for your help!! (or at least your time)
I am displaying a pie chart using the Highchart library. I have two sets of data I want to show, and I toggle between the two sets every 5 seconds indefinitely. When I load the initial set of data, the chart displays as it should. And when I load the second set of data (using setData), the chart changes as it should. However, all subsequent calls to setData seem to do nothing. I would expect the chart to change again and again corresponding to the new data. But nothing happens, and there are no errors logged in the console. What could I be doing wrong?
Here is my code:
var chart24HoursTop5;
var lastSet = 1;
var set1 = [{
"seconds": 754,
"y": 754,
"downtime": "00:05:07",
"siteNumber": "13",
"siteName": "Preston",
"name": "Preston",
"motorolaNumber": "SZ092C113",
"system": "SZ Quantar",
"channels": "5",
"towerOwner": "Wynn Communications",
"shelterOwner": "Wynn Communications",
"equipmentOwner": "DPS",
"latitude": "35.724833",
"longitude": "-95.988333",
"color": "#348AA7"
}, {
"seconds": 20,
"y": 20,
"downtime": "00:00:20",
"siteNumber": "29",
"siteName": "Bakers Peak",
"name": "Bakers Peak",
"motorolaNumber": "SZ092C129",
"system": "SZ Quantar",
"channels": "5",
"towerOwner": "FBI",
"shelterOwner": "DPS",
"equipmentOwner": "DPS",
"latitude": "34.839722",
"longitude": "-98.803333",
"color": "#ffa600"
}, {
"seconds": 19,
"y": 19,
"downtime": "00:00:19",
"siteNumber": "30",
"siteName": "Walters",
"name": "Walters",
"motorolaNumber": "SZ092C130",
"system": "SZ Quantar",
"channels": "5",
"towerOwner": "Cotton Electric",
"shelterOwner": "DPS",
"equipmentOwner": "DPS",
"latitude": "34.358583",
"longitude": "-98.321583",
"color": "#cb5464"
}, {
"seconds": 12,
"y": 12,
"downtime": "00:00:12",
"siteNumber": "69",
"siteName": "Hominy",
"name": "Hominy",
"motorolaNumber": "SZ092C169",
"system": "P25 GTR",
"channels": "",
"towerOwner": "Grand River Dam Authority",
"shelterOwner": "Grand River Dam Authority",
"equipmentOwner": "GRDA",
"latitude": "36.4",
"longitude": "-96.4863888888889",
"color": "#82F2C0"
}];
var set2 = [{
"seconds": 691,
"y": 691,
"downtime": "691 Sec",
"siteNumber": "13",
"siteName": "Preston 2",
"name": "Preston 2",
"motorolaNumber": "SZ092C113",
"system": "SZ Quantar",
"channels": "5",
"towerOwner": "Wynn Communications",
"shelterOwner": "Wynn Communications",
"equipmentOwner": "DPS",
"latitude": "35.724833",
"longitude": "-95.988333",
"color": "#348AA7"
}, {
"seconds": 10,
"y": 10,
"downtime": "10 Sec",
"siteNumber": "29",
"siteName": "Bakers Peak 2",
"name": "Bakers Peak 2",
"motorolaNumber": "SZ092C129",
"system": "SZ Quantar",
"channels": "5",
"towerOwner": "FBI",
"shelterOwner": "DPS",
"equipmentOwner": "DPS",
"latitude": "34.839722",
"longitude": "-98.803333",
"color": "#ffa600"
}, {
"seconds": 1,
"y": 1,
"downtime": "1 Sec",
"siteNumber": "30",
"siteName": "Walters 2",
"name": "Walters 2",
"motorolaNumber": "SZ092C130",
"system": "SZ Quantar",
"channels": "5",
"towerOwner": "Cotton Electric",
"shelterOwner": "DPS",
"equipmentOwner": "DPS",
"latitude": "34.358583",
"longitude": "-98.321583",
"color": "#cb5464"
}, {
"seconds": 5,
"y": 5,
"downtime": "5 Sec",
"siteNumber": "69",
"siteName": "Hominy 2",
"name": "Hominy 2",
"motorolaNumber": "SZ092C169",
"system": "P25 GTR",
"channels": "",
"towerOwner": "Grand River Dam Authority",
"shelterOwner": "Grand River Dam Authority",
"equipmentOwner": "GRDA",
"latitude": "36.4",
"longitude": "-96.4863888888889",
"color": "#82F2C0"
}];
$(document).ready(function () {
var optionsFor24HoursTop5 = {
chart: {
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false,
type: 'pie'
},
credits: {
enabled: false
},
title: {
text: 'Last 24 Hours'
},
tooltip: {
pointFormat: '{series.name}: {point.downtime}'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
format: '{point.name}: {point.downtime}'
}
}
},
series: [{
name: 'DropSum',
colorByPoint: true,
data: set1
}]
};
chart24HoursTop5 = Highcharts.chart("chartContainer", optionsFor24HoursTop5);
setTimeout(changeData, 5000);
});
function changeData() {
if (lastSet == 1) {
chart24HoursTop5.series[0].setData(set2);
lastSet = 2;
} else {
chart24HoursTop5.series[0].setData(set1);
lastSet = 1;
}
And here is a fully working jsFiddle example:
https://jsfiddle.net/mspinks/ksd8gjec/23/
You'll notice in the example that the chart displays initially, and then 5 seconds later, the data changes and is reflected in the chart display. However, the data changes again every 5 seconds, and none of those changes are reflected in the chart display. Why won't Highcharts show the updated data after the first change?
For performace Highcharts mutate the original data array, which causes that variables set1 and set2 are the same after the first update.
The solution can be to return the data by function:
function set1() {
return [...];
}
function set2() {
return [...];
}
function changeData() {
if (lastSet == 1) {
chart24HoursTop5.series[0].setData(set2());
lastSet = 2;
} else {
chart24HoursTop5.series[0].setData(set1());
lastSet = 1;
}
setTimeout(changeData, 2000);
}
Live demo: https://jsfiddle.net/BlackLabel/0smxjLac/
This does appear to be some sort of bug(?), but a workaround seems to be to specify that points should not be updated when setting the data. For example (JSFiddle):
function changeData() {
if (lastSet == 1){
// The fourth parameter makes or breaks the update
chart24HoursTop5.series[0].setData(set2, true, true, false);
lastSet = 2;
} else {
// The fourth parameter makes or breaks the update
chart24HoursTop5.series[0].setData(set1, true, true, false);
lastSet = 1;
}
setTimeout(changeData, 5000);
}
This does mean that there is no animation, as the points are scraped and new points are created. It does however appear that it is this updating of points that seems to stop the update from happening at all, so hopefully the main issue can be resolved as well.
I am getting an array of objects as below in my Ajax response.
{
"id": 2,
"name": "An ice sculpture",
"price": 12.50,
"tags": ["cold", "ice"],
"dimensions": {
"length": 7.0,
"width": 12.0,
"height": 9.5
},
"warehouseLocation": {
"latitude": -78.75,
"longitude": 20.4
}
},
{
"id": 3,
"name": "A blue mouse",
"price": 25.50,
"dimensions": {
"length": 3.1,
"width": 1.0,
"height": 1.0
},
"warehouseLocation": {
"latitude": 54.4,
"longitude": -32.7
}
}
{
"id": 3,
"name": "A blue mouse",
"price": 25.50,
"dimensions": {
"length": 3.1,
"width": 1.0,
"height": 1.0
},
"warehouseLocation": ""
}
I want to filter these objects by warehouseLocation which means I need only objects where warehouseLocation is not empty.
You can use Array.prototype.filter function:
var data = [{
"id": 2,
"name": "An ice sculpture",
"price": 12.50,
"tags": ["cold", "ice"],
"dimensions": {
"length": 7.0,
"width": 12.0,
"height": 9.5
},
"warehouseLocation": {
"latitude": -78.75,
"longitude": 20.4
}
}, {
"id": 3,
"name": "A blue mouse",
"price": 25.50,
"dimensions": {
"length": 3.1,
"width": 1.0,
"height": 1.0
},
"warehouseLocation": {
"latitude": 54.4,
"longitude": -32.7
}
},
{
"id": 3,
"name": "A blue mouse",
"price": 25.50,
"dimensions": {
"length": 3.1,
"width": 1.0,
"height": 1.0
},
"warehouseLocation": ""
}
];
var warehouseData = data.filter(function(val) {
return val.warehouseLocation != "";
});
Here is an example to get started.
var arr = [{
"id": 2,
"name": "An ice sculpture",
"price": 12.50,
"tags": ["cold", "ice"],
"dimensions": {
"length": 7.0,
"width": 12.0,
"height": 9.5
},
"warehouseLocation": {
"latitude": -78.75,
"longitude": 20.4
}
}, {
"id": 3,
"name": "A blue mouse",
"price": 25.50,
"dimensions": {
"length": 3.1,
"width": 1.0,
"height": 1.0
},
"warehouseLocation": {
"latitude": 54.4,
"longitude": -32.7
}
}, {
"id": 3,
"name": "A blue mouse",
"price": 25.50,
"dimensions": {
"length": 3.1,
"width": 1.0,
"height": 1.0
},
"warehouseLocation": ""
}]
var filteredArr = arr.filter(function(val) {
if (val.warehouseLocation == "")
return false;
return true;
});
console.log(filteredArr);