I have to display the following data in a c3js multi-line chart.
The date will be the x axis.
each row will be each line in the chart.
When I try to display this in multi line chart it doesn't display and also not giving any error.
Please help me.
["date", "2017-05-01", "2017-05-02", "2017-05-03", "2017-05-04", "2017-05-06", "2017-05-08", "2017-05-09", "2017-05-10", "2017-05-12", "2017-05-13", "2017-05-16", "2017-05-17", "2017-05-18", "2017-05-19", "2017-05-20", "2017-05-23", "2017-05-24", "2017-05-25", "2017-05-29"]["Shrirang Adkar", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null]["Delhi Store", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null]["Ajay Subramaniam", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null]["Shivani Yadavalli", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null]["Siddhesh 2020", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null]["Salva", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null]["Iranna Zampa", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null]["Hisam", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null] ["Samruddhi Sawant", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null]["Manish K S", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null] ["Sukanya Ray", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null]["Karen Ho", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null]["Srishti Narang", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null]["Sreejata Mitra", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null]["Estroz", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null]
You can check this JSFiddle. You need to put , between every chunk of datas.
var chart = c3.generate({
data: {
x: 'date',
columns: [
["date", "2017-05-01", "2017-05-02", "2017-05-03", "2017-05-04", "2017-05-06", "2017-05-08", "2017-05-09", "2017-05-10", "2017-05-12", "2017-05-13", "2017-05-16", "2017-05-17", "2017-05-18", "2017-05-19", "2017-05-20", "2017-05-23", "2017-05-24", "2017-05-25", "2017-05-29"],
["Shrirang Adkar", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null],
["Delhi Store", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null],
["Ajay Subramaniam", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null],
["Shivani Yadavalli", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null],
["Siddhesh 2020", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null],
["Salva", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null],
["Iranna Zampa", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null],
["Hisam", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null],
["Samruddhi Sawant", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null],
["Manish K S", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null],
["Sukanya Ray", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null],
["Karen Ho", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null],
["Srishti Narang", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null],
["Sreejata Mitra", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null],
["Estroz", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null]
]
},
axis: {
x: {
type: 'timeseries',
tick: {
format: '%Y-%m-%d'
}
}
}
});
Related
I have a function that returns staff and there associated attributes as below
foreach ($merchant_user_ac->staffs->sortByDesc('id') as $staff) {
$wage = Staff::find($staff->id)->totalCommissions($start_date, $end_date);
$payments = StaffPayment::where('merchant_id', AH::cMiD())
->where('user_id', $staff->id)
->when(!empty($start_date) && !empty($end_date), function ($q) use (
$start_date,
$end_date
) {
$q->whereBetween(\DB::raw('date(payment_date)'), [
$start_date,
$end_date,
]);
})
->sum('amount');
$balance_owed = $wage - $payments;
$transactions->add([
'id' => $staff->id,
'name' => $staff->name,
'profilephoto' => $staff->profilephoto,
'wage' => $wage,
'payments' => $payments,
'salary' => $staff->salary,
'rent' => $staff->rent,
'balance_owed' => $balance_owed + $staff->salary - $staff->rent,
]);
}
$merchant_staffs = collect(json_decode(json_encode($transactions), false));
$merchant_staffs = $merchant_staffs->paginate(10);
return response()->json($merchant_staffs);
In the results, the first page is OK but the subsequent pages are having a different data type from the first page and displaying the data becomes an issue.
The data key has different data types.
I have tried paginating before the foreach loop but the response did not have the pagination links.
I have tried adding ->toArray() method when collecting the data but has the same issue of different types.
How can I return the same data in all pagination links?
The data returned is as below
{
"current_page": 1,
"data": [
{
"id": 532,
"name": "George2",
"profilephoto": "photos/GwSIKoIXUk1GdL7boD7Ht9mSp1loxM1nGcZ5l5Gd.jpg",
"wage": 0,
"payments": 10000,
"salary": "90000.00",
"rent": "1000.00",
"balance_owed": 79000
},
{
"id": 528,
"name": "david",
"profilephoto": null,
"wage": 100,
"payments": 0,
"salary": "67000.00",
"rent": "67000.00",
"balance_owed": 100
},
{
"id": 524,
"name": "Naggie",
"profilephoto": null,
"wage": 0,
"payments": 0,
"salary": null,
"rent": null,
"balance_owed": 0
},
{
"id": 503,
"name": "Khaki ",
"profilephoto": null,
"wage": 0,
"payments": 0,
"salary": null,
"rent": null,
"balance_owed": 0
},
{
"id": 502,
"name": "Susan",
"profilephoto": null,
"wage": 0,
"payments": 0,
"salary": null,
"rent": null,
"balance_owed": 0
},
{
"id": 476,
"name": "Maggie",
"profilephoto": null,
"wage": 0,
"payments": 17000,
"salary": null,
"rent": "15000.00",
"balance_owed": -32000
},
{
"id": 475,
"name": "Aggy",
"profilephoto": null,
"wage": 0,
"payments": 15000,
"salary": "15000.00",
"rent": null,
"balance_owed": 0
},
{
"id": 465,
"name": "Rhoda",
"profilephoto": null,
"wage": 0,
"payments": 0,
"salary": null,
"rent": null,
"balance_owed": 0
},
{
"id": 464,
"name": "Very New Staff",
"profilephoto": null,
"wage": 500,
"payments": 0,
"salary": "10000.00",
"rent": null,
"balance_owed": 10500
},
{
"id": 422,
"name": "jane",
"profilephoto": null,
"wage": 0,
"payments": 0,
"salary": "15000.00",
"rent": null,
"balance_owed": 15000
}
],
"first_page_url": "http://127.0.0.1:8000/api/v1/staff/list?page=1",
"from": 1,
"last_page": 3,
"last_page_url": "http://127.0.0.1:8000/api/v1/staff/list?page=3",
"links": [
{
"url": null,
"label": "« Previous",
"active": false
},
{
"url": "http://127.0.0.1:8000/api/v1/staff/list?page=1",
"label": "1",
"active": true
},
{
"url": "http://127.0.0.1:8000/api/v1/staff/list?page=2",
"label": "2",
"active": false
},
{
"url": "http://127.0.0.1:8000/api/v1/staff/list?page=3",
"label": "3",
"active": false
},
{
"url": "http://127.0.0.1:8000/api/v1/staff/list?page=2",
"label": "Next »",
"active": false
}
],
"next_page_url": "http://127.0.0.1:8000/api/v1/staff/list?page=2",
"path": "http://127.0.0.1:8000/api/v1/staff/list",
"per_page": 10,
"prev_page_url": null,
"to": 10,
"total": 25
}
Try
$pagination = $merchant_user_ac->staffs()->latest()->paginate(10);
$data = $pagination->getCollection()->map(function ($staff) {
$wage = Staff::find($staff->id)->totalCommissions($start_date, $end_date);
$payments = StaffPayment::where('merchant_id', AH::cMiD())
->where('user_id', $staff->id)
->when(!empty($start_date) && !empty($end_date), function ($q) use (
$start_date,
$end_date
) {
$q->whereBetween(\DB::raw('date(payment_date)'), [
$start_date,
$end_date,
]);
})
->sum('amount');
$balance_owed = $wage - $payments;
return [
'id' => $staff->id,
'name' => $staff->name,
'profilephoto' => $staff->profilephoto,
'wage' => $wage,
'payments' => $payments,
'salary' => $staff->salary,
'rent' => $staff->rent,
'balance_owed' => $balance_owed + $staff->salary - $staff->rent,
];
});
return response()->json($pagination->setCollection($data));
}
I have the following response payload and there are 4 siteId and I want to select any random siteId from it. This value of 4 can be change it will random, irrespective of it i want to select any random siteId.
Response Value
{
"studyDTO": {
"studyId": 191,
"studyCode": null
},
"sites": [
{
"studyId": 191,
"siteRecid": 1,
"siteId": "10000"
},
{
"studyId": 191,
"siteRecid": 16521,
"siteId": "11001"
},
{
"studyId": 191,
"siteRecid": 16632,
"siteId": "11011"
},
{
"studyId": 191,
"siteRecid": 201,
"siteId": "20000"
}
],
"subjects": [],
"visits": [],
"sftpLocations": [],
"dicomLocations": [],
"fileSystemLocations": [],
"rawFileSystemLocations": [],
"states": [],
"modalities": [],
"examDates": [],
"series": [],
"transferType": null,
"customFolder": false,
"customFile": false,
"folderStructure": null,
"fileStructure": null,
"allSites": false,
"allSubjects": false,
"allVisits": false,
"allStates": false,
"allExamDates": false,
"allModalities": false,
"allSeries": false,
"softEditOverride": false,
"includePS": false,
"includeSR": false,
"includeRTStruct": false,
"dicomTemplate": null,
"errorMessage": null,
"successMessage": null
}
Add JMESPath Extractor to your sampler and configure it:
JMESPath expressions: sites[*].studyId
Match No.: 0
Default Values: STUDYID_NOT_FOUND
JMESPath Extractor will collect all the studyId values and return one selected randomly.
I hope someone will be able to help me.
This code works fine :
cy.request({
method: 'POST',
url: surl,
log : true,
auth: {
user: 'xxxx',
pass: 'xxxx'
},
headers: {
//'Content-Type': 'application/json; charset=utf-8',
},
body:{
Obpos_Applications_ID: 'AE765712BBCC47669475A5478EEFA8B3',
inpKeyName: 'inpobposApplicationsId',
inpTabId: 'FF80818132F311740132F3233778004B',
inpTableId: 'FF80818132F311740132F31E2C9A0016',
inpadClientId: '48429219C6DA47AEB1F7958F1375D601',
inpadOrgId: '736B1011B45D4B96B31E329A15DB437A',
inpcBpartnerId: '6A7F4BF891884403A48E1DC0921FA71B',
inpcurrentCacheSessionId: '7139E00CEB614C6C947511AFCC6C20C5',
inpdefaultwebpostab: 'scan',
inpdocumentnoPadding: '7',
inpemAc3Host: null,
inpemAc3Interface: '',
inpemAc3Port: null,
inpemAc3Printsinfo: 'Y',
inpemAc3Terminal: null,
inpemGcnvGcseqLastnum: '0',
inpemGcnvGcseqPrefix: 'CAISSE_37_99',
inpemObcfrIsblockchained: 'N',
inpemObposcsCopyTerminal: 'N',
inpemPossBusinessdate: '27-11-2020',
inpemPossClosesession: 'N',
inpemPossOpensession: 'N',
inpemPossSession: 'N',
inpemPossStoreopen: null,
inpfullinvdocnoPrefix: 'CAISSE_37_99',
inpfullinvlastassignednum: '0',
inpfullretinvdocnoPrefix: 'CAISSE_37_99',
inpfullretinvlastassignednum: '0',
inphardwareurl: 'http://localhost:8090/printer',
inpisactive: 'Y',
inpislinked: 'Y',
inpismaster: 'N',
inpkeyColumnId: 'Obpos_Applications_ID',
inplastassignednum: '369',
inpmasterterminalId: null,
inpname: 'CAISSE_37_99_Automate',
inpobposApplicationsId: 'AE765712BBCC47669475A5478EEFA8B3',
inpobposCBpartnerLocId: '9AE0222DE3AD46498CFBB360DD1ADAD4',
inpobposTerminaltypeId: 'B5AC8D0ED0654B89AAC1A299AD40B269',
inpopenhardwareurl: 'N',
inporderdocnoPrefix: 'CAISSE_37_99',
inpprintertype: 'HWM',
inpprintoffline: 'N',
inpquotationdocnoPrefix: 'CAISSE_37_99',
inpquotationslastassignednum: '0',
inpreturndocnoPrefix: '37_99R',
inpreturnslastassignednum: '1',
inpscaleurl: null,
inpsimpinvdocnoPrefix: 'CAISSE_37_99SINV',
inpsimpinvlastassignednum: '0',
inpsimpretinvdocnoPrefix: 'CAISSE_37_99',
inpsimpretinvlastassignednum: '0',
inpterminalKeyId: 'CAISSE_37_99',
inpterminalLastbenchmark: null,
inpterminalLastcachegeneration: '26-11-2020 15:46:11',
inpterminalLastcashupcompleted: '17-03-2021 13:55:05',
inpterminalLastfullrefresh: null,
inpterminalLasthwmjavainfo: 'Java(TM) SE Runtime Environment (build 1.8.0_271-b09)',
inpterminalLasthwmrevision: '58d64521ad1b',
inpterminalLasthwmversion: '1.0.5600',
inpterminalLastincrefresh: null,
inpterminalLastjsgeneration: null,
inpterminalLastlogindate: null,
inpterminalLastloginuser: 'B728314713644F8EBD2F6E80507D8E94',
inpterminalLastordersynchronized: null,
inpterminalLastticketloaded: null,
inpterminalLasttimeinoffline: '16-10-2020 09:21:45',
inpterminalLasttimeinonline: null,
inpunlinkdevice: 'N',
inpvalue: '990037',
inpwindowId: 'FF80818132F311740132F322B8CD0048',
keyColumnName: 'Obpos_Applications_ID',
keyProperty: 'id',
keyPropertyType: '_id_13',
_buttonValue: 'DONE',
_params: {}
}
})
.then((responseactions) => {
expect(responseactions.status).to.eq(200)
cy.log(responseactions.body)
});
but if i use a parameter, it is ko.
cy.request({
method: 'POST',
url: surl,
log : true,
auth: {
user: 'xxxx',
pass: 'xxxx'
},
headers: {
//'Content-Type': 'application/json; charset=utf-8',
},
body:{
sbody
}
})
.then((responseactions) => {
expect(responseactions.status).to.eq(200)
cy.log(responseactions.body)
});
I would guess that sbody is
const sbody = {
Obpos_Applications_ID: 'AE765712BBCC47669475A5478EEFA8B3',
inpKeyName: 'inpobposApplicationsId',
...
}
If so you want
cy.request({
method: 'POST',
url: surl,
log : true,
auth: {
user: 'xxxx',
pass: 'xxxx'
},
headers: {
//'Content-Type': 'application/json; charset=utf-8',
},
body: sbody
})
.then((responseactions) => {
expect(responseactions.status).to.eq(200)
cy.log(responseactions.body)
});
]
Can I achieve the chart like the above with kendo? The idea is the "line" and "Longdash" type in one line.
Any help/suggestion would be very much appreciated.
You could have separate series for the dashed lines and hide them from legend:
series: [{
name: "India",
data: [3.907, 7.943, 7.848, 9.284, 9.263, 9.801, 3.890, 8.238, 9.552, null]
},{
name: "World",
data: [1.988, 2.733, 3.994, 3.464, 4.001, 3.939, 1.333, -2.245, 4.339, null]
},{
name: "India-predict",
data: [null, null, null, null, null, null, null, null, 9.552, 10.855],
dashType: "dash",
visibleInLegend: false,
color: "red"
},{
name: "World-predict",
data: [null, null, null, null, null, null, null, null, 4.339, 5.727],
dashType: "dash",
visibleInLegend: false,
color: "red"
}],
DEMO
I have the following models in my Laravel project
Merchant
Deals
Deal Votes
Deal Clicks
Deal Deal Types
Merchant Rating
This is how my Merchants Model looks like
class Merchants extends Model
{
//
public function deals()
{
return $this->hasMany('App\Deals', 'merchant_id', 'merchant_id');
}
}
Deals Model
class Deals extends Model
{
//
public function clicks()
{
return $this->hasMany('App\Clicks', 'deal_id', 'deal_id');
}
public function merchants()
{
return $this->hasOne('App\Merchants', 'deal_id', 'deal_id');
}
public function votes()
{
return $this->hasMany('App\Deal_votes', 'deal_id', 'deal_id');
}
public function deal_dealtypes()
{
return $this->hasMany('App\Deal_dealtypes', 'deal_id', 'deal_id');
}
}
Merchant Rating Model
public function merchants()
{
return $this->belongsTo('App\Merchants', 'merchant_id', 'merchant_id');
}
For a specific Merchant Landing page, I am trying to get some Merchant info, deals tied to the merchant, count of votes and clicks for each Deal. This is what I have done so far
$merchant = Merchants::where('merchant_url_text', $merchant_url_text)
-> with('categories' ,'deals','deals.votes','deals.clicks', 'deals.deal_dealtypes')
-> first();
This however is returning Merchant Info, Deal Info, All the Votes records tied to the Deal and all the clicks tied to each deal.
Attached sample data response I am getting
{
merchant_id: 6605,
master_merchant_id: null,
skimlinks_id: null,
merchant_name: "Groupon",
network: "cj",
network_id: "",
network_notes: null,
dual_network: null,
related_merchants: null,
affiliate_link: "http://api.coupilia.com/merchants/?aid=1423&mid=6605",
skimlinks_url: null,
fmtcurl: null,
merchant_homepage_url: "www.groupon.com?z=dealpage",
status: null,
selected_status: null,
relationship_status: null,
primary_country: "US",
apofpo: null,
primary_category: null,
subcategories: null,
special_payment_options: null,
mobile_certified: null,
logos: "",
custom_logo: "https://res-5.cloudinary.com/dhhntbusx/image/upload/t_media_lib_thumb/v1475206550/Groupon-coupons_mzjdm8.jpg",
custom_description: null,
added: null,
lastupdated: null,
merchant_url_text: "groupon.com",
about: "",
primary_category_id: "43",
parent_merchant_id: null,
skimlinks_ids: null,
custom_merchant_name: null,
ship_to_countries: "",
created_at: "2016-10-07 08:04:12",
updated_at: "2016-10-07 08:04:12",
categories: {
id: 43,
slug: "social",
category_name: "Social",
category_url_name: "social",
category_parent_id: null,
category_grandparent_id: null,
created_at: "2016-10-07 08:04:03",
updated_at: "2016-10-07 08:04:03"
},
deals: [
{
deal_id: 875438,
merchant_name: "Groupon",
merchant_id: 6605,
status: null,
deal_text: "Save Up To 90% Off Local Restaurants, Shops, Events And More",
restrictions: "",
coupon_code: "",
deal_start_date: "1/31/2016",
deal_end_date: "11/6/2016",
discount_type: null,
deal_type: "deal",
affiliate_url: "",
final_sale_price: null,
was_price: null,
discount: null,
percent_off: null,
dollars_off: null,
network: null,
image: null,
skimlinks_url: null,
fmtcurl: null,
created: null,
lastupdated: null,
threshold: null,
rank: "3",
starred: null,
master_merchant_id: null,
brands: null,
local: null,
link_id: null,
direct_url: null,
pixel_html: null,
created_at: "2016-10-07 08:05:26",
updated_at: "2016-10-07 08:05:26",
votes: [
{
id: 2,
deal_id: 875438,
vote: 1,
user_id: 0,
uuid: "ad63d5a0-2582-11e6-9a1c-49da886e8d6c",
created_at: "2016-10-12 05:23:57",
updated_at: "2016-10-12 05:23:57"
},
{
id: 5,
deal_id: 875438,
vote: 1,
user_id: 0,
uuid: "bde41ea0-903c-11e6-b93b-51bc5393a427",
created_at: "2016-10-12 05:28:50",
updated_at: "2016-10-12 05:28:50"
}
],
clicks: [
{
id: 1,
tracking_id: null,
merchant_id: null,
deal_id: "875438",
user_id: null,
user_tracking_id: null,
referring_url: "http://trystin.app:8000/deals-coupons/groupon.com",
referring_domain: null,
page_type: null,
page_url: null,
utm_source: null,
utm_medium: null,
utm_term: null,
utm_campaign_id: null,
os: "OS X",
ip_address: "10.0.2.2",
browser: "Chrome",
initial_referring_domain: null,
referring_keyword: null,
deal_position: null,
click_type: null,
created_at: "2016-10-12 02:19:59",
updated_at: "2016-10-12 02:19:59"
},
{
id: 12,
tracking_id: null,
merchant_id: null,
deal_id: "875438",
user_id: null,
user_tracking_id: null,
referring_url: "http://trystin.app:8000/deals-coupons/groupon.com",
referring_domain: null,
page_type: null,
page_url: null,
utm_source: null,
utm_medium: null,
utm_term: null,
utm_campaign_id: null,
os: "OS X",
ip_address: "10.0.2.2",
browser: "Chrome",
initial_referring_domain: null,
referring_keyword: null,
deal_position: null,
click_type: null,
created_at: "2016-10-21 03:41:11",
updated_at: "2016-10-21 03:41:11"
},
{
id: 15,
tracking_id: null,
merchant_id: null,
deal_id: "875438",
user_id: null,
user_tracking_id: null,
referring_url: "http://trystin.app:8000/deals-coupons/groupon.com",
referring_domain: null,
page_type: null,
page_url: null,
utm_source: null,
utm_medium: null,
utm_term: null,
utm_campaign_id: null,
os: "OS X",
ip_address: "10.0.2.2",
browser: "Chrome",
initial_referring_domain: null,
referring_keyword: null,
deal_position: null,
click_type: null,
created_at: "2016-10-21 03:55:33",
updated_at: "2016-10-21 03:55:33"
},
{
id: 16,
tracking_id: null,
merchant_id: null,
deal_id: "875438",
user_id: null,
user_tracking_id: null,
referring_url: "http://trystin.app:8000/deals-coupons/groupon.com",
referring_domain: null,
page_type: null,
page_url: null,
utm_source: null,
utm_medium: null,
utm_term: null,
utm_campaign_id: null,
os: "OS X",
ip_address: "10.0.2.2",
browser: "Chrome",
initial_referring_domain: null,
referring_keyword: null,
deal_position: null,
click_type: null,
created_at: "2016-10-21 04:06:08",
updated_at: "2016-10-21 04:06:08"
}
],
deal_dealtypes: [
{
id: 1888,
deal_id: "875438",
dealtype_id: "3",
created_at: "2016-10-07 08:05:26",
updated_at: "2016-10-07 08:05:26"
}
]
},
}
I need some help with the following
Get limited fields and not all fields tied to Merchant
Get limited fields from deals object
Get Count of Votes and Clicks for each deal in the response
To get limited fields you can use select() function and to get counts you can use withCount() function.
So your query will be as:
$merchant = Merchants::where('merchant_url_text', $merchant_url_text)
->select('id', 'name')
->with(['deals' => function($q) {
$q->select('id', 'name')
->with('votes','clicks', 'deal_dealtypes')
->withCount('votes')
->withCount('clicks');
}])
->with('categories')
-> first();