How to change bar opacity upon click of FusionCharts 2D Column Chart? - bar-chart

I am attempting to toggle the opacity of a bar when it is clicked on utilizing the "dataPlotClick" event. I am able to change the opacity, but as soon as I move my mouse off of the bar the opacity changes back to the default.
NOTE: A similar question has been asked before on SO, but doesn't seem to have a valid answer.
How do I utilize the below dataPlotClick event to achieve this?
events: {
"dataPlotClick": function (evtObj, argObj) {
var i, plotItems;
plotItems = evtObj.sender.jsVars.hcObj.elements.plots[0].items;
plotItems[argObj.dataIndex].graphic.attr("fill-opacity", .2);
}
}
Fusion Chart:
FusionCharts.ready(function () {
var revenueChart = new FusionCharts({
type: 'column2d',
renderAt: 'chart-container',
width: '500',
height: '350',
dataFormat: 'json',
dataSource: {
"chart": {
"caption": "Monthly revenue for last year",
"subCaption": "Harry's SuperMart",
"xAxisName": "Month",
"yAxisName": "Revenue (In USD)",
"numberPrefix": "$",
"paletteColors": "#0075c2",
"bgColor": "#ffffff",
"borderAlpha": "20",
"canvasBorderAlpha": "0",
"usePlotGradientColor": "0",
"plotBorderAlpha": "10",
"placevaluesInside": "1",
"rotatevalues": "1",
"valueFontColor": "#ffffff",
"showXAxisLine": "1",
"xAxisLineColor": "#999999",
"divlineColor": "#999999",
"divLineIsDashed": "1",
"showAlternateHGridColor": "0",
"subcaptionFontBold": "0",
"subcaptionFontSize": "14"
},
"data": [
{
"label": "Jan",
"value": "420000"
}, {
"label": "Feb",
"value": "810000"
}, {
"label": "Mar",
"value": "720000"
}, {
"label": "Apr",
"value": "550000"
}, {
"label": "May",
"value": "910000"
}, {
"label": "Jun",
"value": "510000"
}, {
"label": "Jul",
"value": "680000"
}, {
"label": "Aug",
"value": "620000"
}, {
"label": "Sep",
"value": "610000"
}, {
"label": "Oct",
"value": "490000"
}, {
"label": "Nov",
"value": "900000"
}, {
"label": "Dec",
"value": "730000"
}]
},
events: {
"dataPlotClick": function (evtObj, argObj) {
var i, plotItems, plotLength;
plotItems = evtObj.sender.jsVars.hcObj.elements.plots[0].items;
plotItems[argObj.dataIndex].graphic.attr("fill-opacity", .2);
}
}
}
}).render();
});

The alpha attribute need to set within the dataPlotClick FusionCharts API event for the particular data plot which has been clicked.
The particular data plot index could be found with the help of dataObj parameters dataIndex attribute within dataPlotClick FusionCharts API event.
Finally set the modified JSON structure with the help of FusionCharts setJSONData API method.
Please implement the below given code.
FusionCharts.ready(function () {
var topStores = new FusionCharts({
type: 'column2d',
renderAt: 'chart-container',
width: '400',
height: '300',
dataFormat: 'json',
dataSource: {
"chart": {
"caption": "Monthly revenue for last year",
"subCaption": "Harry's SuperMart",
"xAxisName": "Month",
"yAxisName": "Revenue (In USD)",
"numberPrefix": "$",
"paletteColors": "#0075c2",
"bgColor": "#ffffff",
"borderAlpha": "20",
"canvasBorderAlpha": "0",
"usePlotGradientColor": "0",
"plotBorderAlpha": "10",
"placevaluesInside": "1",
"rotatevalues": "1",
"valueFontColor": "#ffffff",
"showXAxisLine": "1",
"xAxisLineColor": "#999999",
"divlineColor": "#999999",
"divLineIsDashed": "1",
"showAlternateHGridColor": "0",
"subcaptionFontBold": "0",
"subcaptionFontSize": "14"
},
"data": [{
"label": "Jan",
"value": "420000"
}, {
"label": "Feb",
"value": "810000"
}, {
"label": "Mar",
"value": "720000"
}, {
"label": "Apr",
"value": "550000"
}, {
"label": "May",
"value": "910000"
}, {
"label": "Jun",
"value": "510000"
}, {
"label": "Jul",
"value": "680000"
}, {
"label": "Aug",
"value": "620000"
}, {
"label": "Sep",
"value": "610000"
}, {
"label": "Oct",
"value": "490000"
}, {
"label": "Nov",
"value": "900000"
}, {
"label": "Dec",
"value": "730000"
}]
},
events: {
"dataPlotClick": function(evtObj, argObj) {
var plotNum= argObj.dataIndex;
var data =evtObj.sender.args.dataSource.data;
data[plotNum].alpha="10";
evtObj.sender.setJSONData(evtObj.sender.args.dataSource);
}
}
})
.render();
});

Related

Card_V2 display issue in Google Chat

I have the following JSON to display Card_V2 for Google Chat, (note: words with "let_" are variables):
{
"cards_v2": [
{
"card": {
"header": {
"title": "Create campaign",
"subtitle": "Please complete the following information",
"imageType": "CIRCLE",
"imageUrl": "let_avatar"
},
"sections": [
{
"widgets": [
{
"textInput": {
"label": "Campaign name",
"type": "SINGLE_LINE",
"name": "nCampaign",
"value": "let_campaign"
}
},
{
"textInput": {
"label": "Campaign subject",
"type": "SINGLE_LINE",
"name": "subject",
"value": "let_subject"
}
},
{
"textInput": {
"label": "User name",
"type": "SINGLE_LINE",
"name": "userName",
"value": "let_userName"
}
},
{
"buttonList": {
"buttons": [
{
"text": "Create campaign",
"color": {
"red": 0.502,
"green": 1,
"blue": 0.733,
"alpha": 1
},
"onClick": {
"action": {
"function": "create",
"parameters": []
}
}
},
{
"text": "Cancel",
"color": {
"red": 0.502,
"green": 1,
"blue": 0.733,
"alpha": 1
},
"onClick": {
"action": {
"function": "cancel",
"parameters": []
}
}
}
]
},
"horizontalAlignment": "CENTER"
}
]
}
]
}
}
]
}
My problem is that the "textInput" screen does not appear, but last week it did. Does anyone have any idea what's going on?
PS: the Card is the return of the onMessage(event) function in Google Apps Script

JMeter jp#gc JSON/YAML Path Assertion for an array

I'm trying to use jp#gc - JSON/YAML Path Assertion, when my Response Body is:
[
{
"label": "Alabama",
"value": "AL"
},
{
"label": "Alaska",
"value": "AK"
},
{
"label": "American Samoa",
"value": "AS"
},
{
"label": "Arizona",
"value": "AZ"
},
{
"label": "Arkansas",
"value": "AR"
},
{
"label": "California",
"value": "CA"
},
{
"label": "Colorado",
"value": "CO"
},
{
"label": "Connecticut",
"value": "CT"
},
{
"label": "Delaware",
"value": "DE"
},
{
"label": "District Of Columbia",
"value": "DC"
},
{
"label": "Federated States Of Micronesia",
"value": "FM"
},
{
"label": "Florida",
"value": "FL"
},
{
"label": "Georgia",
"value": "GA"
},
{
"label": "Guam",
"value": "GU"
},
{
"label": "Hawaii",
"value": "HI"
},
{
"label": "Idaho",
"value": "ID"
},
{
"label": "Illinois",
"value": "IL"
},
{
"label": "Indiana",
"value": "IN"
},
{
"label": "Iowa",
"value": "IA"
},
{
"label": "Kansas",
"value": "KS"
},
{
"label": "Kentucky",
"value": "KY"
},
{
"label": "Louisiana",
"value": "LA"
},
{
"label": "Maine",
"value": "ME"
},
{
"label": "Marshall Islands",
"value": "MH"
},
{
"label": "Maryland",
"value": "MD"
},
{
"label": "Massachusetts",
"value": "MA"
},
{
"label": "Michigan",
"value": "MI"
},
{
"label": "Minnesota",
"value": "MN"
},
{
"label": "Mississippi",
"value": "MS"
},
{
"label": "Missouri",
"value": "MO"
},
{
"label": "Montana",
"value": "MT"
},
{
"label": "Nebraska",
"value": "NE"
},
{
"label": "Nevada",
"value": "NV"
},
{
"label": "New Hampshire",
"value": "NH"
},
{
"label": "New Jersey",
"value": "NJ"
},
{
"label": "New Mexico",
"value": "NM"
},
{
"label": "New York",
"value": "NY"
},
{
"label": "North Carolina",
"value": "NC"
},
{
"label": "North Dakota",
"value": "ND"
},
{
"label": "Northern Mariana Islands",
"value": "MP"
},
{
"label": "Ohio",
"value": "OH"
},
{
"label": "Oklahoma",
"value": "OK"
},
{
"label": "Oregon",
"value": "OR"
},
{
"label": "Palau",
"value": "PW"
},
{
"label": "Pennsylvania",
"value": "PA"
},
{
"label": "Puerto Rico",
"value": "PR"
},
{
"label": "Rhode Island",
"value": "RI"
},
{
"label": "South Carolina",
"value": "SC"
},
{
"label": "South Dakota",
"value": "SD"
},
{
"label": "Tennessee",
"value": "TN"
},
{
"label": "Texas",
"value": "TX"
},
{
"label": "Utah",
"value": "UT"
},
{
"label": "Vermont",
"value": "VT"
},
{
"label": "Virgin Islands",
"value": "VI"
},
{
"label": "Virginia",
"value": "VA"
},
{
"label": "Washington",
"value": "WA"
},
{
"label": "West Virginia",
"value": "WV"
},
{
"label": "Wisconsin",
"value": "WI"
},
{
"label": "Wyoming",
"value": "WY"
}
]
Here is how is use the JSON/YAML Path Assertion:
but I'm getting Assertion failure:
The following setup should work for you:
More information:
JsonPath - Getting Started
Perl 5 Regex Cheat sheet
The New JSON/YAML Plugin - Using YAML in JMeter
Use JSON Assertion ( jp#gc - JSON/YAML is deprecated)
JSON start with array so use JSON Path
$.[0].label
You can also uncheck Match as regular expression

FusionCharts: How to have a stacked column chart along with area chart in a single chart

I want to display a chart using fusion charts with stacked column chart along with area chart.
Is there an option to create the same? I went through the fusion charts website but did not find that option is combination charts.
Below is my code:
FusionCharts.ready(function () {
var salesAnlysisChart = new FusionCharts({
type: 'mscombi2D',
renderAt: 'chart-container',
width: '600',
height: '300',
dataFormat: 'json',
dataSource: {
"categories": [{
"category": [{
"label": "25 Jun - \r\n01 Jul"
},
{
"label": "02 Jul - \r\n08 Jul"
},
{
"label": "09 Jul - \r\n15 Jul"
},
{
"label": "16 Jul - \r\n22 Jul"
}]
}],
"chart": {
"showPlotBorder": "0",
"showValues": "0",
"showToolTip": "1",
"caption": "Line1",
"YAxisName": "Demand",
"showBorder": "0",
"canvasBorderThickness": "1",
"usePlotGradientColor": "0",
"showAlternateHGridColor": "0",
"showToolTipShadow": "1",
"toolTipBgAlpha": "90",
"bgColor": "#ffffff",
"canvasBorderColor": "#f2f2f2",
"xAxisName": "Timeline",
"toolTipBorderColor": "#333333",
"toolTipBgColor": "#ffffff",
"legendBorderThickness": "0",
"divLineColor": "#f2f2f2",
"legendShadow": "0"
},
"dataset": [{
"seriesname": "Five Days",
"color": "#92d3e4",
"data": [{
"value": 4262
},
{
"value": 4524
},
{
"value": 4804
},
{
"value": 4528
}]
},
{
"seriesname": "Overtime (1 Day)",
"color": "#2ea2c0",
"data": [{
"value": 1067
},
{
"value": 619
},
{
"value": 762
},
{
"value": 1009
}]
},
{
"seriesname": "Overtime (2 Days)",
"color": "#366082",
"data": [{
"value": 887
},
{
"value": 910
},
{
"value": 1152
},
{
"value": 1110
}]
},
{
"anchorHoverEffect": "1",
"seriesname": "Demand",
"showValues": "0",
"anchorRadius": "3",
"color": "#e9f057",
"data": [{
"value": 4.9E-323
},
{
"value": 4230
},
{
"value": 4230
},
{
"value": 4230
}],
"anchorHoverRadius": "5",
"parentYAxis": "S",
"renderAs": "line",
"anchorBgColor": "#e9f057"
},
{
"seriesname": "Cum. Capacity",
"color": "#2ea2c0",
"renderAs": "area",
"data": [{
"value": 4262
},
{
"value": 4566
},
{
"value": 5140
},
{
"value": 5438
}]
}],
"trendlines": [{
"line": [{
"displayValue": "5 Day Capacity",
"isTrendZone": "1",
"color": "#da433f",
"thickness": "2",
"valueOnRight": "1",
"startValue": 4468,
"valuePadding": "10",
"tooltext": "5 Day Capacity: 4468.0"
}]
}]
}
}).render();
});
The column charts are not stacked.
If i use type='stackedcolumn2dline' then the area chart become stacked too.
Is there a way to get this done?
Any help would be appreciated.
Thank You.
yes as of now you can have stackedcolumn2dline chart as the only combination chart which has stacked plot in it, however, you can raise a request FusionCharts support.
They could assist you accordingly.

jsonpath query for reading json's child elements

I'm trying to read element's values.
For test purposes I was trying to read account_name element value.
I've tried this
jsonloop query = "data/ads/data/insights/data[*]"
account_name = "$.data.ads.data.insights.data.[*].account_name"
But not getting result. Apart from this I've googled alot and my logic seems to be okay..but I dont know where am doing wrong.
{
"data": [{
"id": "act_78425484545145418"
}, {
"id": "act_87814545415645416"
}, {
"ads": {
"data": [{
"insights": {
"data": [{
"account_name": "Emirates WW",
"campaign_name": "FR_Ozone_aug",
"adset_name": "Android",
"ad_name": "C_mail_9sept",
"spend": 12.2,
"impressions": "1146",
"clicks": "16",
"_store_clicks": "0",
"inline_click_pointss": "16",
"actions": [{
"action_type": "custom_event._activate_",
"value": 2
}, {
"action_type": "custom_event.other",
"value": 1
}, {
"action_type": "click_points",
"value": 16
}, {
"action_type": "__install",
"value": 1
}, {
"action_type": "offsite_points.view_content_points",
"value": 25
}, {
"action_type": "post_points",
"value": 16
}, {
"action_type": "post_points",
"value": 16
}, {
"action_type": "offsite_points",
"value": 25
}, {
"action_type": "custom_event",
"value": 3
}],
"date_start": "2016-09-09",
"date_stop": "2016-09-19"
}],
"paging": {
"cursors": {
"before": "ADZZZZ",
"after": "ADZZZZ"
}
}
},
"id": "6054027758549"
}, {
"insights": {
"data": [{
"account_name": "Emirates WW",
"campaign_name": "FR_Ozone_aug",
"adset_name": "Reta_Phy_iOS",
"ad_name": "Council_email_9sept",
"spend": 10.13,
"impressions": "1004",
"clicks": "10",
"_store_clicks": "8",
"inline_click_pointss": "10",
"actions": [{
"action_type": "click_points",
"value": 10
}, {
"action_type": "offsite_points.view_content_points",
"value": 38
}, {
"action_type": "post_points",
"value": 10
}, {
"action_type": "post_points",
"value": 10
}, {
"action_type": "offsite_points",
"value": 38
}],
"date_start": "2016-09-09",
"date_stop": "2016-09-19"
}],
"paging": {
"cursors": {
"before": "ADZZZZ",
"after": "ADZZZZ"
}
}
},
"id": "6054030075149"
}],
"paging": {
"cursors": {
"before": "Juysubgysbyy",
"after": "Nhwunhseuubeyegb"
}
}
}
}]
}
Can anyone help ?
Thanks in Advance !!
First and second data properties have array values, so you should add .[*] after them:
account_name = "$.data.[*].ads.data.[*].insights.data.[*].account_name"
The result:
[
"Emirates WW",
"Emirates WW"
]

How to get a value of a object from its foreign key?

Im using Backand to store my data. I have an object, Events, that references another object, Locations.
{
"name": "events",
"fields": {
"eventCommentsId": {
"collection": "comments",
"via": "eventId"
},
"tags": {
"collection": "events_tags",
"via": "event"
},
"users": {
"collection": "users_events",
"via": "event"
},
"name": {
"type": "string"
},
"date": {
"type": "datetime"
},
"time": {
"type": "datetime"
},
"info": {
"type": "text"
},
"locationId": {
"object": "locations"
}
},
{
"name": "locations",
"fields": {
"events": {
"collection": "events",
"via": "locationId"
},
"name": {
"type": "text"
},
"geo": {
"type": "point"
}
}
}
When I try to display the location of the event, I can only get the value of locationID. I want the actual name of the location, not the id. How do I do that?
<ion-list>
<ion-item class="item item-thumbnail-left" ng-repeat="event in events" type="item-text-wrap" href="#/event-detail/{{event.id}}">
<h2>{{event.name}}</h2>
<p><i class="ion-location"></i> {{event.locationId.name}}</p>
<ion-option-button class="button-assertive" ng-click="deleteEvent(event.id)">
Delete
</ion-option-button>
</ion-item>
</ion-list>
angular code
.service('EventService', function ($http, Backand) {
var baseUrl = '/1/objects/';
var objectName = 'events/';
function getUrl() {
return Backand.getApiUrl() + baseUrl + objectName;
}
function getUrlForId(id) {
return getUrl() + id;
}
getEvents = function () {
return $http.get(getUrl());
};
addEvent = function(event) {
return $http.post(getUrl(), event);
}
deleteEvent = function (id) {
return $http.delete(getUrlForId(id));
};
getEvent = function (id) {
return $http.get(getUrlForId(id));
};
return {
getEvents: getEvents,
addEvent: addEvent,
deleteEvent: deleteEvent,
getEvent: getEvent
}
})
.controller('FeedCtrl', ['$scope', '$ionicModal', '$ionicSideMenuDelegate', 'EventService', function($scope, $ionicModal, $ionicSideMenuDelegate, EventService) {
$scope.events = [];
$scope.input = {};
function getAllEvents() {
EventService.getEvents()
.then(function (result) {
$scope.events = result.data.data;
});
}
$scope.addEvent = function() {
EventService.addEvent($scope.input)
.then(function(result) {
$scope.input = {};
getAllEvents();
});
}
$scope.deleteEvent = function(id) {
EventService.deleteEvent(id)
.then(function (result) {
getAllEvents();
});
}
getAllEvents();
}])
There are two options. You can either use the descriptive value in the __metadata of each object like this:
request: https://api.backand.com/1/objects/events?pageSize=20&pageNumber=1
response:
{
"totalRows": 2,
"data": [
{
"__metadata": {
"id": "1",
"fields": {
"id": {
"type": "int",
"unique": true
},
"name": {
"type": "string"
},
"date": {
"type": "datetime"
},
"time": {
"type": "datetime"
},
"info": {
"type": "text"
},
"locationId": {
"object": "locations"
}
},
"descriptives": {
"locationId": {
"label": "Madison Square Garden",
"value": "1"
}
},
"dates": {
"date": "",
"time": ""
}
},
"id": 1,
"name": "knicks vs warriors",
"date": null,
"time": null,
"info": "",
"locationId": "1"
},
{
"__metadata": {
"id": "2",
"fields": {
"id": {
"type": "int",
"unique": true
},
"name": {
"type": "string"
},
"date": {
"type": "datetime"
},
"time": {
"type": "datetime"
},
"info": {
"type": "text"
},
"locationId": {
"object": "locations"
}
},
"descriptives": {
"locationId": {
"label": "Madison Square Garden",
"value": "1"
}
},
"dates": {
"date": "",
"time": ""
}
},
"id": 2,
"name": "knicks vs cavs",
"date": null,
"time": null,
"info": "",
"locationId": "1"
}
]
}
or you can do a deep request and get the value in the relatedObjects
request: https://api.backand.com/1/objects/events?pageSize=20&pageNumber=1&deep=true
response:
{
"totalRows": 2,
"data": [
{
"__metadata": {
"id": "1",
"fields": {
"id": {
"type": "int",
"unique": true
},
"name": {
"type": "string"
},
"date": {
"type": "datetime"
},
"time": {
"type": "datetime"
},
"info": {
"type": "text"
},
"locationId": {
"object": "locations"
}
},
"descriptives": {
"locationId": {
"label": "Madison Square Garden",
"value": "1"
}
},
"dates": {
"date": "",
"time": ""
}
},
"id": 1,
"name": "knicks vs warriors",
"date": null,
"time": null,
"info": "",
"locationId": "1"
},
{
"__metadata": {
"id": "2",
"fields": {
"id": {
"type": "int",
"unique": true
},
"name": {
"type": "string"
},
"date": {
"type": "datetime"
},
"time": {
"type": "datetime"
},
"info": {
"type": "text"
},
"locationId": {
"object": "locations"
}
},
"descriptives": {
"locationId": {
"label": "Madison Square Garden",
"value": "1"
}
},
"dates": {
"date": "",
"time": ""
}
},
"id": 2,
"name": "knicks vs cavs",
"date": null,
"time": null,
"info": "",
"locationId": "1"
}
],
"relatedObjects": {
"locations": {
"1": {
"__metadata": {
"id": "1",
"fields": {
"id": {
"type": "int",
"unique": true
},
"events": {
"collection": "events",
"via": "locationId"
},
"name": {
"type": "text"
},
"geo": {
"type": "point"
}
},
"descriptives": {},
"dates": {}
},
"id": 1,
"events": null,
"name": "Madison Square Garden",
"geo": [
40.7505,
73.9934
]
}
}
}
}
search for Madison Square Garden as the name of the location to understand the JSON structure.
You can set the descriptive field in the Object Settings