chartScrollbar AmCharts - scrollbar

I have a Chart in AmCharts, I want to begin the scroll on the top of the graph not on the bottom.
var chart = AmCharts.makeChart("chartdiv", {
"type": "serial",
"theme": "light",
"rotate":true,
"maxSelectedSeries": 4,
"mouseWheelScrollEnabled": true,
"marginRight": 70,
"dataProvider": [{
"country": "USA",
"visits": 3025,
"color": "#FF0F00"
}, {
"country": "China",
"visits": 1882,
"color": "#FF6600"
}, {
"country": "Japan",
"visits": 1809,
"color": "#FF9E01"
}, {
"country": "Germany",
"visits": 1322,
"color": "#FCD202"
}, {
"country": "UK",
"visits": 1122,
"color": "#F8FF01"
}, {
"country": "France",
"visits": 1114,
"color": "#B0DE09"
}, {
"country": "India",
"visits": 984,
"color": "#04D215"
}, {
"country": "Spain",
"visits": 711,
"color": "#0D8ECF"
}, {
"country": "Netherlands",
"visits": 665,
"color": "#0D52D1"
}, {
"country": "Russia",
"visits": 580,
"color": "#2A0CD0"
}, {
"country": "South Korea",
"visits": 443,
"color": "#8A0CCF"
}, {
"country": "Canada",
"visits": 441,
"color": "#CD0D74"
}],
"valueAxes": [{
"axisAlpha": 0,
"position": "left",
"title": "Visitors from country"
}],
"startDuration": 1,
"graphs": [{
"balloonText": "<b>[[category]]: [[value]]</b>",
"fillColorsField": "color",
"fillAlphas": 0.9,
"lineAlpha": 0.2,
"type": "column",
"valueField": "visits"
}],
"chartCursor": {
"categoryBalloonEnabled": false,
"cursorAlpha": 0,
"zoomable": false
},
"categoryField": "country",
"categoryAxis": {
"gridPosition": "start",
"labelRotation": 45
},
"chartScrollbar": {
//"graph": "Not set",
"backgroundColor":"#2f373e",
"graphType": "smoothedLine",
"resizeEnabled": false,
"scrollbarHeight": 15,
"scrollDuration": 0,
"updateOnReleaseOnly": true
}
});
jsfiddle
As you can see in the jsfiddle the scrollbar begin on the bottom of the graph and I have to scroll to the top of the graph to see the first result.

It seems that the chart zooms to the end because the maxSelectedSeries property is set - the chart zooms to the last ~x series upon initilzation. You can work around this by adding an init listener that sets the zoom to the desired location upon initilation by calling zoomToIndexes:
var chart = AmCharts.makeChart("chartdiv", {
// ...
"listeners": [{
"event": "init",
"method": function(e) {
e.chart.zoomToIndexes(0, 4);
}
}]
});
Updated fiddle

Related

Vega-lite interactive Bar Chart

I am trying to make a basic interactive chart where the user can select a country and observe a single measurement based on the height of the bar. However, prior to selecting a country, the chart shows all the bars stacked on top of each other. once a country is selected i achieve the view that i want.
{"$schema": "https://vega.github.io/schema/vega-lite/v4.json",
"data": {
"url": "https://raw.githubusercontent.com/ConorQuah/ConorQuah.github.io/main/Happiness%26liberties_s%26e.csv"
},
"title": {
"text": "Happiness and Liberty",
"subtitle":"view the happiness of different countries. Notice how the colour of the bar changes!",
"subtitleFontStyle":"italic",
"subtitleFontSize":10,
"anchor": "start"
},
"height": 300,
"width": 300,
"transform": [{"filter": {"selection": "Region"}}],
"selection": {
"Region": {
"type": "single",
"fields": ["Country"],
"bind": {
"input": "select",
"options": [
"null",
"Finland",
"Sweden",
"New Zealand",
"United Kingdom",
"Serbia",
"Zimbabwe",
"Afghanistan"
],
"name": "Select a country"
}
}
},
"mark": {"type": "bar", "width":50},
"encoding": {
"color": {
"field": "Civil liberties",
"title": "Civil liberties",
"scale":{"scheme":"redyellowgreen", "domain":[0,60]},
"type": "quantitative"
},
"y": {
"field": "Happiness",
"scale": {"domain": [0,10]},
"type": "quantitative",
"title": "Happiness"
}
}
}
Here you go:
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"data": {
"url": "https://raw.githubusercontent.com/ConorQuah/ConorQuah.github.io/main/Happiness%26liberties_s%26e.csv"
},
"title": {
"text": "Happiness and Liberty",
"subtitle": "view the happiness of different countries. Notice how the colour of the bar changes!",
"subtitleFontStyle": "italic",
"subtitleFontSize": 10,
"anchor": "start"
},
"params": [
{
"name": "p",
"select": {"type": "point", "fields": ["Country"]},
"bind": { "name": "Country",
"input": "select",
"options": [
"Pick a Country",
"Finland",
"Sweden",
"New Zealand",
"United Kingdom",
"Serbia",
"Zimbabwe",
"Afghanistan"
]
}
}
],
"height": 300,
"width": 300,
"transform": [{"filter": "datum.Country ==p_Country"}],
"mark": {"type": "bar", "width": 50},
"encoding": {
"color": {
"field": "Civil liberties",
"title": "Civil liberties",
"scale": {"scheme": "redyellowgreen", "domain": [0, 60]},
"type": "quantitative"
},
"y": {
"field": "Happiness",
"scale": {"domain": [0, 10]},
"type": "quantitative",
"title": "Happiness"
}
}
}

How to format data to algolia

I'm learning How to use Algolia and I have a few questions.
I have the table FreightDriver, which has a relationship one to many with the table Truck
id: ID!
name: String!
email: String!
phoneNumber: String!
cities: [String!]!
state: String!
country: String!
picture: String
trucks: [Truck] #connection(keyName: "byFreightDriver", fields: ["id"])
Then, the table Truck, which has a relationship one to one with the table FreightDriver, and another table, which is Box one to one as well
id: ID!
freightDriverId: ID!
boxId: ID!
brand: String!
model: String!
yearModel: Int!
// and more fields
freightDriver: FreightDriver #connection(fields: ["freightDriverId"])
box: Box #connection(fields: ["boxId"])
and the table Box:
id: ID!
type: String!
width: Float!
height: Float!
depth: Float!
I want to find trucks based on the state and city of the FreightDrivers, and also (if the user needs it), find based on the type of box and brand or model of a truck (just as an example).
Example find by state and city of a FreightDriver:
{
"data": {
"freightDriversByState": {
"items": [
{
"name": "Andrés Montoya",
"cities": [
"GUADALAJARA"
],
"state": "JALISCO",
"country": "MX",
"trucks": {
"items": [
{
"brand": "chevrolet",
"model": "12",
"yearModel": 2020,
"box": {
"type": "Ganadera",
"width": 1,
"height": 2,
"depth": 3
}
},
{
"brand": "chevrolet",
"model": "12",
"yearModel": 2020,
"box": {
"type": "Seca (abierta)",
"width": 12,
"height": 12,
"depth": 12
}
},
{
"brand": "chevrolet",
"model": "12",
"yearModel": 2020,
"box": {
"type": "Seca (abierta)",
"width": 12,
"height": 12,
"depth": 12
}
},
{
"brand": "chevrolet",
"model": "Semi",
"yearModel": 2020,
"box": {
"type": "Seca (abierta)",
"width": 1,
"height": 2,
"depth": 3
}
},
{
"brand": "chevrolet",
"model": "12",
"yearModel": 2020,
"box": {
"type": "Seca (abierta)",
"width": 1,
"height": 2,
"depth": 3
}
},
{
"brand": "chevrolet",
"model": "12",
"yearModel": 2020,
"box": {
"type": "Volcadora",
"width": 1,
"height": 2,
"depth": 3
}
},
{
"brand": "hola",
"model": "12",
"yearModel": 12,
"box": {
"type": "Plataforma",
"width": 1,
"height": 2,
"depth": 3
}
},
{
"brand": "Ford",
"model": "12",
"yearModel": 2020,
"box": {
"type": "Seca (abierta)",
"width": 1,
"height": 2,
"depth": 1
}
},
{
"brand": "dasdas",
"model": "12",
"yearModel": 12231,
"box": {
"type": "Grúa",
"width": 1,
"height": 2,
"depth": 3
}
},
{
"brand": "Tesla",
"model": "Semi",
"yearModel": 2020,
"box": {
"type": "Seca (abierta)",
"width": 4,
"height": 4,
"depth": 2
}
}
]
}
},
{
"name": "Roberto mendez",
"cities": [
"GUADALAJARA"
],
"state": "JALISCO",
"country": "MX",
"trucks": {
"items": []
}
},
{
"name": "Fletes Jalisco Sa de Cv ",
"cities": [
"GUADALAJARA"
],
"state": "JALISCO",
"country": "MX",
"trucks": {
"items": [
{
"brand": "Ford",
"model": "F-450",
"yearModel": 2018,
"box": {
"type": "Seca (cerrada)",
"width": 2.7,
"height": 2.5,
"depth": 4.5
}
},
{
"brand": "Hiundai",
"model": "H100",
"yearModel": 2009,
"box": {
"type": "Seca (abierta)",
"width": 2.3,
"height": 2,
"depth": 4
}
},
{
"brand": "Hiundai",
"model": "H100",
"yearModel": 2020,
"box": {
"type": "Seca (abierta)",
"width": 2.35,
"height": 2,
"depth": 3
}
},
{
"brand": "Ford",
"model": "F-450",
"yearModel": 2018,
"box": {
"type": "Seca (cerrada)",
"width": 2.7,
"height": 2.2,
"depth": 3
}
},
{
"brand": "Ford",
"model": "F-450",
"yearModel": 2004,
"box": {
"type": "Seca (abierta)",
"width": 2.5,
"height": 2,
"depth": 3
}
}
]
}
},
{
"name": "Cotransport",
"cities": [
"GUADALAJARA"
],
"state": "JALISCO",
"country": "MX",
"trucks": {
"items": [
{
"brand": "Chevrolet",
"model": "CX-5",
"yearModel": 2019,
"box": {
"type": "Seca (cerrada)",
"width": 4,
"height": 3,
"depth": 4
}
}
]
}
},
{
"name": "Andrés",
"cities": [
"EL LIMÓN",
"MAGDALENA",
"SANTA MARÍA DEL ORO",
"GUADALAJARA",
"ETZATLÁN"
],
"state": "JALISCO",
"country": "MX",
"trucks": {
"items": [
{
"brand": "chevrolet",
"model": "12",
"yearModel": 2020,
"box": {
"type": "Seca (abierta)",
"width": 1,
"height": 2,
"depth": 3
}
}
]
}
}
]
}
}
}
But, if I want to find using the state and city of a freight driver, the type of box and the model or brand of a truck, that's where the problem comes, because I'm using Dynamodb and this one does not have relationships, so, it's a little bit tricky to get the exact data. That's why I'd like to use Algolia, but how do I format the data for Algolia in this case? What do I need to do? thanks!
If someone is interested, here's the answer https://discourse.algolia.com/t/how-to-format-data-to-algolia/10897

Rest API returning wrong result

I was planning to migrate from the json API to the rest API, however, the results are not matching, the reverse geocode of the rest API is returning the wrong result. has anyone faced that issue before? Find sample below:
https://revgeocode.search.hereapi.com/v1/revgeocode?at=-32.05786%2C115.93382&lang=en-US&apiKey={KEY}
enter code here {
"items": [
{
"title": "Reece Australia",
"id": "here:pds:place:036qd63w-93b4e78634c7482aa36a7140fde9701b",
"resultType": "place",
"address": {
"label": "Reece Australia, Thornlie WA 6108, Australia",
"countryCode": "AUS",
"countryName": "Australia",
"state": "Western Australia",
"city": "Perth",
"district": "Thornlie",
"postalCode": "6108"
},
"position": {
"lat": -32.05779,
"lng": 115.93393
},
"access": [
{
"lat": -32.05779,
"lng": 115.93393
}
],
"distance": 13,
"categories": [
{
"id": "700-7400-0366",
"primary": true
}
]
}
]
}
https://reverse.geocoder.ls.hereapi.com/6.2/reversegeocode.json?apiKey={APIKEY}&mode=retrieveAddresses&prox=-32.05786,115.93382&maxresults=1
enter code here {
"Response": {
"MetaInfo": {
"Timestamp": "2020-06-25T05:17:32.232+0000",
"NextPageInformation": "2"
},
"View": [
{
"_type": "SearchResultsViewType",
"ViewId": 0,
"Result": [
{
"Relevance": 1.0,
"Distance": 2.1,
"MatchLevel": "street",
"MatchQuality": {
"Country": 1.0,
"State": 1.0,
"City": 1.0,
"District": 1.0,
"Street": [
1.0
],
"PostalCode": 1.0
},
"Location": {
"LocationId": "NT_K800C2SShmW5hJiQktPlsB_l_133454375_L",
"LocationType": "point",
"DisplayPosition": {
"Latitude": -32.0578752,
"Longitude": 115.9338325
},
"MapView": {
"TopLeft": {
"Latitude": -32.05782,
"Longitude": 115.9337
},
"BottomRight": {
"Latitude": -32.05798,
"Longitude": 115.9339
}
},
"Address": {
"Label": "Bannister Rd, Canning Vale WA 6155, Australia",
"Country": "AUS",
"State": "WA",
"City": "Perth",
"District": "Canning Vale",
"Street": "Bannister Rd",
"PostalCode": "6155",
"AdditionalData": [
{
"value": "Australia",
"key": "CountryName"
},
{
"value": "Western Australia",
"key": "StateName"
}
]
},
"MapReference": {
"ReferenceId": "133454375",
"Spot": 0.66,
"SideOfStreet": "neither",
"CountryId": "1469256839",
"StateId": "1469256834",
"CityId": "1469263736",
"DistrictId": "1469282231"
}
}
}
]
}
]
}
}
Result given by Rest API is correct as you are getting accurate result at that coordinate.
while in JSON API you are passing proximities with retrieveAddresses which always search for the closest street address or addresses in the given proximities.
for more details you can visit the documentations for both API.
https://developer.here.com/documentation/geocoding-search-api/api-reference-swagger.html
https://developer.here.com/documentation/geocoder/dev_guide/topics/resource-reverse-geocode.html

Highchart Pie Chart not working properly with series

Sample Code
JsFiddle Example for below code.
Highcharts.chart('container', {
chart: {
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false,
type: 'pie'
},
title: {
text: 'Browser market shares in January, 2018'
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
format: '<b>{point.name}</b>: {point.percentage:.1f} %'
}
}
},
series: [{
name: 'Brands',
colorByPoint: true,
data: [
{
"name": "Display",
"y": 0.1,
"value": 5
},
{
"name": "Paid Social",
"y": 0,
"value": 0,
sliced: true,
selected: true
},
{
"name": "Direct",
"y": 14.5,
"value": 559
},
{
"name": "Referral",
"y": 2,
"value": 77
},
{
"name": "Email",
"y": 4,
"value": 152
},
{
"name": "Other",
"y": 0,
"value": 1
},
{
"name": "Organic Search",
"y": 23.4,
"value": 901
},
{
"name": "Meta Search",
"y": 0.2,
"value": 5
},
{
"name": "Organic Social",
"y": 2.4,
"value": 93
},
{
"name": "Directory",
"y": 0.2,
"value": 9
},
{
"name": "Other Advertising",
"y": 0.1,
"value": 3
},
{
"name": "OTA Referral Traffic",
"y": 0.7,
"value": 26
},
{
"name": "Paid Search",
"y": 27.8,
"value": 1068
},
{
"name": "Local",
"y": 24.5,
"value": 941
}]
}]
});
Scenario
I want to display dataLabels for all even y value is zero.
In Above code We have "name": "Display" y=0.1 but still it is not displaying in Pie Chart don't know why. If any one have idea about this problem please let me know.
The dataLabels are hidden due to lack of space and overlapping. As a solution you can set: padding: 0
plotOptions: {
pie: {
...,
dataLabels: {
padding: 0,
...
}
}
}
Live demo: https://jsfiddle.net/BlackLabel/g5s27tyb/
API Reference: https://api.highcharts.com/highcharts/plotOptions.pie.dataLabels.padding

Here API Indoor discovery

I am trying to get the venue list using the API
https://indoor-discovery.venue.maps.api.here.com/discovery/v2?app_id=XXXXXXXXXXXXXXXXXXXX&app_code=XXXXXXXXXXXXXXXXXXXX&at=31.2403,74.6354,8.6291,77.5743
The "at" parameter almost covers the country. but the results always come back as
{
"hostname": "ip-10-13-214-44",
"type": "venues",
"status": {
"code": "OK",
"reason": "DISCOVERY_SUCCESSFULL"
},
"results": {
"items": []
}
}
The maximum value for the bounding box is at 100km x 100km. If you search within a smaller area you will get some results in the list. Here is one for the coverage of Chennai:
https://indoor-discovery.venue.maps.api.here.com/discovery/v2?app_id=yyy&app_code=xxxx&at=13.2403,79.8454,12.7291,80.5743
{
"hostname": "ip-10-13-214-44",
"type": "venues",
"status": {
"code": "OK",
"reason": "DISCOVERY_SUCCESSFULL"
},
"results": {
"items": [
{
"id": "DM_17331",
"title": "Phoenix Marketcity Mall",
"address": {
"countryCode": "IND",
"city": "Chennai",
"postalCode": "600042",
"street": "Radha Mohan Street",
"house": ""
},
"position": [
12.991487949990416,
80.21652530007341
],
"distance": 1045.380777404391,
"type": "urn:nlp-types:venue",
"vicinity": "Radha Mohan Street,600042,Chennai,IND",
"bbox": [
[
12.992687434189028,
80.21572801724027
],
[
12.990288596080005,
80.21732267846822
]
],
"minFloor": -1,
"maxFloor": 3,
"namespace": "public"
},
{
"id": "DM_3869",
"title": "Maya Plaza",
"address": {
"countryCode": "IND",
"city": "Chennai",
"postalCode": "600017",
"street": "Sir Thyagaraya Road",
"house": ""
},
"position": [
13.041404800089397,
80.23480899848522
],
"distance": 6860.646286724997,
"type": "urn:nlp-types:venue",
"vicinity": "Sir Thyagaraya Road,600017,Chennai,IND",
"bbox": [
[
13.041557002816027,
80.23472596161558
],
[
13.04125261448761,
80.23489217568006
]
],
"minFloor": 0,
"maxFloor": 4,
"namespace": "public"
},
{
"id": "DM_3866",
"title": "Challa Mall",
"address": {
"countryCode": "IND",
"city": "Chennai",
"postalCode": "600017",
"street": "Sir Thyagaraya Road",
"house": ""
},
"position": [
13.040501949969517,
80.24325910031074
],
"distance": 7183.4301593814025,
"type": "urn:nlp-types:venue",
"vicinity": "Sir Thyagaraya Road,600017,Chennai,IND",
"bbox": [
[
13.040704496188196,
80.24306093132118
],
[
13.040299554031115,
80.24345735684514
]
],
"minFloor": -1,
"maxFloor": 1,
"namespace": "public"
},
{
"id": "DM_3871",
"title": "Kasi Arcade Mall",
"address": {
"countryCode": "IND",
"city": "Chennai",
"postalCode": "600017",
"street": "Sir Thyagaraya Road",
"house": ""
},
"position": [
13.040300249964666,
80.24435859999508
],
"distance": 7224.9813794400025,
"type": "urn:nlp-types:venue",
"vicinity": "Sir Thyagaraya Road,600017,Chennai,IND",
"bbox": [
[
13.040532567087016,
80.24415738929856
],
[
13.04006805606027,
80.24455999517599
]
],
"minFloor": -1,
"maxFloor": 1,
"namespace": "public"
},
I had copied the lat/long from google maps, then I realized that the longitude has space, in the beginning, I removed the space and it started to work!

Resources