I am adapting the Vega animated scatter chart to display test data.
When the data is loaded from a json file, the chart looks like this:
When the data is loaded from an elasticsearch index, the result is empty data:
Here is a code snippet showing the beginning of the "data" section of the source code:
"data": [
{
"name": "fxtrades",
// uncommenting the following url displays the data
// "url": "http://localhost/AnimatedPriceData1.json"
// uncommenting the following url results in empty data
// note: pricescattertest index contains identical data to AnimatedPriceData1.json
"url": {
%context%: true
%timefield%: @timestamp
index: pricescattertest-*
body: {
size: 10000
_source: [ "settlementcurrency", "price", "quantity", "monthnum", "mnthname"]
}
}
},
{
"name": "clusters",
"values": [
{"id": 0, "name": "AUS"},
Here is the the first part source: (could somebody tell me why the the elasticsearch index solution is not working):
{
"$schema": "https://vega.github.io/schema/vega/v3.json",
"title": "Animated Scatter plot test - Historical 2018 monthly Max Close price vs Min AdjustedSodPrice",
"background": lightyellow
"width": 1200,
"height":650,
"config": {
"axis": {
"grid": true,
"gridColor": "lightblue",
"labelColor": "#888",
"labelAngle": -45,
"labelPadding": 8,
"titleColor": "blue",
"titleFontSize": 14
},
"legend": {
"padding": 10,
"titleColor": "blue"
}
},
"padding": 5,
"autosize": "pad",
"data": [
{
"name": "fxtrades",
// uncommenting the following url displays the data
// "url": "http://localhost/AnimatedPriceData1.json"
// uncommenting the following url results in empty data
// note: pricescattertest index contains identical data to AnimatedPriceData1.json
"url": {
%context%: true
%timefield%: @timestamp
index: pricescattertest-*
body: {
size: 10000
_source: [ "settlementcurrency", "price", "quantity", "monthnum", "mnthname"]
}
}
},
{
"name": "clusters",
"values": [
{"id": 0, "name": "AUS"},
{"id": 1, "name": "BRA"},
{"id": 2, "name": "CAN"},
{"id": 3, "name": "CHN"},
{"id": 4, "name": "HKG"},
{"id": 5, "name": "IND"},
{"id": 6, "name": "JPN"},
{"id": 7, "name": "KOR"},
{"id": 8, "name": "MYS"},
{"id": 9, "name": "SGP"},
{"id": 10, "name": "THA"},
{"id": 11, "name": "TWN"},
{"id": 12, "name": "USA"},
]
},
{
"name": "settlementcurrency_timeline",
"source": "fxtrades",
//"source": _source,
"transform": [
{"type": "filter", "expr": "timeline && datum.settlementcurrency == timeline.settlementcurrency"},
{"type": "collect", "sort": {"field": "monthnum"}}
]
},
{
"name": "thisMonth",
"source": "fxtrades",
// "source": _source,
"transform": [
{"type": "filter", "expr": "datum.monthnum == currentMonth"}
]
},
{
"name": "prevMonth",
"source": "fxtrades",
// "source": _source,
"transform": [
{"type": "filter", "expr": "datum.monthnum == currentMonth - stepMonth"}
]
},
{
"name": "nextMonth",
"source": "fxtrades",
// "source": _source,
"transform": [
{"type": "filter", "expr": "datum.monthnum == currentMonth + stepMonth"}
]
},
{
"name": "settlementcurrencies",
"source": "fxtrades",
// "source": _source,
"transform": [
{"type": "aggregate", "groupby": ["settlementcurrency"]}
]
},
{
"name": "interpolate",
"source": "settlementcurrencies",
"transform": [
{
"type": "lookup",
"from": "thisMonth", "key": "settlementcurrency",
"fields": ["settlementcurrency"], "as": ["this"],
"default": {}
},
{
"type": "lookup",
"from": "prevMonth", "key": "settlementcurrency",
"fields": ["settlementcurrency"], "as": ["prev"],
"default": {}
},
{
"type": "lookup",
"from": "nextMonth", "key": "settlementcurrency",
"fields": ["settlementcurrency"], "as": ["next"],
"default": {}
},
{
"type": "formula",
"as": "target_price",
"expr": "interMonth > currentMonth ? datum.next.price : (datum.prev.price||datum.this.price)"
},
{
"type": "formula",
"as": "target_quantity",
"expr": "interMonth > currentMonth ? datum.next.quantity : (datum.prev.quantity||datum.this.quantity)"
},
{
"type": "formula",
"as": "inter_price",
"expr": "interMonth==11 ? datum.this.price : datum.this.price + (datum.target_price-datum.this.price) * abs(interMonth-datum.this.monthnum)/1"
},
{
"type": "formula",
"as": "inter_quantity",
"expr": "interMonth==11 ? datum.this.quantity : datum.this.quantity + (datum.target_quantity-datum.this.quantity) * abs(interMonth-datum.this.monthnum)/1"
}
]
},
{
"name": "trackSettlementcurrencies",
"on": [
{"trigger": "active", "toggle": "{settlementcurrency: active.settlementcurrency}"}
]
}
],