Adding labels for the last level in fusioncharts multilevel pie - javascript
I am trying to generate a labels for the last level of the category...
This is the one I am looking for...
Created JsFiddle for you
var Cdata={"data":[{"label":"2010","value":"702600","color":"#FF8B3C","category":[{"label":"Public","value":"340394","color":"#FF8B3C","category":[{"label":"Single","value":"91787","color":"#FF8B3C","category":null},{"label":"Married","value":"85787","color":"#FF8B3C","category":null},{"label":"Divorced","value":"77464","color":"#FF8B3C","category":null},{"label":"Widow","value":"85356","color":"#FF8B3C","category":null}]},{"label":"Private","value":"362206","color":"#FF8B3C","category":[{"label":"Single","value":"102443","color":"#FF8B3C","category":null},{"label":"Married","value":"77220","color":"#FF8B3C","category":null},{"label":"Divorced","value":"85393","color":"#FF8B3C","category":null},{"label":"Widow","value":"97150","color":"#FF8B3C","category":null}]}]},{"label":"2011","value":"746880","color":"#A5AC0F","category":[{"label":"Public","value":"358315","color":"#A5AC0F","category":[{"label":"Single","value":"86968","color":"#A5AC0F","category":null},{"label":"Married","value":"92456","color":"#A5AC0F","category":null},{"label":"Divorced","value":"83679","color":"#A5AC0F","category":null},{"label":"Widow","value":"95212","color":"#A5AC0F","category":null}]},{"label":"Private","value":"388565","color":"#A5AC0F","category":[{"label":"Single","value":"100185","color":"#A5AC0F","category":null},{"label":"Married","value":"94838","color":"#A5AC0F","category":null},{"label":"Divorced","value":"96399","color":"#A5AC0F","category":null},{"label":"Widow","value":"97143","color":"#A5AC0F","category":null}]}]},{"label":"2012","value":"789482","color":"#83E0FF","category":[{"label":"Public","value":"383454","color":"#83E0FF","category":[{"label":"Single","value":"104390","color":"#83E0FF","category":null},{"label":"Married","value":"89375","color":"#83E0FF","category":null},{"label":"Divorced","value":"96117","color":"#83E0FF","category":null},{"label":"Widow","value":"93572","color":"#83E0FF","category":null}]},{"label":"Private","value":"406028","color":"#83E0FF","category":[{"label":"Single","value":"99938","color":"#83E0FF","category":null},{"label":"Married","value":"93399","color":"#83E0FF","category":null},{"label":"Divorced","value":"115378","color":"#83E0FF","category":null},{"label":"Widow","value":"97313","color":"#83E0FF","category":null}]}]},{"label":"2013","value":"705560","color":"#ff9999","category":[{"label":"Public","value":"354781","color":"#ff9999","category":[{"label":"Single","value":"98333","color":"#ff9999","category":null},{"label":"Married","value":"87342","color":"#ff9999","category":null},{"label":"Divorced","value":"77118","color":"#ff9999","category":null},{"label":"Widow","value":"91988","color":"#ff9999","category":null}]},{"label":"Private","value":"350779","color":"#ff9999","category":[{"label":"Single","value":"102129","color":"#ff9999","category":null},{"label":"Married","value":"79801","color":"#ff9999","category":null},{"label":"Divorced","value":"81731","color":"#ff9999","category":null},{"label":"Widow","value":"87118","color":"#ff9999","category":null}]}]},{"label":"2014","value":"738714","color":"#e580ff","category":[{"label":"Public","value":"350028","color":"#e580ff","category":[{"label":"Single","value":"69093","color":"#e580ff","category":null},{"label":"Married","value":"100824","color":"#e580ff","category":null},{"label":"Divorced","value":"89057","color":"#e580ff","category":null},{"label":"Widow","value":"91054","color":"#e580ff","category":null}]},{"label":"Private","value":"388686","color":"#e580ff","category":[{"label":"Single","value":"92575","color":"#e580ff","category":null},{"label":"Married","value":"105411","color":"#e580ff","category":null},{"label":"Divorced","value":"86773","color":"#e580ff","category":null},{"label":"Widow","value":"103927","color":"#e580ff","category":null}]}]},{"label":"2015","value":"726130","color":"#9999ff","category":[{"label":"Public","value":"348346","color":"#9999ff","category":[{"label":"Single","value":"84893","color":"#9999ff","category":null},{"label":"Married","value":"92005","color":"#9999ff","category":null},{"label":"Divorced","value":"81349","color":"#9999ff","category":null},{"label":"Widow","value":"90099","color":"#9999ff","category":null}]},{"label":"Private","value":"377784","color":"#9999ff","category":[{"label":"Single","value":"88107","color":"#9999ff","category":null},{"label":"Married","value":"94300","color":"#9999ff","category":null},{"label":"Divorced","value":"101897","color":"#9999ff","category":null},{"label":"Widow","value":"93480","color":"#9999ff","category":null}]}]}]};
FusionCharts.ready(function () {
var topProductsChart = new FusionCharts({
type: 'multilevelpie',
renderAt: 'chart-container',
id : "myChart",
width: '500',
height: '500',
dataFormat: 'json',
dataSource: {
"chart": {
"caption": "Split of Top Products Sold",
"subCaption": "Last Quarter",
"captionFontSize": "14",
"subcaptionFontSize": "14",
"baseFontColor" : "#333333",
"baseFont" : "Helvetica Neue,Arial",
"basefontsize": "9",
"subcaptionFontBold": "0",
"bgColor" : "#ffffff",
"canvasBgColor" : "#ffffff",
"showBorder" : "0",
"showShadow" : "0",
"showCanvasBorder": "0",
"pieFillAlpha": "60",
"pieBorderThickness": "2",
"hoverFillColor": "#cccccc",
"pieBorderColor": "#ffffff",
"useHoverColor": "1",
"showValuesInTooltip": "1",
"showPercentInTooltip": "0",
"numberPrefix": "$",
"plotTooltext": "$label, $$valueK, $percentValue"
},
"category": Cdata.data
}
});
topProductsChart.render();
});
Suggest us how can we draw the lines for the last level.
You can use annotation feature provided by FusionCharts to draw lines for outer-ring and and add label values. Check out this link to know more about annotations.
You can check implementation example in this updated JSFiddle.
Here's code used for annotations in above JSFiddle:
"annotations": {
"groups": [{
"items": [{
"id": "line1",
"type": "line",
"x": "$chartCenterX + 205",
"y": "$chartCenterY - 50",
"toX": "$chartCenterX + 240",
"toY": "$chartCenterY - 80",
},
{
"id": "linelabel1",
"type": "text",
"x": "$chartCenterX + 245",
"y": "$chartCenterY - 88",
"text": "22.76%",
"fontSize": "11"
}
]
}]
}
Related
Get id from tr created using js-grid, property path changes every time
So i'm using js-grid to populate a generic grid. I have 4 visible columns and 1 hidden id column. I am trying to pass the unique id per row into another function. However, when I dive into the property path of a object return by using jquery. The key that I need to get to is nested in a key that seems to change every time i return the object. Here's the JS grid code... $("#jsGrid").jsGrid({ width: "100%", height: "25rem", autoload: true, inserting: false, editing: false, sorting: false, paging: true, pageloading: true, data: data, fields: [ { name: "ID", type: "text", width: 25, align: "center", visible: false }, { name: "Date", type: "text", width: 25, align: "center" }, { name: "Color", type: "text", width: 25, align: "center" }, { name: "type", type: "text", width: 25, align: "center" }, { name: "other", type: "text", width: 25, align: "center" } ] }); Here's some sample data... var data = [ { "ID": "123", "Date": "3/15/19", "color": "Brown", "type": "something", "other": "7 mins" }, { "ID": "124", "Date": "3/15/19", "color": "Red", "type": "something", "other": "15 mins" }, { "ID": "125", "Date": "3/15/19", "color": "Blue", "type": "something", "other": "15 mins" }, { "ID": "126", "Date": "3/15/19", "color": "Blue", "type": "something", "other": "7 mins" }, { "ID": "127", "Date": "3/15/19", "color": "Black", "type": "something", "other": "20 mins" }, { "ID": "128", "Date": "3/15/19", "color": "Gold", "type": "something", "other": "5 mins" }, { "Date": "TOTAL", "color": "", "type": "", "other": "74 mins"} ]; Here's the code I use to get the <tr> object using console $(".jsgrid-table > tbody > tr:not('[class*=totalsRow]')"); Here's what I see. The key/keys that changes are in the attached image and starts with the word jQuery.
So i have tried your code. Based on what you have given me, i had to write custom method to achieve it. var k = $('.jsgrid-table > tbody > tr'); Items = GetMatchingProperties(k, 'jQuery'); //'jQuery' This is the word that matches console.log(Items); function GetMatchingProperties(items, attribName) { var list = []; $(items).each(function(i, t) { var $t = $(t); var keys = Object.keys($t[0]); var JQueryKey = keys.filter(function(x){ if(x.match(attribName)){ return x; } }); $.each(JQueryKey, function(i, v){ list.push( $t[0][v] ); }); }); return list; }
How to change pie chart colours in a custom TFS widget
I've to change default bar color in a custom tfs widget, how can I do this? I know there a "color" option but I can't find the correct syntax. Thanks. Here's my chart code: chartOptions = { "hostOptions": { "height": "290", "width": "300" }, "chartType": "bar", "series": [{ "data": [myBugs, myVuln, myCodeSm] }], "xAxis": { "labelValues": ["Bugs", "Vulnerabilities", "Code smells"] }, "specializedOptions": { "showLabels": "true", "size": 200 } };
Try to add your custom colors like below: chartOptions = { "hostOptions": { "height": "290", "width": "300" }, "colorCustomizationOptions": { "customColors": ["#FF0000", "#00CC00", "#302772"] }, "chartType": "bar", "series": [{ "data": [myBugs, myVuln, myCodeSm] }], "xAxis": { "labelValues": ["Bugs", "Vulnerabilities", "Code smells"] }, "specializedOptions": { "showLabels": "true", "size": 200 } };
In vss-web-extension-sdk/typings/charts.d.ts I found that customColors is a ColorEntry array. ColorEntry has two string properties: value, backgroundColor. With some trial and error I found out that value should be the label for which you want to set the color. So I think this should work: chartOptions = { "hostOptions": { "height": "290", "width": "300" }, "chartType": "bar", "series": [{ "data": [myBugs, myVuln, myCodeSm] }], "xAxis": { "labelValues": ["Bugs", "Vulnerabilities", "Code smells"] }, "colorCustomizationOptions": { "customColors": [ {backgroundColor: "#FF0000", value: "Bugs"}, {backgroundColor: "#00CC00", value: "Vulnerabilities"}, {backgroundColor: "#302772", value: "Code smells"} ] }, "specializedOptions": { "showLabels": "true", "size": 200 } };
How to intergrate a for loop to Fusion Charts
I want to add a for loop to my FusionChart script, so i can enter values through the loop. but so far i could not do it. please help. this is the code. what can i do to make this loop work? FusionCharts.ready(function () { var revenueChart = new FusionCharts({ type: 'column3d', renderAt: 'chartContainer', width: '500', height: '300', dataFormat: 'json', dataSource: { "chart": { "caption": "Monthly revenue for last year", "subCaption": "Harry's SuperMart", "xAxisName": "Month", "yAxisName": "Revenues (In USD)", }, "data": [ //for (var i = 0; i < ist.length; i++) {// this is where i want to add the loop { "label": ist[0].MyProperty_Test_Customer_Id, "value": parseFloat(ist[0].MyProperty_Test_Chargers) }, { "label": ist[1].MyProperty_Test_Customer_Id, "value": parseFloat(ist[1].MyProperty_Test_Chargers) }, { "label": ist[2].MyProperty_Test_Customer_Id, "value": parseFloat(ist[2].MyProperty_Test_Chargers) } //} ] } }); revenueChart.render(); });
OK, so the data attribute needs to be an array. You can achieve this with a for loop if it is inside of a so-called IIFE and having the IFFE return an array (note that you would put the following inside the chart configuration): "data": (function() { var data = []; for (var i = 0; i < ist.length; i++) { data.push({ "label": ist[i].MyProperty_Test_Customer_Id, "value": parseFloat(ist[i].MyProperty_Test_Chargers) }) } return data; })() Better yet, create the array you need using the for loop above var revenueChart = new FusionCharts({...: var chartData = []; for (var i = 0; i < ist.length; i++) { chartData.push({ "label": ist[i].MyProperty_Test_Customer_Id, "value": parseFloat(ist[i].MyProperty_Test_Chargers) }) } var revenueChart = new FusionCharts({ ... data: chartData ...
FusionCharts.ready(function () { var data = []; //alert(x.length); for (var i = 0; i < x.length; i++) { data.push({ "label": x[i].HR_BG, "value": x[i].b }) } var ageGroupChart = new FusionCharts({ type: 'pie3d', renderAt: 'chart-pie', width: '600', height: '500', dataFormat: 'json', dataSource: { "chart": { "caption": "YTR Production Hours", "subCaption": "", "paletteColors": "#0075c2,#1aaf5d,#f2c500,#f45b00,#8e0000", "bgColor": "#ffffff", "showBorder": "0", "use3DLighting": "0", "showShadow": "0", "enableSmartLabels": "0", "startingAngle": "0", "showPercentValues": "0", "showPercentInTooltip": "0", "decimals": "", "captionFontSize": "14", "subcaptionFontSize": "14", "subcaptionFontBold": "0", "toolTipColor": "#ffffff", "toolTipBorderThickness": "0", "toolTipBgColor": "#000000", "toolTipBgAlpha": "80", "toolTipBorderRadius": "2", "toolTipPadding": "5", "showHoverEffect":"1", "showLegend": "1", "legendBgColor": "#ffffff", "legendBorderAlpha": '0', "legendShadow": '0', "legendItemFontSize": '10', "legendItemFontColor": '#666666' }, "data": data } }).render(); });
How to get this jSON data from API with Javascript / AngularJS
I am working with jSON, an API and AngularJS. I want to get the following data, but I will not know in advanced what the keywords or the dates will be { "landscape gardening middlesex": { "2015-02-12": { "position": null, "change": "n/a", "class": "gray" }, "2015-03-17": { "position": "0", "change": "n/a", "class": "gray" } }, "landscape gardening staines": { "2015-02-12": { "position": null, "change": "n/a", "class": "gray" }, "2015-03-17": { "position": "94", "change": "n/a", "class": "green" } }, "landscape gardening surrey": { "2015-02-12": { "position": null, "change": "n/a", "class": "green" }, "2015-03-17": { "position": "0", "change": "n/a", "class": "gray" } } } How can i retrieve this using AngularJS ng-repeat Thanks.
create a javascript object and store it somewhere... you can always stringify it then re-parse it var myJSON = { name: "bill", skills : ["coding", "sleeping", "eating"], age : 25 }; // this string can be stored anywhere, like even as a string in mySQL. var string = JSON.stringify( myJSON ); /// Turn Back into JSON obj var newJSON = JSON.parse(string); console.log( newJSON.name ); // >> "bill" /// Hope this helps
Google Chrome Apps: chrome.storage.local
I am having a struggle finding out why the following is happening in a application i'm developing: So i read a JSON file where i want to read and save his content on localStorage, which in a chrome app is chrome.storage.local So i get the following from a json file: { "schedule": { "id": "416a18d6-7e42-4f8a-ac24-e902abe76f39", "name": "blabla", "updatedOn": "2013-09-08T16:34:41.000Z", "etag": "esxrdctfvygbuhnij5464df7g8hu", "applications": [ { "id": "app001", "type": "text/html", "src": "http://www.google.com" }, { "id": "app002", "type": "text/html", "src": "http://www.stackoverflow.com" } ], "normalContent": [ { "layout_id": "layout001", "layout_name": "layout1", "layout_dur": "indefinite", "regions": [ { "region_id": "region001", "region_name": "regiao1", "left": "0", "top": "0", "width": "0.5", "height": "1", "minWidth": "0", "minHeight": "0", "scheduleItem": "container", "limitCycle": "1", "selector": "seq", "containerList": [ { "cid": "app001", "dur": "25" }, { "cid": "app002", "dur": "15" } ] }, { "region_id": "region002", "region_name": "regiao2", "left": "0.5", "top": "0", "width": "0.5", "height": "1", "minWidth": "0", "minHeight": "0", "scheduleItem": "container", "limitCycle": "1", "selector": "seq", "containerList": [ { "cid": "app002", "dur": "15" }, { "cid": "app001", "dur": "15" } ] } ] } ] } } So i get this and then i save the content in storage using: chrome.storage.local.set({playerSchedule:this.schedule}, function(){ console.log('saved!') }); Later on when i read the content stored using: chrome.storage.local.get(["playerSchedule", "playerScheduleType"], function (res) { self.currentSchedule = res.playerSchedule; self.scheduleType = res.playerScheduleType; }); This is what i get: { "schedule": { "applications": [ { "id": "app001", "type": "text/html", "src": "http://www.google.com" }, { "id": "app002", "type": "text/html", "src": "http://www.stackoverflow.com" } ], "etag": "esxrdctfvygbuhnij5464df7g8hu", "id": "416a18d6-7e42-4f8a-ac24-e902abe76f39", "name": "blabla", "normalContent": [ { "layout_dur": "indefinite", "layout_id": "layout001", "layout_name": "layout1", "regions": [ { ... "containerList": [ ] }, { ... "containerList": [ ] } ] } ], "updatedOn": "2013-09-08T16:34:41.000Z" } } As you can observe, the content i read comes in alphabetic order and the content in containerList is empty. Any reason why this is happening? I solved this by converting the object to string and storing it, but i wonder why saving as object i get that from reading as an object or is there something i am missing? Thanks in advance.
This is probably http://code.google.com/p/chromium/issues/detail?id=277647. Fix is in the works for Chrome 31.