I use a Custom Fusion Chart (Scatter) and I have loaded the data I want to display. I stick to the required x, y format with my data. I would now like to scatter the data along a time axis (x). The import of the data works like a charm, but the axis looks like it just uses the x value as String/Integer. Does anyone have an idea how to properly format the x-axis or the data to be a time axis?
What I also found out that by using regular charts it looks a bit better but the time-stamps do not scale properly across the x-axis (can be seen in the 2nd image).
The json for the custom chart:
{
"type": "scatter",
"dataSource": {
"chart": {
"caption": "Axes",
"subCaption": "Aggregated History",
"baseFont": "Helvetica Neue,Arial",
"xAxisName": "Date",
"yAxisName": "Price",
"theme": "fusion"
},
"categories": [],
"dataset": [
{
"seriesname": "Offer",
"showregressionline": "0",
"data": [
{
"x": "2022-01-20T13:50:00Z",
"y": 105.316
},
{
"x": "2022-02-01T11:16:00Z",
"y": 104.64
},
{
"x": "2022-02-01T11:16:00Z",
"y": 104.64
},
{
"x": "2022-02-01T12:18:00Z",
"y": 104.599
},
{
"x": "2022-02-01T12:18:00Z",
"y": 104.599
},
{
"x": "2022-02-01T12:19:00Z",
"y": 104.564
},
{
"x": "2022-02-01T12:49:00Z",
"y": 104.608
},
{
"x": "2022-02-01T12:49:00Z",
"y": 104.572
},
{
"x": "2022-02-01T13:03:00Z",
"y": 104.56
},
{
"x": "2022-02-01T13:19:00Z",
"y": 104.593
}
]
},
{
"seriesname": "Bid",
"showregressionline": "0",
"data": [
{
"x": "2022-02-14T13:47:00Z",
"y": 102.415
},
{
"x": "2022-02-14T13:47:00Z",
"y": 102.415
},
{
"x": "2022-02-14T13:47:00Z",
"y": 102.415
},
{
"x": "2022-02-14T14:17:00Z",
"y": 102.421
},
{
"x": "2022-02-14T14:17:00Z",
"y": 102.421
},
{
"x": "2022-02-14T14:17:00Z",
"y": 102.421
},
{
"x": "2022-02-14T14:47:00Z",
"y": 102.373
},
{
"x": "2022-02-14T14:47:00Z",
"y": 102.373
},
{
"x": "2022-02-14T14:47:00Z",
"y": 102.373
},
{
"x": "2022-02-14T15:17:00Z",
"y": 102.443
}
]
}
],
"vtrendlines": []
}
}
This worked for me, Basically the scatter chart is having a hard time understanding the date objects directly. To resolve that we will need to use some configs from the fusion chart and also the moment lib to get the right value
Start with adding the category object in the `categories object.
...
"categories": [{
"category": [
{
"x": "{{moment('2022-01-20').unix()}}",
"label": "2022-01-20",
"showverticalline": "0"
}, ...
]
}]
...
notice that the x key value will correspond to the value in your dataset.
Now we do the same for the dataset as well.
...
"dataset": [
{
"seriesname": "Offer",
"showregressionline": "0",
"data": [
{
"x": "{{moment('2022-01-20T13:50:00Z').unix()}}",
"y": 105.316
}, ...
]
}
], ...
the result of this is:
My JS object
var x = {
"type": "scatter",
"dataSource": {
"chart": {
"caption": "Axes",
"subCaption": "Aggregated History",
"baseFont": "Helvetica Neue,Arial",
"xAxisName": "Date",
"yAxisName": "Price",
"theme": "fusion"
},
"categories": [{
"category": [
{
"x": "{{moment('2022-01-20').unix()}}",
"label": "2022-01-20",
"showverticalline": "0"
},
{
"x": "{{moment('2022-02-01').unix()}}",
"label": "2022-02-01",
"showverticalline": "1"
},
{
"x": "{{moment('2022-02-02').unix()}}",
"label": "2022-02-02",
"showverticalline": "1"
},
{
"x": "{{moment('2022-02-03').unix()}}",
"label": "2022-02-03",
"showverticalline": "1"
},
{
"x": "{{moment('2022-02-04').unix()}}",
"label": "2022-02-04",
"showverticalline": "1"
},
{
"x": "{{moment('2022-02-05').unix()}}",
"label": "2022-02-05",
"showverticalline": "1"
},
{
"x": "{{moment('2022-02-06').unix()}}",
"label": "2022-02-06",
"showverticalline": "1"
},
{
"x": "{{moment('2022-02-07').unix()}}",
"label": "2022-02-07",
"showverticalline": "1"
},
{
"x": "{{moment('2022-02-08').unix()}}",
"label": "2022-02-08",
"showverticalline": "1"
},
{
"x": "{{moment('2022-02-09').unix()}}",
"label": "2022-02-09",
"showverticalline": "1"
}
]
}],
"dataset": [
{
"seriesname": "Offer",
"showregressionline": "0",
"data": [
{
"x": "{{moment('2022-01-20T13:50:00Z').unix()}}",
"y": 105.316
},
{
"x": "{{moment('2022-02-01T11:16:00Z').unix()}}",
"y": 104.64
},
{
"x": "{{moment('2022-02-01T11:16:00Z').unix()}}",
"y": 104.64
},
{
"x": "{{moment('2022-02-01T12:18:00Z').unix()}}",
"y": 104.599
},
{
"x": "{{moment('2022-02-01T12:18:00Z').unix()}}",
"y": 104.599
},
{
"x": "{{moment('2022-02-01T12:19:00Z').unix()}}",
"y": 104.564
},
{
"x": "{{moment('2022-02-01T12:49:00Z').unix()}}",
"y": 104.608
},
{
"x": "{{moment('2022-02-01T12:49:00Z').unix()}}",
"y": 104.572
},
{
"x": "{{moment('2022-02-01T13:03:00Z').unix()}}",
"y": 104.56
},
{
"x": "{{moment('2022-02-01T13:19:00Z').unix()}}",
"y": 104.593
}
]
}
],
"vtrendlines": []
}
}
console.log(x)
Related
How do I convert number to double word in Node-red?
I tried throwing the array in
but no response
I'm not very good at node red, please answer me, thank you
What do you mean converting 'number' to 'double word'?
Data type 'double' is already number type.
Do you mean String to number?
[
{
"id": "bd8884d5c2f82322",
"type": "tab",
"label": "플로우 1",
"disabled": false,
"info": "",
"env": []
},
{
"id": "4546977fe7434e95",
"type": "inject",
"z": "bd8884d5c2f82322",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "1234.34",
"payloadType": "str",
"x": 160,
"y": 40,
"wires": [
[
"a93489fbd55883b2",
"f1ad7ec076bceb78"
]
]
},
{
"id": "a93489fbd55883b2",
"type": "function",
"z": "bd8884d5c2f82322",
"name": "Convert String to Number",
"func": "msg.payload=Number(msg.payload);\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 370,
"y": 40,
"wires": [
[
"1f695a58ebc55f90"
]
]
},
{
"id": "1f695a58ebc55f90",
"type": "debug",
"z": "bd8884d5c2f82322",
"name": "number",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 560,
"y": 40,
"wires": []
},
{
"id": "f1ad7ec076bceb78",
"type": "debug",
"z": "bd8884d5c2f82322",
"name": "string",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 310,
"y": 80,
"wires": []
}]
Name | Value 1 | Value 2
BTC | 1 | 2
ETH | 1 | 2
to this:
Tried to used this as an example: https://vega.github.io/vega-lite/examples/bar_grouped.html,
but I can't make it work.
Can someone please point me to the right direction? Thank you in advance.
Instead of using column provided in your question, You can simply use layers and keep the x axis as common and provide value1 and value2 in y axis of each layer respectively and simply provide some offset to show it as a grouped bar chart. Below is the basic spec configuration and editor:
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"description": "A simple bar chart with embedded data.",
"title": "My chart",
"width": 200,
"data": {
"values": [
{"name": "BTH", "value1": 28, "value2": 24, "legendTitle": "value1"},
{"name": "ETH", "value1": 55, "value2": 25, "legendTitle": "value2"}
]
},
"encoding": {
"x": {"field": "name", "type": "nominal", "axis": {"labelAngle": 0}}
},
"layer": [
{
"mark": {"type": "bar", "xOffset": -20, "size": 30, "color": "skyblue"},
"encoding": {
"y": {
"field": "value1",
"type": "quantitative",
"axis": {"title": null, "ticks": false}
}
}
},
{
"mark": {"type": "bar", "size": 30, "xOffset": 18, "color": "orange"},
"encoding": {
"y": {
"field": "value2",
"type": "quantitative",
"axis": {"title": null, "ticks": false}
}
}
},
{
"mark": {"type": "text"},
"encoding": {
"fill": {
"field": "legendTitle",
"scale": {"range": ["skyBlue", "orange"]},
"legend": {"title": null, "symbolType": "square", "orient": "bottom"}
}
}
}
]
}
I have implemented an OCR invoice solution using Google Vision API DOCUMENT_TEXT_DETECTION service. The software has been in production for a couple months. 99% of the time, the results are pretty accurate. But every once in a while, I get some results containing normalizedVertices with points greater than 1. According to the docs, a normalized vertex should be between 0 and 1. Anyone know why this happens? And how these should be interpreted?
Only thing I have noticed (in conjunction with this issue) is that often the documents producing these results may be rotated. But I don't see why rotation would cause the normalization to be off.
Here's a sample file
{
"fullTextAnnotation": {
"pages": [
{
"property": {
"detectedLanguages": [
{
"languageCode": "en",
"confidence": 0.84
},
{
"languageCode": "da",
"confidence": 0.01
}
]
},
"width": 612,
"height": 792,
"blocks": [
{
"boundingBox": {
"normalizedVertices": [
{
"x": 1.2254902,
"y": 0.79545456
},
{
"x": 1.2254902,
"y": 0.9166667
},
{
"x": 1.1960784,
"y": 0.9166667
},
{
"x": 1.1960784,
"y": 0.79545456
}
]
},
"paragraphs": [
{
"boundingBox": {
"normalizedVertices": [
{
"x": 1.2254902,
"y": 0.79545456
},
{
"x": 1.2254902,
"y": 0.9166667
},
{
"x": 1.1960784,
"y": 0.9166667
},
{
"x": 1.1960784,
"y": 0.79545456
}
]
},
"words": [
{
"property": {
"detectedLanguages": [
{
"languageCode": "en"
}
]
},
"boundingBox": {
"normalizedVertices": [
{
"x": 1.2254902,
"y": 0.79545456
},
{
"x": 1.2254902,
"y": 0.9166667
},
{
"x": 1.1960784,
"y": 0.9166667
},
{
"x": 1.1960784,
"y": 0.79545456
}
]
},
"symbols": [
{
"property": {
"detectedLanguages": [
{
"languageCode": "en"
}
]
},
"text": "I",
"confidence": 0.99
},
{
"property": {
"detectedLanguages": [
{
"languageCode": "en"
}
]
},
"text": "N",
"confidence": 1
},
{
"property": {
"detectedLanguages": [
{
"languageCode": "en"
}
]
},
"text": "V",
"confidence": 0.99
},
{
"property": {
"detectedLanguages": [
{
"languageCode": "en"
}
]
},
"text": "O",
"confidence": 0.99
},
{
"property": {
"detectedLanguages": [
{
"languageCode": "en"
}
]
},
"text": "I",
"confidence": 0.99
},
{
"property": {
"detectedLanguages": [
{
"languageCode": "en"
}
]
},
"text": "C",
"confidence": 0.99
},
{
"property": {
"detectedLanguages": [
{
"languageCode": "en"
}
],
"detectedBreak": {
"type": "LINE_BREAK"
}
},
"text": "E",
"confidence": 1
}
],
"confidence": 0.99
}
],
"confidence": 0.99
}
],
"blockType": "TEXT",
"confidence": 0.99
},...
My input JSON looks like below, but i am not sure of how to do internal array related parameter transformation using JOLT. Any help is appreciated as i am new to JOLT
{
"pktId": 7603,
"seq": 1,
"vehicleNumber": "66079",
"rmdLocation": "1",
"rmdTime": "2019-01-07T11:27:05.745Z",
"position": {
"lat": 55.4911232,
"lng": -3.686831
},
"dataSource": 11,
"frames": [
{
"seq": 0,
"card": 8,
"channel": 6,
"value": 117
},
{
"seq": 1,
"card": 8,
"channel": 6,
"value": 120
}
]
}
Below is the spec file i have created but it is not complete
[
{
"operation": "shift",
"spec": {
"frames": {
"*": {
"seq": "parameters[&1].seq",
"card": "parameters[&1].card",
"channel": "parameters[&1].channel",
"value": "parameters[&1].value"
}
},
"rmdTime": "messageTime",
"vehicleNumber": "roadNumber"
}
},
{
"operation": "default",
"spec": {
"appId": "configMsgXX",
"customerId": "ABC",
"messageRev": 1,
"messageType": "customStatistics"
}
}
]
Expected output is as below
{
"appId": "configMsgXX",
"customerId": "ABC",
"deviceId": string1+roadNumber+string2",
"messageRev": 1,
"messageTime": 1543395341000,
"messageType": "customStatistics",
"parameters": [
{
"address": string1+string2,
"name": "EM2000VoltageMainGenerator",
"timestamp": 1543395341000,
"quality": "3",
"datatype": "INTEGER",
"value": 100,
"qualityReason": "Stale Data",
"category": "REAL"
}
],
"roadNumber": 66079
}
I am using this library https://github.com/bazaarvoice/jolt
[
{
"operation": "shift",
"spec": {
"frames": {
"*": {
"seq": "parameters[&1].seq",
"card": "parameters[&1].card",
"channel": "parameters[&1].channel",
"value": "parameters[&1].value",
"#(2,rmdTime)": "parameters[&1].timestamp"
}
},
"rmdTime": "messageTime",
"vehicleNumber": "roadNumber"
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"parameters": {
"*": {
"quality": "3",
"name": "",
"address": "",
"datatype": "INTEGER",
"qualityReason": "Stale Data",
"category": "REAL"
}
}
}
},
{
"operation": "default",
"spec": {
"appId": "configMsgXX",
"customerId": "ABC",
"messageRev": 1,
"messageType": "customStatistics"
}
}
]
i whant to make every bar in chart - in different collor. please help.
so default chart like described in docs:
https://vega.github.io/vega/examples/bar-chart/
for example - i whant to make like: blue, red, yellow, green, blue, blue.
please help! thanks!
Using the Vega bar chart example you linked to:
First, create a scale to define the colors:
{
"name": "colors",
"type": "ordinal",
"domain": {"data": "table", "field": "category"},
"range": {"scheme": "category10"}
}
The value for the "scheme" can be a built-in scheme from Vega, or a custom scheme.
Then, you need to specify the color for the fill on the mark's update property set, specifying the name of the scheme:
"update": {
"fill": {"scale": "colors", "field": "category"}
},
You can define a categorical color scale and use it to change the color of the bar mark. Check out some of the other examples that use categorical color scales.
I had the same problem and with a little help from https://vega.github.io/vega-lite/examples/bar_color_disabled_scale.html I got to the following - the idea is to encode the color in the data:
{
"$schema": "https://vega.github.io/schema/vega-lite/v4.json",
"description": "A simple bar chart with embedded data.",
"data": {
"values": [
{"a": "A", "b": 28, "c": "black"},
{"a": "B", "b": 55, "c": "black"},
{"a": "C", "b": 43, "c": "black"},
{"a": "D", "b": 91, "c": "red"}
]
},
"mark": "bar",
"encoding": {
"x": {"field": "a", "type": "ordinal"},
"y": {"field": "b", "type": "quantitative"},
"color": {"field": "c", "type": "nominal", "scale": null}
}
}
alternatively this also works and keeps the legend if you need it:
{
"$schema": "https://vega.github.io/schema/vega-lite/v4.json",
"description": "A simple bar chart with embedded data.",
"data": {
"values": [
{"a": "A", "b": 28},
{"a": "B", "b": 55},
{"a": "C", "b": 43},
{"a": "D", "b": 91}
]
},
"mark": "bar",
"encoding": {
"x": {"field": "a", "type": "ordinal", "sort": ["C", "A", "B", "D"]},
"y": {"field": "b", "type": "quantitative"},
"color": {"field": "a", "type": "nominal", "sort": ["C", "A", "B", "D"], "scale": {"range": ["red", "black", "black", "black", "black"]}}
}
}
For bar charts
{
"$schema": "https://vega.github.io/schema/vega-lite/v4.json",
"description": "A bar chart that directly encodes color names in the data.",
"data": {
"values": [
{
"color": "yellow",
"b": 28
},
{
"color": "green",
"b": 55
},
{
"color": "blue",
"b": 43
}
]
},
"mark": "bar",
"encoding": {
"x": {
"field": "color",
"type": "nominal"
},
"y": {
"field": "b",
"type": "quantitative"
},
"color": {
"field": "color",
"type": "nominal",
"scale": null
}
}
}
For Pie charts
{
"$schema": "https://vega.github.io/schema/vega/v5.json",
"width": 200,
"height": 200,
"autosize": "none",
"signals": [
{
"name": "startAngle", "value": 0,
"bind": {"input": "range", "min": 0, "max": 6.29, "step": 0.01}
},
{
"name": "endAngle", "value": 6.29,
"bind": {"input": "range", "min": 0, "max": 6.29, "step": 0.01}
},
{
"name": "padAngle", "value": 0,
"bind": {"input": "range", "min": 0, "max": 0.1}
},
{
"name": "innerRadius", "value": 0,
"bind": {"input": "range", "min": 0, "max": 90, "step": 1}
},
{
"name": "cornerRadius", "value": 0,
"bind": {"input": "range", "min": 0, "max": 10, "step": 0.5}
},
{
"name": "sort", "value": false,
"bind": {"input": "checkbox"}
}
],
"data": [
{
"name": "table",
"values": [
{"field": 10,"color": "blue"},
{"field": 3,"color": "green"},
{"field": 7,"color": "red"},
{"field": 8,"color":"orange"},
{"field": 15,"color":"yellow"}
],
"transform": [
{
"type": "pie",
"field": "field",
"startAngle": {"signal": "startAngle"},
"endAngle": {"signal": "endAngle"},
"sort": {"signal": "sort"}
}
]
}
],
"scales": [
{
"name": "color",
"type": "ordinal",
"domain": {"data": "table", "field": "color"},
"range": {"scheme": "category20"}
}
],
"marks": [
{
"type": "arc",
"from": {"data": "table"},
"encode": {
"enter": {
"fill": { "field": "color",
"type": "nominal",
"scale": null},
"x": {"signal": "width / 2"},
"y": {"signal": "height / 2"}
},
"update": {
"startAngle": {"field": "startAngle"},
"endAngle": {"field": "endAngle"},
"padAngle": {"signal": "padAngle"},
"innerRadius": {"signal": "innerRadius"},
"outerRadius": {"signal": "width / 2"},
"cornerRadius": {"signal": "cornerRadius"}
}
}
}
]
}