*Desired output**
Actual output
The points don't become a line.
Question
How do I modify my code to achieve the desired output?
This is my code:
function create() {
var series = [];
$.ajax({
type: "POST",
url: url,
async: false,
success: function (result) {
var channels = Object.keys(result.result.data);
var size = channels.length;
var name = result.result.labels[1];
for (var i = 0; i < size; i++) {
var data = result.result.data[i][1];
var time = result.result.data[i][0];
var test = [];
test.push({
x:time,
y:data
});
series.push({
"name": name,
"data": test
});
}
}
}, false);
return series;
}
Here is the data returned from url
{
"api": 1,
"id": "system.cpu",
"name": "system.cpu",
"view_update_every": 1,
"update_every": 1,
"first_entry": 1464153889,
"last_entry": 1464154575,
"before": 1464154575,
"after": 1464154556,
"dimension_names": ["iowait"],
"dimension_ids": ["iowait"],
"latest_values": [0],
"view_latest_values": [0],
"dimensions": 1,
"points": 20,
"format": "json",
"result": {
"labels": ["time", "iowait"],
"data":
[
[ 1464154556000, 0],
[ 1464154557000, 0],
[ 1464154558000, 0],
[ 1464154559000, 0],
[ 1464154560000, 0],
[ 1464154561000, 0],
[ 1464154562000, 0],
[ 1464154563000, 0],
[ 1464154564000, 0],
[ 1464154565000, 0],
[ 1464154566000, 0],
[ 1464154567000, 0],
[ 1464154568000, 0],
[ 1464154569000, 0],
[ 1464154570000, 0],
[ 1464154571000, 0],
[ 1464154572000, 0],
[ 1464154573000, 0],
[ 1464154574000, 0],
[ 1464154575000, 0]
]
},
"min": 0,
"max": 96.9697
}
Related
query = {
"maxResults": 2,
"criteria": {
"sinceDate": [
2022,
1,
3
],
"untilDate": [
2022,
3,
31
],
"allOfTheseWords": [],
"anyOfTheseWords": [
],
"noneOfTheseWords": [],
"theseHashtags": [],
"fromTheseAccounts": [],
"toTheseAccounts": [],
"mentioningTheseAccounts": [],
"language": "tr",
"filterReplies": True,
"filterLinks": False
}
}
query_json = json.dumps(query)
#print(query_json)
try:
async with session.post("xxx", json = query_json) as response:
resp = await response.read()
I have a response json like this:
{
"variables": {
"lock": 0,
"pos": 55,
"pos_on": 55,
"pos_off": 150
},
"id": "11",
"name": "Lock_table_2",
"hardware": "esp8266",
"connected": true
}
and I try to show the lock value in 'variables' object
so I write
constructor(props) {
super(props)
this.state = {
dock_1: {}, // define a empty json
dock_2: {},
dock_3: {},
}
}
pingIP() {
axios
.get('http://192.168.50.225:8888/test_check')
.then(response => {
let data = response.data.list; // return value is a list
this.setState({ // every 2 sec setState
dock_1: data[0], // data[0] -> 192.168.50.40's json
dock_2: data[1],
dock_3: data[2],
})
})
}
render(){
return (
<p>{this.state.dock_1.variables.lock}</p>
);
}
but I got this error
in here
So I tried this
render(){
return (
<p>{this.state.dock_1.variables}</p>
);
}
then here comes the another error message
in here
here is the get request return value
{
"list": [
{
"connected": true,
"hardware": "esp8266",
"id": "10",
"name": "Lock_table_1",
"variables": {
"lock": 1,
"pos": 80,
"pos_off": 160,
"pos_on": 80
}
},
{
"connected": true,
"hardware": "esp8266",
"id": "10",
"name": "Lock_table_2",
"variables": {
"lock": 1,
"pos": 80,
"pos_off": 160,
"pos_on": 80
}
},
{
"connected": true,
"hardware": "esp8266",
"id": "10",
"name": "Lock_table_3",
"variables": {
"lock": 1,
"pos": 80,
"pos_off": 160,
"pos_on": 80
}
}
]
}
the return value is a list
in order to get first value so I wrote data[0], data1 ...
what's happening in here?
I think your response is an array of 3 items like this:
[
{
variables: {
lock: 0,
pos: 55,
pos_on: 55,
pos_off: 150
},
id: "11",
name: "Lock_table_2",
hardware: "esp8266",
connected: true
},
{
variables: {
lock: 1,
pos: 44,
pos_on: 56,
pos_off: 151
},
id: "11",
name: "Lock_table_3",
hardware: "esp8267",
connected: false
},
{
variables: {
lock: 2,
pos: 45,
pos_on: 57,
pos_off: 152
},
id: "11",
name: "Lock_table_4",
hardware: "esp8268",
connected: true
}
]
So you can access the dock 1 variable lock using Inline If with Logical && Operator to prevent null exception.
<p>{this.state.dock_1.variables && this.state.dock_1.variables.lock}</p>
A sample working codesandbox with a fake api:
https://codesandbox.io/s/stoic-chaplygin-r1yxd
So I've got the code to express my spreadsheet data in a pivot table, but I need the values to show as a percentage of column total. It seems that there's a property to achieve that result, but I don't know how to integrate that into the script.
https://developers.google.com/apps-script/reference/spreadsheet/pivot-value-display-type
function addPivotTable3(spreadsheetId3, pivotSourceDataSheetId3, destinationSheetId3)
{
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheetName = "Sheet3";
var pivotTableParams = {};
// The source indicates the range of data you want to put in the table.
// optional arguments: startRowIndex, startColumnIndex, endRowIndex, endColumnIndex
pivotTableParams.source = {
sheetId: ss.getSheetByName(sheetName).getSheetId()
};
// Group rows, the 'sourceColumnOffset' corresponds to the column number in the source range
// eg: 0 to group by the first column
pivotTableParams.rows = [{
sourceColumnOffset: 2,
sortOrder: "ASCENDING"
}];
// Defines how a value in a pivot table should be calculated.
pivotTableParams.values = [{
summarizeFunction: "SUM",
displayType: "PERCENT_OF_COLUMN_TOTAL",
sourceColumnOffset: 3
}];
var requests = [{
'updateCells': {
'rows': {
'values': [
{
'pivotTable': {
'source': {
'sheetId': pivotSourceDataSheetId3,
'startRowIndex': 0,
'startColumnIndex': 0,
'endRowIndex': 94,
'endColumnIndex': 4,
},
'rows': [
{
'sourceColumnOffset': 2,
'showTotals': true,
'sortOrder': 'ASCENDING',
'valueBucket': {
'buckets': [
{
'stringValue': 'BAE Stages',
},
],
},
},
{
'sourceColumnOffset': 94,
'showTotals': true,
'sortOrder': 'ASCENDING',
'valueBucket': {},
},
],
'columns': [
{
'sourceColumnOffset': 0,
'sortOrder': 'ASCENDING',
'showTotals': true,
'valueBucket': {},
},
],
'values': [
{
'summarizeFunction': "SUM",
'sourceColumnOffset': 3,
//'displayType': "PERCENT_OF_COLUMN_TOTAL",
//This line triggers a JSON erorr
},
],
'valueLayout': 'HORIZONTAL',
},
},
],
},
'start': {
'sheetId': destinationSheetId3,
'rowIndex': 0,
'columnIndex': 0,
},
'fields': 'pivotTable',
},
}];
var response =
Sheets.Spreadsheets.batchUpdate({'requests': requests}, spreadsheetId3);
}
Well, I didn't know either and the documentation is soooooo mysterious.
I was about to give up then I came across this: https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets#PivotValueCalculatedDisplayType
Eventually I worked out your line should be:
'calculatedDisplayType' : "PERCENT_OF_COLUMN_TOTAL",
(On the above webpage is PivotValueCalculatedDisplayType and within the table is the ENUM you mentioned, "PERCENT_OF_COLUMN_TOTAL"
I had a hunch that since we are in pivot table/value part of the object, we don't need the PivotValue ... so we're left with calculatedDisplayType.
Phew.
UPDATE(2):
I got it to work so here is the working fiddle. See below for my solution. If you know of any other solutions, let me know. Thanks! otherwise...feel free to use this example :)
UPDATE(1):
I've continued working on it and here is my updated fiddle. I think I'm overriding my variable/data values each time I loop through. Any help is greatly appreciated.
ORIGINAL POST:
I have a jsfiddle here that shows what I'm trying to do.
I have a series of data in json format that has multiple objects(i.e.,
[
{"name":"name1", "data":[[0,4.3],[1,2.47],[2,0.2],etc.]},
{"name":"name2", "data":[[0,4.3],[1,2.47],[2,0.2],etc.]}
]
)
and am graphing with HighCharts line graphs. Instead, I'd like to define the series data to objects from multiple subtasks all on the same graph. (the variable is better shown in the jsfiddle link)
[
{"subtask":"id1", "":[
{"name":"name1", "data":[[0,4.3],[1,2.47],[2,0.2],etc.]},
{"name":"name2", "data":[[0,3.5],[1,2.12],[2,0.1],etc.]}
]
},
{"subtask":"id2", "":[
{"name":"name1", "data":[[0,4.1],[1,2.23],[2,0.4],etc.]},
{"name":"name2", "data":[[0,3],[1,2.62],[2,0.15],etc.]}
]
}
]
and I'd like the graph to draw a line for each name/data for each subtask (i.e., the graph draw a line for id1.name1.data, id1.name2.data, id2.name1.data, and id2.name2.data)
My Solution:
I got it to work so here is the working fiddle. If you know of any other solutions, let me know. Thanks! otherwise...feel free to use this example :)
// what currently works
var jsonFormatThatWorks = [{
"name": "name1",
"data": [
[0, 100],
[10, 70.02],
[20, 60.7],
[30, 45.3],
[40, 35],
[50, 32],
[60, 14],
[70, 0]
]
},
{
"name": "name2",
"data": [
[0, 100],
[10, 30],
[20, 13],
[30, 8],
[40, 7.5],
[50, 5.2],
[60, 4.54],
[70, 0.3],
[80, 0.01]
]
}
]
// format I want/need to be able to access/graph
var jsonFormatIWant = [{
"p1": "12345",
"taskName": "z-echo",
"taskData": [{
"subTaskId": "z8-echo",
"someTaskStatus": "Rejected",
"someTaskData": [{
"objectId": "name1",
"objectData": [
[0, 100],
[10, 90.80],
[20, 80.37],
[30, 75],
[40, 66],
[50, 33],
[60, 15],
[70, 0]
]
},
{
"objectId": "name2",
"objectData": [
[0, 100],
[10, 23],
[20, 15],
[30, 11],
[40, 8.5],
[50, 6.2],
[60, 3.44],
[70, 0.7],
[80, 0.5]
]
}
]
},
{
"subTaskId": "z9-echo",
"someTaskStatus": "Accepted",
"someTaskData": [{
"objectId": "name1",
"objectData": [
[0, 100],
[10, 70.02],
[20, 60.7],
[30, 45.3],
[40, 35],
[50, 32],
[60, 14],
[70, 0]
]
},
{
"objectId": "name2",
"objectData": [
[0, 100],
[10, 30],
[20, 13],
[30, 8],
[40, 7.5],
[50, 5.2],
[60, 4.54],
[70, 0.3],
[80, 0.01]
]
}
]
}
]
}]
// my chart
$(document).ready(function() {
var options = {
chart: {
renderTo: 'container',
type: 'line',
zoomType: 'xy',
panning: true,
panKey: 'shift'
},
xAxis: {
title: {
text: 'Some X Label'
},
crosshair: true
},
plotOptions: {
series: {
marker: {
radius: 1
},
allowPointSelect: true
}
},
yAxis: {
labels: {
format: '{value} %'
},
floor: 0,
ceiling: 100,
title: {
text: 'Value (%)'
},
crosshair: true,
gridLineDashStyle: 'ShortDash',
gridLineColor: '#aaaaaa'
},
title: {
text: 'Sample Chart'
},
subtitle: {
text: 'Click and drag to zoom in. Hold down shift key to pan.'
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'middle',
borderWidth: 0
},
series: seriesOptions
};
var chart = new Highcharts.Chart(options);
});
var seriesOptions = [],
seriesCounter = 0
var data = jsonFormatIWant[0]
var taskData = data.taskData
taskData.forEach(function(element, i) {
element.someTaskData.forEach(function(childElement, j) {
seriesOptions[seriesCounter] = {
//task: element.subTaskId,
name: element.subTaskId + "_" + element.someTaskData[j].objectId,
data: element.someTaskData[j].objectData
}
seriesCounter += 1
//console.log(seriesCounter)
childElement.objectData.forEach(function(grandChildElement, h) {})
})
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/series-label.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<div id="container"></div>
<!-- I'd like to be able to graph each objects data for each subTask
(i.e., z8-echo and z9-echo from the data jsonFormatIWant variable beneath the chart definition)
something like: taskData[0].someTaskData and taskData[1].someTaskData -->
I know you can animate circles on google maps , see example
http://jsbin.com/nuwem/1/edit?html,output
.....But can you do the same thing on Mapbox
I am creating a live earthquake map www.livehazards.com. Each earthquake mag is respresent by a circle
I would just like the outline of the circle and to be able to animate it.
I have tried using circle-stroke for just the outline but it did not work
Thanks
To animate your circle you can simply change its paint property several times: map.setPaintProperty('yourmarker', 'circle-radius', 20)
If you only want the circle outline, set "circle-opacity":0 and "circle-stroke-width": 1.
Codepen
const map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/light-v9',
center: [ 2.35, 48.85 ],
zoom: 3
});
map.on('load', () => {
let radius = 1;
map.addLayer({
"id": "points",
"type": "circle",
// Create the marker
"source": {
"type": "geojson",
"data": {
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [ 2.35, 48.85 ]
}
}]
}
},
// Draw the circle
"paint": {
"circle-opacity": 0,
"circle-stroke-width": 1,
"circle-stroke-color": "#000",
"circle-radius": radius,
"circle-radius-transition": {
"duration": 0
}
}
});
// Animate the circle
setInterval(() => {
map.setPaintProperty('points', 'circle-radius', radius);
radius = ++radius % 30;
}, 50);
});
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/light-v9',
center: [ 2.35, 48.85 ],
zoom: 3
});
map.on('load', function() {
let radius = 1;
map.addSource("earthquakes", {
type: "geojson",
data: "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/4.5_day.geojson",
});
map.addLayer({
"id": "earthquake-layer",
"type": "circle",
"source": "earthquakes",
"paint": {
"circle-opacity": 0.4,
"circle-color": "#830300",
"circle-stroke-width": 2,
"circle-stroke-color": "#fff",
"circle-radius": {
"property": "mag",
"base": 2.5,
"stops": [
[{zoom: 0, value: 2}, 1],
[{zoom: 0, value: 8}, 40],
[{zoom: 11, value: 2}, 10],
[{zoom: 11, value: 8}, 2400],
[{zoom: 20, value: 2}, 20],
[{zoom: 20, value: 8}, 6000]
"circle-radius-transition": {
"duration": 0
}
]
}
}
});
setInterval(() => {
map.setPaintProperty('eaarthquake-layer', 'circle-radius', radius);
radius = ++radius % 30
}, 50);
});