amcharts not rendering India map correctly in worldmap - amcharts

While amcharts shows the India map correctly (showing the disputed regions as part of India) when displaying only India (http://jsfiddle.net/zxhseguw/5/)
"dataProvider": {
"map": "indiaLow",
"areas": [ {
"id": "IN-KA",
"value": 4447100,
}, {
"id": "IN-UP",
"value": 38763
}]
},
it shades it differently when rendering it on world map (http://jsfiddle.net/zxhseguw/6/)
"dataProvider": {
"map": "worldLow",
"areas": [ {
"id": "IN",
"value": 4447100,
}, {
"id": "AU",
"value": 387633
}]
},
I wonder, if there is a way to make it render India correctly, just like its possible in Google Charts by setting origin='India'

I'm assuming you're referring to the region around Kashmir, correct? Try using worldIndiaLow instead of worldLow, which includes more of that disputed area as part of India.
"dataProvider": {
"map": "worldIndiaLow",
"areas": [ {
"id": "IN",
"value": 4447100,
}, {
"id": "AU",
"value": 387633
}]
},
Updated fiddle

Related

Turn a JSON array of key/value pairs into object properties

I'm trying to use JSONata to convert arrays of "key/value" objects into properties of the parent object. My input looks like this:
[
{
"city": "Ottawa",
"properties": [
{
"name": "population",
"value": 37
},
{
"name": "postalCode",
"value": 10001
},
{
"name": "founded",
"value": 1826
}
]
},
{
"city": "Toronto",
"properties": [
{
"name": "population",
"value": 54
},
{
"name": "postalCode",
"value": 10002
}
]
}
]
I'm struggling to generate the output I need, I've seen examples that reference explicit elements, like in this answer, but I need the properties to be converted "dynamically" since I don't know them in advance. I think I need something like this, but I'm missing some particular function:
$[].{
"city": city,
properties.name: properties.value
}
This is the output I need to generate:
[
{
"city": "Ottawa",
"population": 37,
"postalCode": 10001,
"founded": 1826
},
{
"city": "Toronto",
"population": 54,
"postalCode": 10002
}
]
The properties arrays don't always contain the same keys, but the city attributes are always present.
You can use the reduce operator, as described in the Grouping docs here:
$[].(
$city := city;
properties{ "city": $city, name: value }
)
You can play with it live: https://stedi.link/uUANwtE
Please try this expression.
$[].{
"city": $.city,
$.properties[0].name: $.properties[0].value,
$.properties[1].name: $.properties[1].value,
$.properties[2].name: $.properties[2].value,
$.properties[3].name: $.properties[3].value
}
https://try.jsonata.org/s1Ea4kUvo

Retrieve name of leaf(box) of amchart4 treeMap

I followed the question here Retrieving object from TreeMap but I am unable to get the name out of it like for in
chart.data = [{
"name": "First",
"value": 190
}, {
"name": "Second",
"value": 289
}, {
"name": "Third",
"value": 635
}, {
"name": "Fourth",
"value": 732
}, {
"name": "Fifth",
"value": 835
}]
I want to get name like First, Second and so on. on hit event how do I do that?
Ok so it was bit deeper than I thought:
var series = chart.seriesTemplates.create("0");
series.columns.template.events.on('hit', function(ev) {
console.log(ev.target.dataItem.dataContext.dataContext.name);
});
instead of
console.log(ev.target.dataItem)

amcharts 4 category X axis labels not aligned with graphed data

Using rotated labels on category X axis. (Real graph uses long names but results are the same.)
A: Alignment of axis labels and their data points is fine without label rotation.
B: Labels are not aligned when rotated.
The only difference between A and B graph coding is the addition of "labels":{"rotation":90} in the xAxes renderer.
How can alignment be fixed?
var chart =am4core.createFromConfig({
"colors": { "list": ["#DB3", "#000", "#888"] },
"data": [$data],
"legend": { "markers":{"width":20, "height":10},
"position":"top",
"useDefaultMarker":true
},
"series": [
{ "dataFields": { "categoryX":"X", "valueY":"Y1" },
"name": "[font-size:16px;font-weight:600;]{$n1}[/]",
"strokeWidth": 2,
"type": "LineSeries"
},
{ "dataFields": { "categoryX":"X", "valueY":"Y2" },
"name": "[font-size:16px;font-weight:600;]{$n2}[/]",
"strokeWidth": 2,
"type": "LineSeries"
},
{ "dataFields": { "categoryX":"X", "valueY":"Y3" },
"name": "[font-size:16px;font-weight:600;]others[/]",
"strokeWidth": 2,
"type": "LineSeries"
}
],
"xAxes": [
{ "dataFields": { "category": "X" },
"renderer": { "minGridDistance":11, "labels":{"rotation":90}},
"type": "CategoryAxis"
}
],
"yAxes": [
{ "renderer": {"minGridDistance":15},
"title": {"text": "[font-size:16px;font-weight:600;]Values[/]"},
"type": "ValueAxis"
}]
}, "line", am4charts.XYChart);
LABELS renderer needed "verticalCenter":"middle" with rotation.
I don't know how many other things I tried!

Custom colors when generating a pie chart from JSON

I'm trying to create a pie chart with a custom set of colours using Am4Charts and the createFromConfig method.
I've followed the tutorial here but the chart keeps appearing with it's default color set.
Here is a sample of the JSON I've tried:
"innerRadius": 100,
"colors": {"list": ["#ff0000", "#00ff00", "#0000ff" ]},
"data": {
"0": {
"pot": "Within 8 days",
"value": "£111,119.70",
},
"1": {
"pot": "9 - 17 days",
"value": "£225,537.73"
},
"2": {
"pot": "18+ days",
"value": "£720,279.85"
}
},
"legend": [],
"xAxes": [
{
"type": "CategoryAxis",
"title": {
"text": "pot"
},
"dataFields": {
"category": "pot",
"title": {
"text": "Month"
}
},
"renderer": {
"labels": {
"rotation": 190,
"verticalCenter": "middle",
"horizontalCenter": "left"
}
}
}
],
"series": [
{
"type": "PieSeries",
"dataFields": {
"value": "value",
"category": "pot"
},
"ticks": {
"disabled": true
},
"labels": {
"disabled": true
},
}
],
Can somebody see where I've gone wrong?
Update 2:
Fixed in 4.0.0-beta.85.
Make sure you clear your browser cache after upgrading. And feel free to contact us again if you are still experiencing this issue.
Update 1:
Response from amchart contributor/CTO Martynas Majeris (https://github.com/martynasma):
Looks like there are two issues: documentation is wrong and there's a bug that prevents it from working :)
I updated the docs. It should say this:
{
// ...
"series": [{
// ...
"colors": {
"list": [
"#845EC2",
"#D65DB1",
"#FF6F91",
"#FF9671",
"#FFC75F",
"#F9F871"
]
}
}]
}
Also, fixed bug in dev version. New version will be released within 1-2 days.
Original
This might be a bug and I have opened an issue on amchart github. I will update this once I get a response: https://github.com/amcharts/amcharts4/issues/577
By the way, I do think your configuration JSON has couple issues:
data is an array, not an object
legend is an object, not an array
This is what I used to create the pie chart demo for the opened issue:
// Create chart instance in one go
let chart = am4core.createFromConfig({
"colors": {
"list": ["#ff0000","#00ff00", "#0000ff"]
},
// Create pie series
"series": [{
"colors": ["#ff0000","#00ff00", "#0000ff"],
"type": "PieSeries",
"dataFields": {
"value": "value",
"category": "pot"
}
}],
// Add data
"data": [{
"pot": "Within 8 days",
"value": "£111,119.70"
}, {
"pot": "9 - 17 days",
"value": "£225,537.73"
}, {
"pot": "18+ days",
"value": "£720,279.85"
}],
// Add legend
"legend": {},
"innerRadius": 100
}, "chart", am4charts.PieChart);

Create Products using Rest API : Magento V2.0

I have been trying to create a product using Rest API for Magento Version 2.0.
I am using Postman to test the rest api.
URL : http://13.91../rest/V1/products
I have added the following headers to the request.
Authorization : Bearer **********************
Content-Type : application/json
JSON BODY
{
"sku":"10090-White-XL",
"store_view_code":"",
"attribute_set_code":"ColorSize",
"product_type":"virtual",
"categories":"Menswear/Tops",
"product_websites":"base",
"name":"10090-White-XL",
"description":"<p>Precise Long-Sleeve Shirt in Black, Denim, or White.</p>",
"short_description":"",
"weight":"",
"product_online":1,
"tax_class_name":"Taxable Goods",
"visibility":"Not Visible Individually",
"price":119,
"special_price":"",
"special_price_from_date":"",
"special_price_to_date":"",
"url_key":"10090-white-xl",
"meta_title":"Precise Long-Sleeve Shirt",
"meta_keywords":"Precise Long-Sleeve Shirt",
"meta_description":"Precise Long-Sleeve Shirt <p>Precise Long-Sleeve Shirt in Black, Denim, or White.</p>",
"base_image":"",
"base_image_label":"",
"small_image":"",
"small_image_label":"",
"thumbnail_image":"",
"thumbnail_image_label":"",
"swatch_image":"",
"swatch_image_label":"",
"created_at":"3/23/16, 2:15 PM",
"updated_at":"3/23/16, 2:15 PM",
"new_from_date":"",
"new_to_date":"",
"display_product_options_in":"Block after Info Column",
"map_price":"",
"msrp_price":"",
"map_enabled":"",
"gift_message_available":"",
"custom_design":"",
"custom_design_from":"",
"custom_design_to":"",
"custom_layout_update":"",
"page_layout":"",
"product_options_container":"",
"msrp_display_actual_price_type":"",
"country_of_manufacture":"",
"additional_attributes":"color=White,size=XL",
"qty":null,
"out_of_stock_qty":0,
"use_config_min_qty":1,
"is_qty_decimal":0,
"allow_backorders":0,
"use_config_backorders":1,
"min_cart_qty":1,
"use_config_min_sale_qty":1,
"max_cart_qty":10000,
"use_config_max_sale_qty":1,
"is_in_stock":0,
"notify_on_stock_below":1,
"use_config_notify_stock_qty":1,
"manage_stock":0,
"use_config_manage_stock":0,
"use_config_qty_increments":1,
"qty_increments":0,
"use_config_enable_qty_inc":0,
"enable_qty_increments":0,
"is_decimal_divided":0,
"website_id":1,
"related_skus":"",
"crosssell_skus":"",
"upsell_skus":"",
"additional_images":"",
"additional_image_labels":"",
"hide_from_product_page":"",
"bundle_price_type":"",
"bundle_sku_type":"",
"bundle_price_view":"",
"bundle_weight_type":"",
"bundle_values":"",
"configurable_variations":"",
"configurable_variation_labels":"",
"associated_skus":""
}
The error that I get is {"message":"%fieldName is a required field.","parameters":{"fieldName":"product"}}
It will be great if someone could let me know how I could add a product. I have checked all the documents and but could not find an answer.
I have found the answer to my question. The json structure need to be in this format:
{
"product":{
"id": 12345,
"sku": "10090-White-XL",
"name": "10090-White-XL",
"attribute_set_id": 9,
"price": 119,
"status": 1,
"visibility": 1,
"type_id": "virtual",
"created_at": "2016-04-05 23:04:09",
"updated_at": "2016-04-05 23:04:09",
"product_links": [],
"options": [],
"tier_prices": [],
"custom_attributes": [
{
"attribute_code": "description",
"value": "<p>Precise Long-Sleeve Shirt in Black, Denim, or White.</p>"
},
{
"attribute_code": "meta_title",
"value": "Precise Long-Sleeve Shirt"
},
{
"attribute_code": "meta_keyword",
"value": "Precise Long-Sleeve Shirt"
},
{
"attribute_code": "meta_description",
"value": "Precise Long-Sleeve Shirt <p>Precise Long-Sleeve Shirt in Black, Denim, or White.</p>"
},
{
"attribute_code": "color",
"value": "11"
},
{
"attribute_code": "options_container",
"value": "container2"
},
{
"attribute_code": "required_options",
"value": "0"
},
{
"attribute_code": "has_options",
"value": "0"
},
{
"attribute_code": "url_key",
"value": "10090-white-xl"
},
{
"attribute_code": "msrp_display_actual_price_type",
"value": "0"
},
{
"attribute_code": "tax_class_id",
"value": "2"
},
{
"attribute_code": "size",
"value": "8"
}
]
},"saveOptions": true
}
The important thing to note is the product tag in the json.The swagger document help to idenity it. Here is the link to it: http://devdocs.magento.com/swagger/#!/catalogProductRepositoryV1/catalogProductRepositoryV1SavePost
Simple product with custom attributes (ex: remarks).
Just take note of the media_gallery_entries. Make sure to supply a valid base64_encoded_data image content and mime type.
URL: http://domain/index.php/rest/V1/products
METHOD: POST
HEADER:
application/json
Authorization: Bearer
POST DATA / RAW PAYLOAD:
{
"product": {
"sku": "TESTPRD002",
"name": "Women's Running - Pure Boost X Shoes",
"attribute_set_id": 4,
"price": 84,
"status": 1,
"visibility": 4,
"type_id": "simple",
"created_at": "2016-12-16 15:20:55",
"updated_at": "2016-12-16 15:20:23",
"weight": 2.5,
"extension_attributes": {
"stock_item": {
"item_id": 1,
"stock_id": 1,
"qty": 20,
"is_in_stock": true,
"is_qty_decimal": false
}
},
"product_links": [],
"options": [],
"media_gallery_entries": [
{
"media_type": "image",
"label": "Women's Running - Pure Boost X Shoes",
"position": 1,
"disabled": false,
"types": [
"image",
"small_image",
"thumbnail"
],
"content": {
"base64_encoded_data": "<ENCODED IMAGE DATA>",
"type": "image/jpeg",
"name": "TESTPRD002-01.jpg"
}
}
],
"tier_prices": [],
"custom_attributes": [
{
"attribute_code": "description",
"value": "<p>Lightweight and sleek, these women's running shoes are fueled by boost™ energy. The low-profile runners blend an energy-returning boost™ midsole with a STRETCHWEB outsole for a cushioned ride with terrific ground-feel. They feature a breathable mesh upper with a sock-like fit that offers all-around support. With a full boost™ midsole that keeps every stride charged with light, fast energy, the shoe has an upper that hovers over a free-floating arch.</p>"
},
{
"attribute_code": "short_description",
"value": "<p>PURE BOOST X SHOES</p><p>NATURAL RUNNING SHOES WITH ARCH SUPPORT.</p>"
},
{
"attribute_code": "meta_title",
"value": "PURE BOOST X SHOES"
},
{
"attribute_code": "meta_keyword",
"value": "boost X, running, shoes, adidas"
},
{
"attribute_code": "meta_description",
"value": "NATURAL RUNNING SHOES WITH ARCH SUPPORT."
},
{
"attribute_code": "category_ids",
"value": [
"2", "3"
]
},
{
"attribute_code": "url_key",
"value": "womens-running-pure-boost-x-shoes"
},
{
"attribute_code": "tax_class_id",
"value": "1"
},
{
"attribute_code": "remarks",
"value": "Lorem ipsum.."
}
]
},
"saveOptions": true
}

Resources