Related
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 am fetching data like this
Future<List> dosomestuff() async {
http.Response res = await http.get(
'http://retailapi.airtechsolutions.pk/api/menu/2112',
);
Map<String, dynamic> map = json.decode(res.body);
print(map);
}
Its showing data like this
{
"Categories": [{
"ID": 1064,
"Name": "Pizza",
"Subcategories": [{
"ID": 87,
"CategoryID": 1064,
"CategoryName": "Pizza",
"Items": [{
"ID": 1195,
"Name": "Fajita Pizza (S)"
},
{
"ID": 1196,
"Name": "Fajita Pizza (M)"
},
{
"ID": 1197,
"Name": "Fajita Pizza (L)"
}
]
},
{
"ID": 87,
"CategoryID": 1064,
"CategoryName": "Pizza",
"Items": [{
"ID": 1195,
"Name": "Fajita Pizza (S)"
},
{
"ID": 1196,
"Name": "Fajita Pizza (M)"
},
{
"ID": 1197,
"Name": "Fajita Pizza (L)"
}
]
}
]
},
{
"ID": 1064,
"Name": "Pizza",
"Subcategories": [{
"ID": 87,
"CategoryID": 1064,
"CategoryName": "Pizza",
"Items": [{
"ID": 1195,
"Name": "Fajita Pizza (S)"
},
{
"ID": 1196,
"Name": "Fajita Pizza (M)"
},
{
"ID": 1197,
"Name": "Fajita Pizza (L)"
}
]
}]
},
{
"ID": 1084,
"Name": "beverages",
"Description": null,
"Image": null,
"StatusID": 1,
"LocationID": 2112,
"Subcategories": []
}
],
"description": "Success",
"status": 1
}
What i need to do know is show items of all arrays. Mean in above data there are 2 arrays in subcategories and in 1 array there are 3 items. I need to merge all items of array 1 and 2 so it can total 6.
Expecting output
{ "Items": [
{
"ID": 1195,
"SubCategoryID": 87,
"Name": "Fajita Pizza (S)",
},
{
"ID": 1196,
"SubCategoryID": 87,
"Name": "Fajita Pizza (M)",
},
{
"ID": 1197,
"SubCategoryID": 87,
"Name": "Fajita Pizza (L)",
},
{
"ID": 1195,
"SubCategoryID": 87,
"Name": "Fajita Pizza (S)",
},
{
"ID": 1196,
"SubCategoryID": 87,
"Name": "Fajita Pizza (M)",
},
{
"ID": 1197,
"SubCategoryID": 87,
"Name": "Fajita Pizza (L)",
}
]
}
I don't know if I understand what you want to do but you can try the addAll function
fetchedList = [a, b, 2, 3];
myList = [4, 5, c];
fetchedList.addAll(myList);
print(fetchedList);
// [a, b, 2, 3, 4, 5, c]
hope these steps help you:
Create a new empty map
Loop in your map data['Categories']['Subcategories']
Put each element in your new map
You can use forEach to split the json data layer by layer
var items = {'Items':[]};
if(map['Categories'] != null){
map['Categories'].forEach((category){
if(category['Subcategories'] != null){
category['Subcategories'].forEach((subcategory){
items['Items'].addAll(subcategory['Items']);
});
}
});
}
print(items);
dynamic data = {
"Categories": [
{
"ID": 1064,
"Name": "Pizza",
"Subcategories": [
{
"ID": 87,
"CategoryID": 1064,
"CategoryName": "Pizza",
"Items": [
{"ID": 1195, "Name": "Fajita Pizza (S)"},
{"ID": 1196, "Name": "Fajita Pizza (M)"},
{"ID": 1197, "Name": "Fajita Pizza (L)"}
]
},
{
"ID": 87,
"CategoryID": 1064,
"CategoryName": "Pizza",
"Items": [
{"ID": 1195, "Name": "Fajita Pizza (S)"},
{"ID": 1196, "Name": "Fajita Pizza (M)"},
{"ID": 1197, "Name": "Fajita Pizza (L)"}
]
}
]
},
{
"ID": 1064,
"Name": "Pizza",
"Subcategories": [
{
"ID": 87,
"CategoryID": 1064,
"CategoryName": "Pizza",
"Items": [
{"ID": 1195, "Name": "Fajita Pizza (S)"},
{"ID": 1196, "Name": "Fajita Pizza (M)"},
{"ID": 1197, "Name": "Fajita Pizza (L)"}
]
}
]
},
{
"ID": 1084,
"Name": "beverages",
"Description": null,
"Image": null,
"StatusID": 1,
"LocationID": 2112,
"Subcategories": []
},
null
],
"description": "Success",
"status": 1
};
var items = List();
var categories = data["Categories"];
categories.forEach((element) {
if (element == null) return;
List subCategories = element['Subcategories'];
subCategories.forEach((element) {
items.add(element["Items"]);
});
});
items = items.expand((element) => element).toList();
print(items);
Having the following record
{
"name": "
Festões Plástico, 12mt x 17cm - Festas Populares",
"categories": [
"Festas",
"Casamentos",
"Decorações"
],
"hierarchicalCategories": {
"lvl0": "Festas",
"lvl1": "Festas > Casamentos",
"lvl2": "Festas > Casamentos > Decorações"
},
"description": "",
"brand": "Misterius",
"price": 14.94,
"stock": "Disponível",
"prices": [
{
"value": 12,
"type": "specificValue",
"family": "fatos",
"subfamily": "example"
},
{
"value": 13,
"type": "specificValue13",
"family": "fatos13",
"subfamily": "example13"
},
{
"value": 14,
"type": "specificValue14",
"family": "fatos14",
"subfamily": "example14"
},
{
"value": 15,
"type": "specificValue15",
"family": "fatos15",
"subfamily": "example15"
},
{
"value": 16,
"type": "specificValue16",
"family": "fatos16",
"subfamily": "example16"
}
],
"color": [
{
"name": "Amarelo",
"label": "Amarelo,#FFFF00",
"hexa": "#FFFF00"
},
{
"name": "Azul",
"label": "Azul,#0000FF",
"hexa": "#0000FF"
},
{
"name": "Branco",
"label": "Branco,#FFFFFF",
"hexa": "#FFFFFF"
},
{
"name": "Laranja",
"label": "Laranja,#FFA500",
"hexa": "#FFA500"
},
{
"name": "Verde Escuro",
"label": "Verde Escuro,#006400",
"hexa": "#006400"
},
{
"name": "Vermelho",
"label": "Vermelho,#FF0000",
"hexa": "#FF0000"
}
],
"specialcategorie": "",
"reference": "3546",
"rating": 0,
"free_shipping": false,
"popularity": 0,
"objectID": "30"
}
Now by searching for "Festas Populares" will return the record and its attributes, is it possible to also filter for one attribute array as "prices" to only return one json. for example "prices.type"="specificValue14" and "family"="fatos14" and "family"="fatos" and "subfamily"="example"
{
“value”: 14,
“type”: “specificValue14”,
“family”: “fatos14”,
“subfamily”: “example14”
}
the record return would be:
{
"name": "
Festões Plástico, 12mt x 17cm - Festas Populares",
"categories": [
"Festas",
"Casamentos",
"Decorações"
],
"hierarchicalCategories": {
"lvl0": "Festas",
"lvl1": "Festas > Casamentos",
"lvl2": "Festas > Casamentos > Decorações"
},
"description": "",
"brand": "Misterius",
"price": 14.94,
"stock": "Disponível",
"prices": [
{
"value": 14,
"type": "specificValue14",
"family": "fatos14",
"subfamily": "example14"
}
],
"color": [
{
"name": "Amarelo",
"label": "Amarelo,#FFFF00",
"hexa": "#FFFF00"
},
{
"name": "Azul",
"label": "Azul,#0000FF",
"hexa": "#0000FF"
},
{
"name": "Branco",
"label": "Branco,#FFFFFF",
"hexa": "#FFFFFF"
},
{
"name": "Laranja",
"label": "Laranja,#FFA500",
"hexa": "#FFA500"
},
{
"name": "Verde Escuro",
"label": "Verde Escuro,#006400",
"hexa": "#006400"
},
{
"name": "Vermelho",
"label": "Vermelho,#FF0000",
"hexa": "#FF0000"
}
],
"specialcategorie": "",
"reference": "3546",
"rating": 0,
"free_shipping": false,
"popularity": 0,
"objectID": "30"
}
for some context a product can have multiple prices associated, for a specific user, or one day there is campaign giving discount, etc so for that cases want to filter price associated to the product/record.
No, this is not possible with Algolia. Records are always returned with the attributes specified inside attributesToRetrieve. These attributes are returned in full.
I have an implementation of a chart where the legend must be in top for screen size reasons. My customer complains that it is hard to see the (in this case) two series titles.
Currently it shows like this:
[] series title 1 [] series title 2
I want:
[] series title 1
[] series title 2
setting legend.position = "right" shows them like I want, but on the side, so it must be set to "top"
Any way to achieve this?
Look here http://plnkr.co/edit/BVPb4AivJuks5VGr6FGz?p=preview
Chart is configured like this:
{
"chartArea": {
"font": "14px/1.714 \"roboto\", \"Arial\", \"Helvetica\", sans-serif",
"width": 1000,
"height": 333.3333333333333,
"background": "",
"border": {
"color": ""
}
},
"title": {
"text": "",
"font": "14px/1.714 \"roboto\", \"Arial\", \"Helvetica\", sans-serif"
},
"legend": {
"position": "top"
},
"seriesDefaults": {
"markers": {
"visible": false
}
},
"series": [
{
"type": "column",
"name": "03-02-2016",
"data": [
0.110845970287301,
0.0914614304545012,
0.0828538550058511,
0.0828538550056237,
0.0897167892449033,
0.178615728107161,
0.178615728107161,
0.178615728107161,
0.178615728107161,
0.0727362937236649,
0,
0
],
"color": "#8f9b49"
},
{
"type": "line",
"name": "02-02-2016 (perioden før!)",
"data": [
0.110709412367669,
0.0911219388724476,
0.0911219388722202,
0.0911219388724476,
0.0911219388722202,
0.0235651458583561,
0.140159626241029,
0.140159626241029,
0.140159626241029,
0.075608331711237,
0.899526564965754,
0.899526564965754,
0.899526564965754,
0.687138348237795,
0.431259248819742,
0.431259248819742,
0.431259248819515,
0.400167587908072,
0.325565217391159,
0.325565217391386,
0.325565217391159,
0.260910866318909,
0.110845970287073,
0.110845970287073
],
"color": "#bdc779",
"border": {
"width": 1,
"color": "#dddddd"
}
}
],
"valueAxis": {
"plotBands": [],
"title": {
"text": "kWh",
"background": "none",
"font": "14px/1.714 \"roboto\", \"Arial\", \"Helvetica\", sans-serif"
},
"labels": {
"format": "{0}",
"font": "12px/1.714 \"roboto\", \"Arial\", \"Helvetica\", sans-serif"
},
"line": {
"visible": false
},
"axisCrossingValue": 0
},
"categoryAxis": {
"majorGridLines": {
"width": 0
},
"title": {
"text": "Time",
"background": "none",
"font": "14px/1.714 \"roboto\", \"Arial\", \"Helvetica\", sans-serif"
},
"categories": [
"00",
"01",
"02",
"03",
"04",
"05",
"06",
"07",
"08",
"09",
"10",
"11",
"12",
"13",
"14",
"15",
"16",
"17",
"18",
"19",
"20",
"21",
"22",
"23"
],
"line": {
"visible": false
},
"labels": {
"padding": {
"top": 4
},
"font": "12px/1.714 \"roboto\", \"Arial\", \"Helvetica\", sans-serif"
}
},
"tooltip": {
"visible": true,
"format": "{0}m2",
"template": "#= series.name # #= category #: #= value #"
}
}
Set the legend orientation to vertical and then set the height as needed:
legend: {
position: "top",
orientation: "vertical",
height: 50
},
How can I replace the color in the pie chart?
Please find my code below :
AmCharts.makeChart("pie-diagramm", {
"type": "pie",
"theme": "none",
"dataProvider": [{
"title": "Интернэшнл",
"value": 100
}, {
"title": "Казахстан",
"value": 90
},{
"title": "Лтд",
"value": 100
},
{
"title": "Лимитед",
"value": 400},
{
"title": "компания",
"value": 400},
{
"title": "ЛУКАРКО",
"value": 600},{
"title": "Компани",
"value": 700
},
{
"title": "«КазМунайГаз»",
"value": 900},{
"title": "КТК",
"value": 350},
{
"title": "Федерация",
"value": 1300},
{
"title": "Пайплайн",
"value": 90}
],
"titleField": "title",
"valueField": "value",
"labelRadius": 5,
"fontSize": 16,
"radius": "25%",
"innerRadius": "30%",
"labelText": "[[title]]",
"exportConfig": {
"menuItems": [{
"icon": '/lib/3/images/export.png',
"format": 'png'
}]
}
});
Thanks!
add color attribute in your DataProvider
dataProvider": [{
"title": "Интернэшнл",
"value": 100,
"color": "your choice of color"
}, {
"title": "Казахстан",
"value": 90,
"color": "your choice of color"
}
http://docs.amcharts.com/3/javascriptcharts/AmPieChart,
http://docs.amcharts.com/3/javascriptcharts/Slice
the dataprovider holds the property of each slice in pie chart
chart.chartData = dataProvider;
The best and most simple way to do this would be setting background-color style of your chart's container div. Or you can set chart.backgroundColor="#FF0000"; and chart.backgroundAlpha to some bigger than 0 value.