unable to insert data in elasticsearch - python-2.7

I have some data in a dictionary. The sample of data is as shown below. when I tried to insert this data of dictionary to elasticsearch. It returns me the error. what I am doing wrong
doc={
'pdpData.addDate': 1453718315L,
'pdpData.ageGroup': 'Adults-Women',
'pdpData.articleAttributes.Body Shape ID': 'Shape ID 424,Shape ID 333,Shape ID 324,Shape ID 443',
'pdpData.articleAttributes.Brand Fit Name': 'NA',
'pdpData.articleAttributes.Closure': 'Elasticated',
'pdpData.articleAttributes.Fabric': 'Polyester',
'pdpData.articleAttributes.Fabric 2': 'NA',
'pdpData.articleAttributes.Fabric 3': 'NA',
'pdpData.articleAttributes.Fit': 'Regular',
'pdpData.articleAttributes.Length': 'Long',
'pdpData.articleAttributes.Occasion': 'Casual',
'pdpData.articleAttributes.Pattern': 'Printed',
'pdpData.articleAttributes.Print / Pattern Type': 'Others',
'pdpData.articleAttributes.Surface Styling / Features': 'NA',
'pdpData.articleAttributes.Type': 'Palazzos',
'pdpData.articleAttributes.Waist Rise': 'Mid',
'pdpData.articleNumber': 'P700418XL-Red-1193441',
'pdpData.articleType.active': True,
'pdpData.articleType.filterOrder': 84L,
'pdpData.articleType.id': 78L,
'pdpData.articleType.isExchangeable': True,
'pdpData.articleType.isFragile': False,
'pdpData.articleType.isHazmat': False,
'pdpData.articleType.isJewellery': False,
'pdpData.articleType.isLarge': False,
'pdpData.articleType.isReturnable': True,
'pdpData.articleType.isTryAndBuyEnabled': True,
'pdpData.articleType.pickupEnabled': True,
'pdpData.articleType.socialSharingEnabled': True,
'pdpData.articleType.typeCode': 'TRSR',
'pdpData.articleType.typeName': 'Trousers',
'pdpData.baseColour': 'Maroon',
'pdpData.brandDetailsEntry.id': 7991L,
'pdpData.brandDetailsEntry.name': 'Trend Arrest',
'pdpData.brandName': 'Trend Arrest',
'pdpData.catalogAddDate': 1468847698L,
'pdpData.catalogDate': 1453964982L,
'pdpData.codEnabled': 'Y',
'pdpData.colour1': 'NA',
'pdpData.colour2': 'NA',
'pdpData.comments': 'westernwearfest-topsellers2016',
'pdpData.crossLinks': [
{
'key': 'More Trousers by Trend Arrest',
'value': 'trousers?f=brand:Trend Arrest::gender:women',
},
{
'key': 'More Maroon Trousers',
'value': 'trousers?f=colour:Maroon::gender:women',
},
{'key': 'More Trousers', 'value': 'trousers?f=gender:women'},
],
'pdpData.discountData.discountAmount': 649.5,
'pdpData.discountData.discountFunding': 'vendor-EOSS',
'pdpData.discountData.discountId': 912071L,
'pdpData.discountData.discountLimit': 30L,
'pdpData.discountData.discountModifiedDate': 1479460272186L,
'pdpData.discountData.discountPercent': 50L,
'pdpData.discountData.discountRuleHistoryId': 1548747L,
'pdpData.discountData.discountRuleId': 912089L,
'pdpData.discountData.discountText.hasFreeItem': False,
'pdpData.discountData.discountText.text': '(50% OFF)',
'pdpData.discountData.discountToolTipText.hasFreeItem': False,
'pdpData.discountData.discountToolTipText.text': 'Buy this item and get <em>50% </em> off',
'pdpData.discountData.discountType': 1L,
'pdpData.discountData.fundingPercentage': 60L,
'pdpData.discountData.icon': 'Flat_Cart_Icon',
'pdpData.discountData.id': 'Flat_Cart_P',
'pdpData.discountData.styleType': 'Style',
'pdpData.discountedPrice': 649L,
'pdpData.fashionType': 'Fashion',
'pdpData.gender': 'Women',
'pdpData.id': 1193441L,
'pdpData.isFlatShotAvailable': 0L,
'pdpData.landingPageUrl': 'Trousers/Trend-Arrest/Trend-Arrest-Maroon-Printed-Palazzo-Trousers/1193441/buy',
'pdpData.masterCategory.active': True,
'pdpData.masterCategory.filterOrder': 0L,
'pdpData.masterCategory.id': 9L,
'pdpData.masterCategory.isExchangeable': True,
'pdpData.masterCategory.isFragile': False,
'pdpData.masterCategory.isHazmat': False,
'pdpData.masterCategory.isJewellery': False,
'pdpData.masterCategory.isLarge': False,
'pdpData.masterCategory.isReturnable': True,
'pdpData.masterCategory.isTryAndBuyEnabled': True,
'pdpData.masterCategory.pickupEnabled': True,
'pdpData.masterCategory.socialSharingEnabled': True,
'pdpData.masterCategory.typeCode': '',
'pdpData.masterCategory.typeName': 'Apparel',
'pdpData.modifiedDate': 1532709720000L,
'pdpData.myntraRating': 0L,
'pdpData.navigationId': 0L,
'pdpData.price': 1299L,
'pdpData.productDescriptors.description.descriptorType': 'description',
'pdpData.productDescriptors.description.value': '<p>A pair of maroon printed mid-rise palazzo trousers, has an elasticated waistband, flared hems</p>',
'pdpData.productDescriptors.materials_care_desc.descriptorType': 'materials_care_desc',
'pdpData.productDescriptors.materials_care_desc.value': '<p>Polyester<br>Machine-wash cold</p>',
'pdpData.productDescriptors.size_fit_desc.descriptorType': 'size_fit_desc',
'pdpData.productDescriptors.size_fit_desc.value': '<p>The model (height 5\'8" and waist 28") is wearing a size 28</p>',
'pdpData.productDescriptors.style_note.descriptorType': 'style_note',
'pdpData.productDescriptors.style_note.value': '<p>Look fabulous and trendy as you step out in this pair of palazzo trousers. Team it with a top or a crop top and pumps for a chic ensemble.</p>',
'pdpData.productDisplayName': 'Trend Arrest Maroon Printed Palazzo Trousers',
'pdpData.productTag': 'Trend Arrest,JIT,ss16launch-women-alloverprintsnew,ss16launch-women-widelegpants,ss16launch-women-alloverprintsnew,HH10FEB16,ss16launch-women-alloverprintsnew,rock-bohemian-style,skirts-for-casual-day-out,nude-pumps-complete-outfit,new-arrivals-offer-10apr,casual-wear-offer-10apr,new-styles-offer-14apr,new-arrival-offer-apr16,grand-premium-30-to-50-off,rs-500-off-22may,new-arrivals-offer-22may,women-western-rfm-2016,rs-500-off-28may,500rs-1jun,rs-500-off-5jun,rs-500-off-june-pn,college-look-print-madness,College-store-pallazos-leggings-women,rs-500-off-26june,college-store,College-store-ethnic-bold-women,500rs-5jul,college-store-view-all,rs-500-off-10jul,rs500-off-17july,500-off-26jul,500-rs-off-10aug,rakhi-store-skirts-palazzos,rs500-off-17aug,inb-august,top-at-august,rs-500-24aug,tat-styles-31aug,off-1000-500-8sep,500-13sep,bottomwear-pre-bbd-sale,bbd-pre-sale-2016,bbd-pre-sale-categories-2016,bbd-one-last,diwali-women-western-oct,wedding-bride-honeymoon-jeans-trousers,myntra-open-coupon-offer,new-customer-Offer,wedding-bride-honeymoon-pack-list-all,ola-offer-nov16,westernwearfest-topsellers2016',
'pdpData.productTypeId': 367L,
'pdpData.recommendations.alsoPopular': [
'append andcat in subtemplate ALL with Women,Apparel',
],
'pdpData.recommendations.matchWith': [
'append andcat in subtemplate ALL with Women',
'append orcat in subtemplate ALL with Shirts',
],
'pdpData.season': 'Summer',
'pdpData.styleImages.back.domain': 'http://assets.myntassets.com/',
'pdpData.styleImages.back.imageType': 'back',
'pdpData.styleImages.back.imageURL': 'http://assets.myntassets.com/assets/images/1193441/2016/1/27/11453879129093-Trend-Arrest-Women-Trousers-8751453879128667-3.jpg',
'pdpData.styleImages.back.path': 'http://assets.myntassets.com/assets/images/1193441/2016/1/27/11453879129093-Trend-Arrest-Women-Trousers-8751453879128667-3.jpg',
'pdpData.styleImages.back.relativePath': 'assets/images/1193441/2016/1/27/11453879129093-Trend-Arrest-Women-Trousers-8751453879128667-3.jpg',
'pdpData.styleImages.back.resolutionFormula': 'h_($height),q_($qualityPercentage),w_($width)/v1/assets/images/1193441/2016/1/27/11453879129093-Trend-Arrest-Women-Trousers-8751453879128667-3.jpg',
'pdpData.styleImages.back.resolutions.1080X1440': 'http://assets.myntassets.com/h_1440,q_95,w_1080/v1/assets/images/1193441/2016/1/27/11453879129093-Trend-Arrest-Women-Trousers-8751453879128667-3.jpg',
'pdpData.styleImages.back.resolutions.1080X1440Xmini': 'http://assets.myntassets.com/h_1440,q_95,w_1080/v1/assets/images/1193441/2016/1/27/11453879129093-Trend-Arrest-Women-Trousers-8751453879128667-3_mini.jpg',
'pdpData.styleImages.back.resolutions.125X161': 'http://assets.myntassets.com/h_161,q_95,w_125/v1/assets/images/1193441/2016/1/27/11453879129093-Trend-Arrest-Women-Trousers-8751453879128667-3.jpg',
'pdpData.styleImages.back.resolutions.125X161Xmini': 'http://assets.myntassets.com/h_161,q_95,w_125/v1/assets/images/1193441/2016/1/27/11453879129093-Trend-Arrest-Women-Trousers-8751453879128667-3_mini.jpg',
'pdpData.styleImages.back.resolutions.150X200': 'http://assets.myntassets.com/h_200,q_95,w_150/v1/assets/images/1193441/2016/1/27/11453879129093-Trend-Arrest-Women-Trousers-8751453879128667-3.jpg',
'pdpData.styleImages.back.resolutions.150X200Xmini': 'http://assets.myntassets.com/h_200,q_95,w_150/v1/assets/images/1193441/2016/1/27/11453879129093-Trend-Arrest-Women-Trousers-8751453879128667-3_mini.jpg',
'pdpData.styleImages.back.resolutions.180X240': 'http://assets.myntassets.com/h_240,q_95,w_180/v1/assets/images/1193441/2016/1/27/11453879129093-Trend-Arrest-Women-Trousers-8751453879128667-3.jpg',
'pdpData.styleImages.back.resolutions.180X240Xmini': 'http://assets.myntassets.com/h_240,q_95,w_180/v1/assets/images/1193441/2016/1/27/11453879129093-Trend-Arrest-Women-Trousers-8751453879128667-3_mini.jpg',
'pdpData.styleImages.back.resolutions.360X480': 'http://assets.myntassets.com/h_480,q_95,w_360/v1/assets/images/1193441/2016/1/27/11453879129093-Trend-Arrest-Women-Trousers-8751453879128667-3.jpg',
'pdpData.styleImages.back.resolutions.360X480Xmini': 'http://assets.myntassets.com/h_480,q_95,w_360/v1/assets/images/1193441/2016/1/27/11453879129093-Trend-Arrest-Women-Trousers-8751453879128667-3_mini.jpg',
'pdpData.styleImages.back.resolutions.48X64': 'http://assets.myntassets.com/h_64,q_95,w_48/v1/assets/images/1193441/2016/1/27/11453879129093-Trend-Arrest-Women-Trousers-8751453879128667-3.jpg',
'pdpData.styleImages.back.resolutions.48X64Xmini': 'http://assets.myntassets.com/h_64,q_95,w_48/v1/assets/images/1193441/2016/1/27/11453879129093-Trend-Arrest-Women-Trousers-8751453879128667-3_mini.jpg',
'pdpData.styleImages.back.resolutions.81X108': 'http://assets.myntassets.com/h_108,q_95,w_81/v1/assets/images/1193441/2016/1/27/11453879129093-Trend-Arrest-Women-Trousers-8751453879128667-3.jpg',
'pdpData.styleImages.back.resolutions.81X108Xmini': 'http://assets.myntassets.com/h_108,q_95,w_81/v1/assets/images/1193441/2016/1/27/11453879129093-Trend-Arrest-Women-Trousers-8751453879128667-3_mini.jpg',
'pdpData.styleImages.back.securedDomain': 'https://secureassets.myntassets.com/',
'pdpData.styleImages.back.servingUploaderType': 'CL',
'pdpData.styleImages.back.storedUploaderType': 'CL',
'pdpData.styleImages.back.supportedResolutions': '1080X1440,540X720,360X480,48X64,81X108',
'pdpData.styleImages.default.domain': 'http://assets.myntassets.com/',
'pdpData.styleImages.default.imageType': 'default',
'pdpData.styleImages.default.imageURL': 'http://assets.myntassets.com/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1.jpg',
'pdpData.styleImages.default.path': 'http://assets.myntassets.com/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1.jpg',
'pdpData.styleImages.default.relativePath': 'assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1.jpg',
'pdpData.styleImages.default.resolutionFormula': 'h_($height),q_($qualityPercentage),w_($width)/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1.jpg',
'pdpData.styleImages.default.resolutions.1080X1440': 'http://assets.myntassets.com/h_1440,q_95,w_1080/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1.jpg',
'pdpData.styleImages.default.resolutions.1080X1440Xmini': 'http://assets.myntassets.com/h_1440,q_95,w_1080/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1_mini.jpg',
'pdpData.styleImages.default.resolutions.125X161': 'http://assets.myntassets.com/h_161,q_95,w_125/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1.jpg',
'pdpData.styleImages.default.resolutions.125X161Xmini': 'http://assets.myntassets.com/h_161,q_95,w_125/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1_mini.jpg',
'pdpData.styleImages.default.resolutions.150X200': 'http://assets.myntassets.com/h_200,q_95,w_150/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1.jpg',
'pdpData.styleImages.default.resolutions.150X200Xmini': 'http://assets.myntassets.com/h_200,q_95,w_150/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1_mini.jpg',
'pdpData.styleImages.default.resolutions.180X240': 'http://assets.myntassets.com/h_240,q_95,w_180/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1.jpg',
'pdpData.styleImages.default.resolutions.180X240Xmini': 'http://assets.myntassets.com/h_240,q_95,w_180/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1_mini.jpg',
'pdpData.styleImages.default.resolutions.360X480': 'http://assets.myntassets.com/h_480,q_95,w_360/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1.jpg',
'pdpData.styleImages.default.resolutions.360X480Xmini': 'http://assets.myntassets.com/h_480,q_95,w_360/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1_mini.jpg',
'pdpData.styleImages.default.resolutions.48X64': 'http://assets.myntassets.com/h_64,q_95,w_48/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1.jpg',
'pdpData.styleImages.default.resolutions.48X64Xmini': 'http://assets.myntassets.com/h_64,q_95,w_48/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1_mini.jpg',
'pdpData.styleImages.default.resolutions.81X108': 'http://assets.myntassets.com/h_108,q_95,w_81/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1.jpg',
'pdpData.styleImages.default.resolutions.81X108Xmini': 'http://assets.myntassets.com/h_108,q_95,w_81/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1_mini.jpg',
'pdpData.styleImages.default.securedDomain': 'https://secureassets.myntassets.com/',
'pdpData.styleImages.default.servingUploaderType': 'CL',
'pdpData.styleImages.default.storedUploaderType': 'CL',
'pdpData.styleImages.default.supportedResolutions': '1080X1440,540X720,180X240,360X480,150X200,96X128,81X108,48X64',
'pdpData.styleImages.default_deprecated.domain': 'http://myntra.myntassets.com/',
'pdpData.styleImages.default_deprecated.imageType': 'default_deprecated',
'pdpData.styleImages.default_deprecated.imageURL': 'http://myntra.myntassets.com/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1.jpg',
'pdpData.styleImages.default_deprecated.path': 'http://myntra.myntassets.com/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1.jpg',
'pdpData.styleImages.default_deprecated.relativePath': 'assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1.jpg',
'pdpData.styleImages.default_deprecated.resolutionFormula': 'assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1_($width)_($height).jpg',
'pdpData.styleImages.default_deprecated.resolutions.1080X1440': 'http://myntra.myntassets.com/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1_1080_1440.jpg',
'pdpData.styleImages.default_deprecated.resolutions.1080X1440Xmini': 'http://myntra.myntassets.com/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1_1080_1440_mini.jpg',
'pdpData.styleImages.default_deprecated.resolutions.125X161': 'http://myntra.myntassets.com/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1_150_200.jpg',
'pdpData.styleImages.default_deprecated.resolutions.125X161Xmini': 'http://myntra.myntassets.com/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1_150_200_mini.jpg',
'pdpData.styleImages.default_deprecated.resolutions.150X200': 'http://myntra.myntassets.com/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1_150_200.jpg',
'pdpData.styleImages.default_deprecated.resolutions.150X200Xmini': 'http://myntra.myntassets.com/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1_150_200_mini.jpg',
'pdpData.styleImages.default_deprecated.resolutions.180X240': 'http://myntra.myntassets.com/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1_180_240.jpg',
'pdpData.styleImages.default_deprecated.resolutions.180X240Xmini': 'http://myntra.myntassets.com/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1_180_240_mini.jpg',
'pdpData.styleImages.default_deprecated.resolutions.360X480': 'http://myntra.myntassets.com/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1_360_480.jpg',
'pdpData.styleImages.default_deprecated.resolutions.360X480Xmini': 'http://myntra.myntassets.com/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1_360_480_mini.jpg',
'pdpData.styleImages.default_deprecated.resolutions.48X64': 'http://myntra.myntassets.com/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1_48_64.jpg',
'pdpData.styleImages.default_deprecated.resolutions.48X64Xmini': 'http://myntra.myntassets.com/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1_48_64_mini.jpg',
'pdpData.styleImages.default_deprecated.resolutions.81X108': 'http://myntra.myntassets.com/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1_81_108.jpg',
'pdpData.styleImages.default_deprecated.resolutions.81X108Xmini': 'http://myntra.myntassets.com/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1_81_108_mini.jpg',
'pdpData.styleImages.default_deprecated.securedDomain': 'https://myntrawebimages.s3.amazonaws.com/',
'pdpData.styleImages.default_deprecated.servingUploaderType': 'S3',
'pdpData.styleImages.default_deprecated.storedUploaderType': 'S3',
'pdpData.styleImages.default_deprecated.supportedResolutions': '1080X1440,540X720,180X240,360X480,150X200,96X128,81X108,48X64',
'pdpData.styleImages.front.domain': 'http://assets.myntassets.com/',
'pdpData.styleImages.front.imageType': 'front',
'pdpData.styleImages.front.servingUploaderType': 'CL',
'pdpData.styleImages.front.storedUploaderType': 'CL',
'pdpData.styleImages.front.supportedResolutions': '1080X1440,540X720,360X480,48X64,81X108',
'pdpData.styleImages.left.domain': 'http://assets.myntassets.com/',
'pdpData.styleImages.left.servingUploaderType': 'CL',
'pdpData.styleImages.left.storedUploaderType': 'CL',
'pdpData.styleImages.left.supportedResolutions': '1080X1440,540X720,360X480,48X64,81X108',
'pdpData.styleImages.right.domain': 'http://assets.myntassets.com/',
'pdpData.styleImages.right.imageType': 'right',
'pdpData.styleImages.right.servingUploaderType': 'CL',
'pdpData.styleImages.right.storedUploaderType': 'CL',
'pdpData.styleImages.right.supportedResolutions': '1080X1440,540X720,360X480,48X64,81X108',
'pdpData.styleImages.search.domain': 'http://assets.myntassets.com/',
'pdpData.styleImages.search.imageType': 'search',
'pdpData.styleImages.search.imageURL': 'http://assets.myntassets.com/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1.jpg',
'pdpData.styleImages.search.path': 'http://assets.myntassets.com/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1.jpg',
'pdpData.styleImages.search.relativePath': 'assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1.jpg',
'pdpData.styleImages.search.resolutionFormula': 'h_($height),q_($qualityPercentage),w_($width)/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1.jpg',
'pdpData.styleImages.search.resolutions.1080X1440': 'http://assets.myntassets.com/h_1440,q_95,w_1080/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1.jpg',
'pdpData.styleImages.search.resolutions.1080X1440Xmini': 'http://assets.myntassets.com/h_1440,q_95,w_1080/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1_mini.jpg',
'pdpData.styleImages.search.resolutions.125X161': 'http://assets.myntassets.com/h_161,q_95,w_125/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1.jpg',
'pdpData.styleImages.search.resolutions.125X161Xmini': 'http://assets.myntassets.com/h_161,q_95,w_125/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1_mini.jpg',
'pdpData.styleImages.search.resolutions.150X200': 'http://assets.myntassets.com/h_200,q_95,w_150/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1.jpg',
'pdpData.styleImages.search.resolutions.150X200Xmini': 'http://assets.myntassets.com/h_200,q_95,w_150/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1_mini.jpg',
'pdpData.styleImages.search.resolutions.180X240': 'http://assets.myntassets.com/h_240,q_95,w_180/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1.jpg',
'pdpData.styleImages.search.resolutions.180X240Xmini': 'http://assets.myntassets.com/h_240,q_95,w_180/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1_mini.jpg',
'pdpData.styleImages.search.resolutions.360X480': 'http://assets.myntassets.com/h_480,q_95,w_360/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1.jpg',
'pdpData.styleImages.search.resolutions.360X480Xmini': 'http://assets.myntassets.com/h_480,q_95,w_360/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1_mini.jpg',
'pdpData.styleImages.search.resolutions.48X64': 'http://assets.myntassets.com/h_64,q_95,w_48/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1.jpg',
'pdpData.styleImages.search.resolutions.48X64Xmini': 'http://assets.myntassets.com/h_64,q_95,w_48/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1_mini.jpg',
'pdpData.styleImages.search.resolutions.81X108': 'http://assets.myntassets.com/h_108,q_95,w_81/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1.jpg',
'pdpData.styleImages.search.resolutions.81X108Xmini': 'http://assets.myntassets.com/h_108,q_95,w_81/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1_mini.jpg',
'pdpData.styleImages.search.securedDomain': 'https://secureassets.myntassets.com/',
'pdpData.styleImages.search.servingUploaderType': 'CL',
'pdpData.styleImages.search.storedUploaderType': 'CL',
'pdpData.styleImages.search.supportedResolutions': '1080X1440,540X720,180X240,360X480,150X200,96X128,81X108,48X64',
'pdpData.styleImages.size_representation.imageType': 'size_representation',
'pdpData.styleImages.size_representation.imageURL': 'images/style/sizechart/Trousers_Adults-Women.png',
'pdpData.styleImages.top.domain': 'http://assets.myntassets.com/',
'pdpData.styleImages.top.imageType': 'top',
'pdpData.styleImages.top.supportedResolutions': '1080X1440,540X720,360X480,48X64,81X108',
'pdpData.styleOptions': [
{
'active': True,
'allSize': '28',
'available': True,
'id': 9677369,
'inventoryCount': 27,
'name': 'Size',
'skuAvailabilityDetailMap': {
'21': {
'availableCount': 27,
'availableInWarehouses': '28',
'leadTime': 0,
'sellerid': 21,
'sellername': 'Health & Happiness Pvt Ltd',
'storeid': 1,
'supplyType': 'ON_HAND',
},
},
'skuId': 9677369,
'taxEntry': {'skuId': 9677369, 'taxRate': 5.25},
'unifiedSize': '28',
'unifiedSizeValue': '28',
'value': 'S',
'warehouseIdToItemCountMap': {},
},
{
'active': True,
'allSize': '30',
'available': True,
'id': 9677372,
'inventoryCount': 3,
'name': 'Size',
'skuAvailabilityDetailMap': {
'21': {
'availableCount': 3,
'availableInWarehouses': '96',
'leadTime': 3,
'sellerid': 21,
'sellername': 'Health & Happiness Pvt Ltd',
'storeid': 1,
'supplyType': 'JUST_IN_TIME',
},
},
'skuId': 9677372,
'taxEntry': {'skuId': 9677372, 'taxRate': 5},
'unifiedSize': '30',
'unifiedSizeValue': '30',
'value': 'M',
'warehouseIdToItemCountMap': {},
},
{
'active': True,
'allSize': '32',
'available': True,
'id': 9677375,
'inventoryCount': 4,
'name': 'Size',
'skuAvailabilityDetailMap': {
'21': {
'availableCount': 4,
'availableInWarehouses': '28',
'leadTime': 0,
'sellerid': 21,
'sellername': 'Health & Happiness Pvt Ltd',
'storeid': 1,
'supplyType': 'ON_HAND',
},
},
'skuId': 9677375,
'taxEntry': {'skuId': 9677375, 'taxRate': 5.25},
'unifiedSize': '32',
'unifiedSizeValue': '32',
'value': 'L',
'warehouseIdToItemCountMap': {},
},
{
'active': True,
'allSize': '34',
'available': True,
'id': 9677378,
'inventoryCount': 1,
'name': 'Size',
'skuAvailabilityDetailMap': {
'21': {
'availableCount': 1,
'availableInWarehouses': '28',
'leadTime': 0,
'sellerid': 21,
'sellername': 'Health & Happiness Pvt Ltd',
'storeid': 1,
'supplyType': 'ON_HAND',
},
},
'skuId': 9677378,
'taxEntry': {'skuId': 9677378, 'taxRate': 5.25},
'unifiedSize': '34',
'unifiedSizeValue': '34',
'value': 'XL',
'warehouseIdToItemCountMap': {},
},
],
'pdpData.styleType': 'P',
'pdpData.subCategory.active': True,
'pdpData.subCategory.filterOrder': 0L,
'pdpData.subCategory.id': 29L,
'pdpData.subCategory.isExchangeable': True,
'pdpData.subCategory.isFragile': False,
'pdpData.subCategory.isHazmat': False,
'pdpData.subCategory.isJewellery': False,
'pdpData.subCategory.isLarge': False,
'pdpData.subCategory.isReturnable': True,
'pdpData.subCategory.isTryAndBuyEnabled': True,
'pdpData.subCategory.pickupEnabled': True,
'pdpData.subCategory.socialSharingEnabled': True,
'pdpData.subCategory.typeCode': '',
'pdpData.subCategory.typeName': 'Bottomwear',
'pdpData.usage': 'Casual',
'pdpData.variantName': 'Printed Palazzo Pants',
'pdpData.vat': 5.5,
'pdpData.visualTag': '',
'pdpData.weight': '0',
'pdpData.year': '2016',}
the code which I am trying
res = es.index(index = INDEX_NAME, doc_type=TYPE_NAME, id=i, body = doc)
error is as shown below
raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info)
elasticsearch.exceptions.RequestError: TransportError(400, u'mapper_parsing_exception', u'failed to parse')

Related

request.data changes in every variable

I have this code:
initial_data = dict(request.data.copy())
reserve_data = dict(request.data.copy())
print(initial_data)
for key in initial_data.keys():
merchant_data = initial_data.get(key)
for sub_key in merchant_data.keys():
if sub_key in keys_to_change:
reserve_data[key].pop(sub_key)
reserve_data[key][values_to_change.get(sub_key)] = merchant_data.get(sub_key)
print(initial_data)
As you can see, I am not changing initial_data, but it changes anyway
#before
{'22': {'domain': 'cashier.random.io', 'salt': 'ewrwerwe', 'active': 1, 'separate_cashier': '', 'additional_hosts': {}, 'tradingroom_url': '', 'crm': {'login': '', 'secret': '', 'url': ''}, 'currencies': ['USD', 'EUR'], 'payment_methods': {'12': {}}, 'processors': {}}}
#after
{'22': {'salt': 'ewrwerwe', 'separate_cashier': '', 'additional_hosts': {}, 'tradingroom_url': '', 'crm': {'login': '', 'secret':
'', 'url': ''}, 'currencies': ['USD', 'EUR'], 'payment_methods': {'12': {}}, 'processors': {}, 'host': None, 'is_active': None}}
Is there a way to avoid this? Thanks everybody
initial_data = dict(request.data.copy())
reserve_data = dict(request.data.copy())
does shallow copies of the request data.
If you're internally modifying the contents, you'll need to use copy.deepcopy instead:
initial_data = dict(copy.deepcopy(request.data))
reserve_data = dict(copy.deepcopy(request.data))

How to convert orderdict into json in python?

How to convert below orderedict into regular json ? in python?
[OrderedDict([('ins_short_name', 'MI'), ('beneficiary', []),
('benefit', 65), ('pcp', []), ('benefit_rates', 216),
('added_dependent', []), ('removed_dependent', []), ('ins_name',
'Medical Insurance'), ('plan', {'carrier_logo':
'How to create a DateTime equal to 15 minutes ago?',
'plan_type': 'HMO', 'creation_time': '2019-02-11T06:21:21.743369Z',
'plan_info_details': '', 'rx_coverage': '11', 'id': 65, 'co_pay':
'11', 'contribution_interval': None, 'updation_time':
'2019-02-11T06:21:21.743808Z', 'benefit_display_name': 'Mi1 HMO',
'carrier': 1, 'status': False, 'carrier_name': 'NHP',
'rx_information': None, 'voluntary': False, 'deductible': '11`',
'hsa_qualified_wrap_plan': False, 'benefit': 65,
'terms_and_conditions': None, 'maximum_contribution': None,
'hsa_qualified_base_plan': False, 'primary_care_physician': False,
'plan_info': ''}), ('dependent', []), ('questions',
[OrderedDict([('question', 1), ('question_type', 'radio'),
('identifier', 'Q1'), ('ref', [Decimal('1.00')])]),
OrderedDict([('question', 4), ('question_type', 'plan'),
('identifier', 'Q4'), ('ref', [Decimal('216.00')])])])]),
OrderedDict([('ins_short_name', 'AI'), ('beneficiary',
[OrderedDict([('id', 365), ('first_name', 'rer'), ('last_name',
'ere'), ('relation', 'Spouse'), ('other_relation', None), ('_type',
'Primary'), ('percentage', '100'), ('benefit', 66), ('enrollment',
357), ('creation_time', '2019-02-14T12:04:00.676078Z'),
('updation_time', '2019-02-14T12:04:33.475164Z')])]), ('benefit', 66),
('pcp', []), ('benefit_rates', None), ('added_dependent', []),
('removed_dependent', []), ('ins_name', 'Ancillary Insurance'),
('plan', {'carrier_logo':
'How to create a DateTime equal to 15 minutes ago?',
'plan_type': 'Other', 'creation_time': '2019-02-11T06:24:32.322178Z',
'plan_info_details': '', 'rx_coverage': '', 'id': 66, 'co_pay': '',
'contribution_interval': None, 'updation_time':
'2019-02-11T06:24:32.322541Z', 'benefit_display_name': 'Ai name',
'carrier': 1, 'status': False, 'carrier_name': 'NHP',
'rx_information': None, 'voluntary': True, 'deductible': '',
'hsa_qualified_wrap_plan': False, 'benefit': 66,
'terms_and_conditions': None, 'maximum_contribution': None,
'hsa_qualified_base_plan': False, 'primary_care_physician': False,
'plan_info': ''}), ('dependent', []), ('questions',
[OrderedDict([('question', 12), ('question_type', 'radio'),
('identifier', 'Q12'), ('ref', [Decimal('10.00')])])])])]

Column Chart in Google Charts is displaying bars 10 times proper height

I can't figure out why, I've triple checked that I'm passing in the right values. When I hover over any of the bars it displays the right data, but every single one of them displays at 10x scale on the graph and I can't figure out why. Here's my code if it helps:
var dashboard2 = new google.visualization.Dashboard(
document.getElementById('dashboard'));
var control2 = new google.visualization.ControlWrapper({
'controlType': 'ChartRangeFilter',
'containerId': 'control2',
'options': {
// Filter by the date axis.
'filterColumnIndex': 0,
'ui': {
'chartType': 'LineChart',
'chartOptions': {
'chartArea': {'width': '80%'},
'hAxis': {'baselineColor': 'none'}
},
// Display a single series that shows the closing value of the stock.
// Thus, this view has two columns: the date (axis) and the stock value (line series).
'chartView': {
'columns': [0, 1, 14]
},
// 1 day in milliseconds = 24 * 60 * 60 * 1000 = 86,400,000
'minRangeSize': 259200000
}
},
// Initial range: 2012-02-09 to 2012-03-20.
'state': {'range': {'start': new Date(2012, 11, 7), 'end': new Date()}}
});
var chart2 = new google.visualization.ChartWrapper({
'chartType': 'ComboChart',
'containerId': 'chart2',
'options': {
// Use the same chart area width as the control for axis alignment.
'chartArea': {'height': '80%', 'width': '80%'},
'hAxis': {'slantedText': false},
'vAxis': {'viewWindow': {'min': 0, 'max': 400}},
'title': 'Sales Made by Affiliate Name',
'seriesType': "bars",
'series': {0: {type: "line"}, 13: {type: "line"}},
'isStacked': true
},
// Convert the first column from 'date' to 'string'.
'view': {
'columns': [
{
'calc': function(dataTable, rowIndex) {
return dataTable.getFormattedValue(rowIndex, 0);
},
'type': 'string'
}, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
}
});
var jsonData2 = $.ajax({
url: "getData.php",
dataType:"json",
async: false
}).responseText;
// Create our data table out of JSON data loaded from server
var data2 = new google.visualization.DataTable(jsonData2);
dashboard2.bind(control2, chart2);
dashboard2.draw(data2);
Edit: Here's a small bit of the data at the very beginning, because I don't want to give out our data, but I suppose it might be necessary to get an idea for what is being passed in. I cut out the starting bracket for readability:
"cols":[ {"id":"","label":"Date","pattern":"","type":"date"}, {"id":"","label":"Total","pattern":"","type":"number"}, {"id":"","label":"andersce99","pattern":"","type":"number"}, {"id":"","label":"sojourn","pattern":"","type":"number"}, {"id":"","label":"warriorplus","pattern":"","type":"number"}, {"id":"","label":"potpie queen","pattern":"","type":"number"}, {"id":"","label":"60minuteaffiliate","pattern":"","type":"number"}, {"id":"","label":"bob voges","pattern":"","type":"number"}, {"id":"","label":"Grayth","pattern":"","type":"number"}, {"id":"","label":"TiffanyDow","pattern":"","type":"number"}, {"id":"","label":"AmandaT","pattern":"","type":"number"}, {"id":"","label":"Gaz Cooper","pattern":"","type":"number"}, {"id":"","label":"Sam England","pattern":"","type":"number"}, {"id":"","label":"Matthew Olson","pattern":"","type":"number"}, {"id":"","label":"Average Per Day Over Time","pattern":"","type":"number"} ],
"rows": [ {"c":[{"v":"Date(2012,11,7)","f":null},{"v":"387","f":null},{"v":"19","f":null},{"v":"275","f":null},{"v":"8","f":null},{"v":"0","f":null},{"v":"35","f":null},{"v":"3","f":null},{"v":"21","f":null},{"v":"0","f":null},{"v":"0","f":null},{"v":"0","f":null},{"v":"11","f":null},{"v":"6","f":null},{"v":"387","f":null}]},
{"c":[{"v":"Date(2012,11,8)","f":null},{"v":"98","f":null},{"v":"11","f":null},{"v":"39","f":null},{"v":"1","f":null},{"v":"0","f":null},{"v":"15","f":null},{"v":"0","f":null},{"v":"7","f":null},{"v":"9","f":null},{"v":"0","f":null},{"v":"0","f":null},{"v":"3","f":null},{"v":"6","f":null},{"v":"242.5","f":null}]},
{"c":[{"v":"Date(2012,11,9)","f":null},{"v":"58","f":null},{"v":"7","f":null},{"v":"16","f":null},{"v":"0","f":null},{"v":"0","f":null},{"v":"4","f":null},{"v":"0","f":null},{"v":"3","f":null},{"v":"10","f":null},{"v":"2","f":null},{"v":"9","f":null},{"v":"0","f":null},{"v":"2","f":null},{"v":"181","f":null}]},
{"c":[{"v":"Date(2012,11,10)","f":null},{"v":"196","f":null},{"v":"5","f":null},{"v":"8","f":null},{"v":"126","f":null},{"v":"0","f":null},{"v":"2","f":null},{"v":"35","f":null},{"v":"0","f":null},{"v":"7","f":null},{"v":"4","f":null},{"v":"3","f":null},{"v":"1","f":null},{"v":"0","f":null},{"v":"184.75","f":null}]},
{"c":[{"v":"Date(2012,11,11)","f":null},{"v":"76","f":null},{"v":"7","f":null},{"v":"5","f":null},{"v":"17","f":null},{"v":"30","f":null},{"v":"7","f":null},{"v":"1","f":null},{"v":"1","f":null},{"v":"2","f":null},{"v":"1","f":null},{"v":"4","f":null},{"v":"0","f":null},{"v":"0","f":null},{"v":"163","f":null}]},
{"c":[{"v":"Date(2012,11,12)","f":null},{"v":"48","f":null},{"v":"4","f":null},{"v":"5","f":null},{"v":"9","f":null},{"v":"20","f":null},{"v":"7","f":null},{"v":"1","f":null},{"v":"0","f":null},{"v":"0","f":null},{"v":"0","f":null},{"v":"0","f":null},{"v":"0","f":null},{"v":"0","f":null},{"v":"143.833333333","f":null}]},
{"c":[{"v":"Date(2012,11,13)","f":null},{"v":"21","f":null},{"v":"3","f":null},{"v":"2","f":null},{"v":"5","f":null},{"v":"4","f":null},{"v":"0","f":null},{"v":"0","f":null},{"v":"1","f":null},{"v":"2","f":null},{"v":"0","f":null},{"v":"1","f":null},{"v":"0","f":null},{"v":"0","f":null},{"v":"126.285714286","f":null}]},
{"c":[{"v":"Date(2012,11,14)","f":null},{"v":"12","f":null},{"v":"1","f":null},{"v":"1","f":null},{"v":"2","f":null},{"v":"4","f":null},{"v":"2","f":null},{"v":"0","f":null},{"v":"0","f":null},{"v":"0","f":null},{"v":"0","f":null},{"v":"0","f":null},{"v":"0","f":null},{"v":"0","f":null},{"v":"112","f":null}]},
{"c":[{"v":"Date(2012,11,15)","f":null},{"v":"8","f":null},{"v":"3","f":null},{"v":"0","f":null},{"v":"1","f":null},{"v":"2","f":null},{"v":"0","f":null},{"v":"0","f":null},{"v":"1","f":null},{"v":"0","f":null},{"v":"1","f":null},{"v":"0","f":null},{"v":"0","f":null},{"v":"0","f":null},{"v":"100.444444444","f":null}]}
Your data is formatted incorrectly: numbers need to be stored as numbers in the JSON, not as strings. As an example, this:
{"v":"387","f":null}
should be like this:
{"v":387,"f":null}
If you are using PHP's json_encode function to build the JSON, you can add JSON_NUMERIC_CHECK as an argument to the function call to output the numbers properly:
json_encode($myData, JSON_NUMERIC_CHECK);

google visualization change label on all values on x-axis

I have a bunch of products which I use ColumnChart to show the product name on the x-axis and then two different values that the products have on my y-axis. Since there are a bunch of products it gets pretty messy if I show all of them at once on the ColumnChart therefore I use the ChartRangeFilter Control to be able to have a window of products.
Now my problem is that ChartRangeFilter can't use strings on the axises. But I don't want to display the product id on the x-axis, so is it possible to change the lable when it is displayd?
Hope you can understand what I mean. Below is some code to test in the google code playground
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>
Google Visualization API Sample
</title>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load('visualization', '1.1', {packages: ['corechart', 'controls']});
</script>
<script type="text/javascript">
function drawVisualization() {
var dashboard = new google.visualization.Dashboard(
document.getElementById('dashboard'));
var control = new google.visualization.ControlWrapper({
'controlType': 'ChartRangeFilter',
'containerId': 'control',
'options': {
// Filter by the date axis.
'filterColumnIndex': 0,
'ui': {
'chartType': 'LineChart',
'chartOptions': {
'chartArea': {'width': '90%'},
'hAxis': {'baselineColor': 'none'}
},
'chartView': {
'columns': [0, 1, 2]
},
'minRangeSize': 1
}
},
// Initial range: 1 to 4.
'state': {'range': {'start': 1, 'end': 4}}
});
var chart = new google.visualization.ChartWrapper({
'chartType': 'ColumnChart',
'containerId': 'chart',
'options': {
// Use the same chart area width as the control for axis alignment.
'chartArea': {'height': '80%', 'width': '90%'},
'hAxis': {'slantedText': false},
'vAxis': {'viewWindow': {'min': 0, 'max': 20}},
'legend': {'position': 'none'}
}
});
var data = new google.visualization.DataTable();
data.addColumn('number', 'Product ID');
data.addColumn('number', 'value1');
data.addColumn('number', 'valu2');
data.addRow([1, 11, 12]);
data.addRow([2, 15, 12]);
data.addRow([3, 10, 11]);
data.addRow([4, 11, 9]);
data.addRow([5, 8, 12]);
data.addRow([6, 4, 9]);
data.addRow([7, 8, 15]);
data.addRow([8, 8, 11]);
data.addRow([9, 8, 9]);
dashboard.bind(control, chart);
dashboard.draw(data);
}
google.setOnLoadCallback(drawVisualization);
</script>
</head>
<body>
<div id="dashboard">
<div id="chart" style='width: 915px; height: 300px;'></div>
<div id="control" style='width: 915px; height: 50px;'></div>
</div>
</body>
</html>
Thanks in advance!
You can use a DataView to get around this problem. In the ControlWrapper, set the view.columns parameter like this:
var control = new google.visualization.ControlWrapper({
'controlType': 'ChartRangeFilter',
'containerId': 'control',
'options': {
// Filter by the date axis.
'filterColumnIndex': 0,
'ui': {
'chartType': 'LineChart',
'chartOptions': {
'chartArea': {'width': '90%'},
'hAxis': {'baselineColor': 'none'}
},
'chartView': {
'columns': [0, 1, 2]
},
'minRangeSize': 1
}
},
// Initial range: 1 to 4.
'state': {'range': {'start': 1, 'end': 4}},
view: {
columns: [{
type: 'number',
calc: function (dt, row) {
return {v: row, f: dt.getFormattedValue(row, 0)};
}
}, 1, 2]
}
});
then reverse the process in the ChartWrapper's view.columns:
var chart = new google.visualization.ChartWrapper({
'chartType': 'ColumnChart',
'containerId': 'chart',
'options': {
// Use the same chart area width as the control for axis alignment.
'chartArea': {'height': '80%', 'width': '90%'},
'hAxis': {'slantedText': false},
'vAxis': {'viewWindow': {'min': 0, 'max': 20}},
'legend': {'position': 'none'}
},
view: {
columns: [{
type: 'string',
label: data.getColumnLabel(0),
calc: function (dt, row) {
return dt.getFormattedValue(row, 0);
}
}, 1, 2]
}
});
That should get you what you want.
This code assumes you have a DataTable with 3 columns: a string (product name) and two number columns (value1 and value2). Here is a demo: http://jsfiddle.net/asgallant/55agF/
change the color of the text as of background
hAxis: {textStyle: {color: 'white'}},

How to change color of annotation text in google-charts

How do you change the color of an annotation text in Google Chart Tools LineChart ?
Here is an example
google.load('visualization', '1', {packages: ['corechart']});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('date', 'Date');
data.addColumn('number', 'Sales');
data.addColumn({id: 'title', label: 'Title', type: 'string', role: 'annotation'});
data.addRows([
[new Date(2012, 3, 5), 80, null],
[new Date(2012, 3, 12), 120, 'New Product'],
[new Date(2012, 3, 19), 80, null],
[new Date(2012, 3, 26), 65, null],
[new Date(2012, 4, 2), 70, null],
]);
var options = {
title: 'Sales by Week',
displayAnnotations: true,
hAxis: {title: 'Date',
titleTextStyle: {color: 'grey'}},
colors: ['#f07f09']
};
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
I want the line to be orange and the annotation text in grey. Currently the annotation text is orange.
No need for extra style data column and plumbing code to fill it for every row with ugly (and even incomplete above) formatting string. Only resort to separate styling column if you want to have different annotation color for the different data points.
There's a global setting, search for annotations.textStyle in https://developers.google.com/chart/interactive/docs/gallery/linechart
var options = {
annotations: {
textStyle: {
fontName: 'Times-Roman',
fontSize: 18,
bold: true,
italic: true,
// The color of the text.
color: '#871b47',
// The color of the text outline.
auraColor: '#d799ae',
// The transparency of the text.
opacity: 0.8
}
}
};
Here is a concept code for your case (notice different initialization google.charts, very important):
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
google.charts.load('current', { 'packages': ['corechart', 'line', 'bar'] });
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('date', 'Date');
data.addColumn('number', 'Sales');
data.addColumn({id: 'title', label: 'Title', type: 'string', role: 'annotation'});
data.addRows([
[new Date(2012, 3, 5), 80, null],
[new Date(2012, 3, 12), 120, 'New Product'],
[new Date(2012, 3, 19), 80, null],
[new Date(2012, 3, 26), 65, null],
[new Date(2012, 4, 2), 70, null],
]);
var options = {
chart: {
title: 'Sales by Week'
},
hAxis: {
title: 'Date',
titleTextStyle: {color: 'grey'}
},
annotations: {
textStyle: {
color: 'grey',
}
}
colors: ['#f07f09']
};
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
You can also change other text formatting of the annotation, like bold, italic, font type, etc. Here is an example where most of the text is configured to be bold:
var options = {
chart: {
title: title
},
hAxis: {
textStyle: {
bold: true
}
},
vAxis: {
format: 'decimal',
textStyle: {
bold: true
}
},
legendTextStyle: {
bold: true
},
titleTextStyle: {
bold: true
},
width: chart_width,
//theme: 'material', // material theme decreases the color contrast and sets the black color items (all text) to 171,171,171 grey -> washed out
annotations: {
alwaysOutside: true,
highContrast: true, // default is true, but be sure
textStyle: {
bold: true
}
}
};
More examples with source repo link: https://mrcsabatoth.github.io/GoogleChartsTalk/
Actually you can. Color of the annotations is the same as line color. Just put a dot in the place you want to make an annotation and set a dot's color to the desirable annotation color.
data.addColumn({type: 'string', role: 'style'});
data.addColumn({type:'string', role:'annotation'});
and then when you add data
'point { size: 14; shape-type: circle; fill-color: #63A74A','Your annotation'
See example at
http://www.marketvolume.com/stocks/stochasticsmomentumindex.asp?s=SPY&t=spdr-s-p-500
If your annotations are not "touching", ie. the points you'd like to annotate are not next to each other, you could add a second line and add the annotations to that line.
In the JSON example below I have a date and a "total balance", as well as an "Ann" line.
"cols":[
{
"id":"date",
"label":"date",
"type":"date",
"p":{
"role":"domain"
}
},
{
"id":"total-balance",
"label":"Total balance",
"type":"number",
"p":{
"role":"data"
}
},
{
"id":"ann",
"label":"Ann",
"type":"number",
"p":{
"role":"data"
}
},
{
"type":"string",
"p":{
"role":"annotation"
}
},
{
"type":"string",
"p":{
"role":"annotationText"
}
}
],
The annotation comes after the "Ann" column so it'll be added to the "Ann" data points.
In my JSON, the date and "total-balance" are always filled in. "Ann" and the annotations are usually empty:
"rows":[
{
"c":[
{
"v":"Date(2013, 0, 1)"
},
{
"v":1000
},
{
"v":null
},
{
"v":null
},
{
"v":null
}
]
},
{
"c":[
{
"v":"Date(2013, 0, 8)"
},
{
"v":1001
},
{
"v":null
},
{
"v":null
},
{
"v":null
}
]
},
When I need an annotation, the "Ann" cell gets the same value as the total balance, and the annotation is added:
{
"c":[
{
"v":"Date(2013, 1, 26)"
},
{
"v":2000
},
{
"v":2000
},
{
"v":"Something!"
},
{
"v":"Something happened here!"
}
]
},
In your GChart's configuration, you can now set two colours. One for the normal line, and one for the "Ann".
colors: ['black','red']
If you have no annotations "touching", GCharts will not draw a line between them and the points will remain "invisible", while the annotations show up at exactly the right place.
Short answer: no, you can't change the text color through standard options (you could write something to find that text in the SVG and change its color with javascript, but that is beyond my level).
You can see an answer from ASGallant on Google Groups here, and his example here.
// code borrowed from Google visualization API playground, slightly modified here
google.load('visualization', '1', {packages: ['corechart']});
google.setOnLoadCallback(drawVisualization);
function drawVisualization() {
// Create and populate the data table.
var data = new google.visualization.DataTable();
data.addColumn('string', 'x');
data.addColumn({type: 'string', role: 'annotation'});
data.addColumn({type: 'string', role: 'annotationText'});
data.addColumn('number', 'Cats');
data.addColumn('number', 'Blanket 1');
data.addColumn('number', 'Blanket 2');
data.addRow(["A", null, null, 1, 1, 0.5]);
data.addRow(["B", null, null, 2, 0.5, 1]);
data.addRow(["C", null, null, 4, 1, 0.5]);
data.addRow(["D", null, null, 8, 0.5, 1]);
data.addRow(["E", 'foo', 'foo text', 7, 1, 0.5]);
data.addRow(["F", null, null, 7, 0.5, 1]);
data.addRow(["G", null, null, 8, 1, 0.5]);
data.addRow(["H", null, null, 4, 0.5, 1]);
data.addRow(["I", null, null, 2, 1, 0.5]);
data.addRow(["J", null, null, 3.5, 0.5, 1]);
data.addRow(["K", null, null, 3, 1, 0.5]);
data.addRow(["L", null, null, 3.5, 0.5, 1]);
data.addRow(["M", null, null, 1, 1, 0.5]);
data.addRow(["N", null, null, 1, 0.5, 1]);
// Create and draw the visualization.
var chart = new google.visualization.LineChart(document.getElementById('visualization'));
chart.draw(data, {
annotation: {
1: {
style: 'line'
}
},
curveType: "function",
width: 500,
height: 400,
vAxis: {
maxValue: 10
}
});
}
The best you can do is to change the style of the line, but it doesn't look like you can currently change the color of the line.
Has this been updated using the 'style' option where one could add a new column {"type":"string","role":"style"} and in each row we would have {"v":"point {size: 4; fill-color: #3366cc;}"}? This allows the annotation to have the same color as the point/marker (which could be changed for each point) but does not allow it to be bold. One example of the data to try would be,
var data =new google.visualization.DataTable(
{
"cols":[
{"label":"Log GDP Per-Capita ","type":"number"},
{"label":"New Chart",
"type":"number"},
{"type":"string","role":"annotation"},
{"type":"string","role":"style"}
],
"rows":[
{"c":[{"v":10.21932},{"v":12.3199676},{"v":"ABW"},{"v":"point {size: 4; fill-color: #3366cc;}"}]},
{"c":[{"v":10.68416},{"v":8.4347518},{"v":"ARE"},{"v":"point {size: 4; fill-color: #3366cc;}"}]},
{"c":[{"v":9.634226},{"v":12.0774068},{"v":"ATG"},{"v":"point {size: 4; fill-color: #3366cc;}"}]},
{"c":[{"v":10.83869},{"v":1.8545959},{"v":"AUS"},{"v":"point {size: 4; fill-color: #3366cc;}"}]},
{"c":[{"v":10.7687},{"v":7.4919999},{"v":"AUT"},{"v":"point {size: 4; fill-color: #3366cc;}"}]}
]
}
);