React js: Nivo Pie chart not showing up - reactjs

i'm working in react js with nivo pie chart i'm using the exact code as provided in the documentation but when i start server the chart is not rendered and it displays empty page and there is no error in the console and server terminal.
code:
import React from 'react';
import { render } from 'react-dom'
import { ResponsivePie } from '#nivo/pie'
var data = [
{
"id": "rust",
"label": "rust",
"value": 576,
"color": "hsl(167, 70%, 50%)"
},
{
"id": "javascript",
"label": "javascript",
"value": 129,
"color": "hsl(119, 70%, 50%)"
},
{
"id": "java",
"label": "java",
"value": 422,
"color": "hsl(253, 70%, 50%)"
},
{
"id": "hack",
"label": "hack",
"value": 71,
"color": "hsl(307, 70%, 50%)"
},
{
"id": "erlang",
"label": "erlang",
"value": 354,
"color": "hsl(187, 70%, 50%)"
}
];
render((
<ResponsivePie
data={data}
margin={{
"top": 40,
"right": 80,
"bottom": 80,
"left": 80
}}
innerRadius={0.5}
padAngle={0.7}
cornerRadius={3}
colors="nivo"
colorBy="id"
borderWidth={1}
borderColor="inherit:darker(0.2)"
radialLabelsSkipAngle={10}
radialLabelsTextXOffset={6}
radialLabelsTextColor="#333333"
radialLabelsLinkOffset={0}
radialLabelsLinkDiagonalLength={16}
radialLabelsLinkHorizontalLength={24}
radialLabelsLinkStrokeWidth={1}
radialLabelsLinkColor="inherit"
slicesLabelsSkipAngle={10}
slicesLabelsTextColor="#333333"
animate={true}
motionStiffness={90}
motionDamping={15}
defs={[
{
"id": "dots",
"type": "patternDots",
"background": "inherit",
"color": "rgba(255, 255, 255, 0.3)",
"size": 4,
"padding": 1,
"stagger": true
},
{
"id": "lines",
"type": "patternLines",
"background": "inherit",
"color": "rgba(255, 255, 255, 0.3)",
"rotation": -45,
"lineWidth": 6,
"spacing": 10
}
]}
fill={[
{
"match": {
"id": "ruby"
},
"id": "dots"
},
{
"match": {
"id": "c"
},
"id": "dots"
},
{
"match": {
"id": "go"
},
"id": "dots"
},
{
"match": {
"id": "python"
},
"id": "dots"
},
{
"match": {
"id": "scala"
},
"id": "lines"
},
{
"match": {
"id": "lisp"
},
"id": "lines"
},
{
"match": {
"id": "elixir"
},
"id": "lines"
},
{
"match": {
"id": "javascript"
},
"id": "lines"
}
]}
legends={[
{
"anchor": "bottom",
"direction": "row",
"translateY": 56,
"itemWidth": 100,
"itemHeight": 18,
"itemTextColor": "#999",
"symbolSize": 18,
"symbolShape": "circle",
"effects": [
{
"on": "hover",
"style": {
"itemTextColor": "#000"
}
}
]
}
]}
/>
), document.getElementById('root'));
this is first time i'm working on charts in react js.
What i'm doing wrong any help will be appreciated.
Thanks.

I think you maybe forget to set the height of the father component of ResponsivePie.Here is the explain in the document
make sure parent container have a defined height when using responsive component,otherwise height will be 0 and no chart will be rendered
like this:
<div style={{height: 200}}>
<ResponsivePie .../>
</div>

Related

I'm new to this, What am I doing wrong? Creating array of line items in JSON and getting parse error. - Expecting 'STRING', got '{'

enter image description here
Parse error on line 15:
...,
"Qty": 3
},
{
"Amount":
--------------------^
Expecting 'STRING', got '{'
I don't know how to format the code for stack overflow but this is the JSON array I'm trying to put together
{
"MetaData": {
"CreateTime": "2019-05-16T18:13:13-08:00",
"LastUpdatedTime": "2019-05-16T18:13:45-08:00"
},
"Line": [{
"Amount": 135,
"DetailType": "SalesItemLineDetail",
"SalesItemLineDetail": {
"ItemRef": {
"value": "1",
"name": "LV"
},
"Qty": 3
},
{
"Amount": 135,
"DetailType": "SalesItemLineDetail",
"SalesItemLineDetail": {
"ItemRef": {
"value": "1",
"name": "LV"
},
"Qty": 3
} }
],
"CustomerRef": {
"value": "20"
}
}
The solution is probably simple
{
"MetaData": {
"CreateTime": "2019-05-16T18:13:13-08:00",
"LastUpdatedTime": "2019-05-16T18:13:45-08:00"
},
"Line": [
{
"Amount": 135,
"DetailType": "SalesItemLineDetail",
"SalesItemLineDetail": {
"ItemRef": {
"value": "1",
"name": "LV"
},
"Qty": 3
} <--- MISSING BRACE HERE
},
{
"Amount": 135,
"DetailType": "SalesItemLineDetail",
"SalesItemLineDetail": {
"ItemRef": {
"value": "1",
"name": "LV"
},
"Qty": 3
}
}
],
"CustomerRef": {
"value": "20"
}
}

Conditional render label Color base on another field value

I'm trying to render the label color base on another field value using test predicate or field predicate but I can not get it right.
All I want is that the label color on axis y (section) can change from black to red when its resilience value equal to 0.
I've made my code on online editor and I really appreciate if you can give me some help.
vega-lite-condition-render-label-color
in the case above, the fifth one <4. Hygiene & Cleaning> should be red instead of black.
I have added another layer with text, in which your text of section field is displayed. In that the color config with condition will work properly. Below is the code and editor:
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"usermeta": {"embedOptions": {"renderer": "svg"}},
"data": {
"values": [
{
"section": "1. General Health & Safety",
"Index": 38.40277777777778,
"resilience": 31
},
{
"section": "10. Environmental Accidents",
"Index": 38.40277777777778,
"resilience": 19
},
{
"section": "2. Health - Process",
"Index": 38.40277777777778,
"resilience": 39
},
{
"section": "3. Health - People",
"Index": 38.40277777777778,
"resilience": 47
},
{
"section": "4. Hygiene & Cleaning",
"Index": 38.40277777777778,
"resilience": 0
},
{
"section": "5. Health Care & Working Conditions",
"Index": 38.40277777777778,
"resilience": 25
},
{
"section": "6. External Pollution & Extreme Weather Conditions",
"Index": 38.40277777777778,
"resilience": 16
},
{
"section": "7. Hazardous Materials/Substances",
"Index": 38.40277777777778,
"resilience": 25
},
{
"section": "8. Safety Accidents",
"Index": 38.40277777777778,
"resilience": 46
},
{
"section": "9. Subcontractors Training",
"Index": 38.40277777777778,
"resilience": "1"
}
]
},
"config": {"view": {"stroke": null}},
"height": 300,
"autosize": {"resize": true},
"layer": [
{
"mark": {"type": "bar", "cornerRadiusEnd": 2},
"encoding": {
"x": {
"field": "resilience",
"type": "quantitative",
"title": null,
"axis": {"grid": true},
"scale": {"domain": [0, 100]}
},
"y": {
"field": "section",
"type": "ordinal",
"axis": {
"grid": false,
"domain": false,
"ticks": false,
"labels": false,
"labelAlign": "left",
"labelBaseline": "middle",
"labelPadding": -5,
"labelOffset": 0,
"labelColor2": {"expr": "datum.resilience < 230 ? 'red' : 'green'"},
"labelColor": {
"condition": {"test": "datum.resilience > 5", "value": "red"},
"value": "green"
},
"title": null
}
},
"tooltip": {
"field": "resilience",
"type": "quantitative",
"format": ".0f"
},
"color": {
"field": "resilience",
"type": "quantitative",
"title": "Score",
"scale": {
"domain": [0, 30, 50, 55, 60, 65, 70, 75, 80, 90, 100],
"range": [
"#DE7363",
"#FB9F38",
"#F9B821",
"#FBE8C9",
"#F5DA01",
"#E2D91E",
"#CBD641",
"#B6D35F",
"#A2D180",
"#7CC895",
"#52BEA9"
]
}
}
}
},
{
"mark": {"type": "text", "align": "left"},
"encoding": {
"text": {"field": "section"},
"color": {
"condition": {"test": "datum.resilience < 2", "value": "red"},
"value": "green"
},
"x": {"datum": 0},
"y": {"field": "section", "type": "ordinal"}
}
},
{
"mark": {"type": "rule", "color": "red", "size": 3},
"encoding": {
"x": {
"aggregate": "max",
"field": "Index",
"type": "quantitative",
"axis": null,
"format": ".0f",
"title": "Module Resilience"
}
}
}
]
}

Solr get facets on each root document

I have a JSON with documents and each document has a few _childDocuments_ I want to search in the parent and get back the parents and facets on each parent separate
Here is a sample JSON
[{
"id": 1,
"productName": "Ford Explorer",
"_childDocuments_": [{
"id": 6,
"color": "blue",
"price": 1000
},
{
"id": 7,
"color": "red",
"price": 2000
}
]
},
{
"id": 1,
"productName": "Ford F150",
"_childDocuments_": [{
"id": 10,
"color": "blue",
"price": 5000
},
{
"id": 11,
"color": "red",
"price": 6000
}
]
},
{
"id": 2,
"productName": "Toyota Highlander",
"_childDocuments_": [{
"id": 8,
"color": "green",
"price": 1200
},
{
"id": 9,
"color": "red",
"price": 2000
}
]
}
]
I want when I search for Ford I should get back all Fords and in each root document get back facets of the children.
Something like this:
[{
"id": 1,
"productName": "Ford Explorer",
"facets": {
"count": 2,
"prices": {
"buckets": [{
"val": 2000,
"count": 1
},
{
"val": 3000,
"count": 1
}
]
}
}
},
{
"id": 1,
"productName": "Ford F150",
"facets": {
"count": 2,
"prices": {
"buckets": [{
"val": 5000,
"count": 1
},
{
"val": 6000,
"count": 1
}
]
}
}
}
]
This is what I got so far
q={!parent+which=type:parent}&json.facet={ "prices": {
"type": "range",
"field": "price",
"start": 1000,
"end": 1000,
"gap": 1000
}
,
}
But this is only returning facets on all child documents.
Thanks in advance

angular ui tree for complex json

How to create angular ui tree for complex json?
[
{
"name": "bmw",
"model": "x3",
"specs": [
{
"name": "bmw",
"maxspeed": 350,
"minspeed": 0,
"model": "x3",
"type": "car"
},
{
"value": 30,
"name": "bmw",
"maxspeed": 350,
"minspeed": 0,
"model": "x3",
"type": "car"
}
],
"available": true,
"price": 50
},
{
"name": "audi",
"model": "r8",
"specs": [
{
"color": [
{
"value": "red",
"price": 100
},
{
"value": [
"white",
"black"
],
"price": 200
}
],
"maxspeed": 330,
"minspeed": 0,
"type": "car"
},
{
"color": [
{
"value": "blue",
"price": 300
},
{
"value": [
"yellow",
"gold"
],
"price": 500
}
],
"maxspeed": 330,
"minspeed": 0,
"type": "car"
}
],
"available": true
}
]

Angular states not showing amcharts after switching back to that state

I have two charts divs in html which I am able to display first time. but when my state changes and I come back to the state where I displayed charts. Then charts are not shown. I think I have to re-attach the dataProvider and render it again but i don't know how.
this is my controller
.controller('HomeCtrl', function ($location,$window) {
AmCharts.makeChart("chartdiv-pie", {
"type": "pie",
"theme": "light",
"dataProvider": [{
"title": "20%",
"value": 3852,
"color": "#18aa9f"
}, {
"title": "40%",
"value": 3899,
"color": "#e65548"
},
{
"title": "40%",
"value": 4899,
"color": "#e1e3e4"
}
],
"title": "AmCharts",
"color": "black",
"titleField": "title",
"valueField": "value",
"radius": "25%",
"outlineAlpha":0,
"innerRadius": "40%",
"balloonText": "[[value]]",
"labelText": "[[title]]",
"labelsEnabled": true,
"colorField": "color",
"labelText": "[[title]]",
"export": {
"enabled": true
},
});
var chart = AmCharts.makeChart( "chartdiv-male", {
"type": "serial",
"addClassNames": true,
"theme": "light",
"autoMargins": false,
"marginLeft": 30,
"marginRight": 8,
"marginTop": 10,
"marginBottom": 26,
"balloon": {
"adjustBorderColor": false,
"horizontalPadding": 10,
"verticalPadding": 8,
"color": "#ffffff"
},
"dataProvider": [ {
"year": "Pos",
"income": 30.1,
"color": "#FF0F00",
"expenses": 34.9,
}, {
"year": "Neg",
"income": 29.5,
"expenses": 31.1
}, {
"year": "Neu",
"income": 30.6,
"expenses": 28.2,
"dashLengthLine": 5,
"columnColor": 'green'
} ],
"valueAxes": [ {
"axisAlpha": 0,
"position": "left"
} ],
"startDuration": 1,
"graphs": [ {
"alphaField": "alpha",
"balloonText": "<span style='font-size:12px;'>[[title]] in [[category]]:<br><span style='font-size:20px;'>[[value]]</span> [[additional]]</span>",
"fillAlphas": 1,
"title": "Income",
"type": "column",
"valueField": "income",
"dashLengthField": "dashLengthColumn"
}, ],
"categoryField": "year",
"categoryAxis": {
"gridPosition": "start",
"axisAlpha": 0,
"tickLength": 0
},
"export": {
"enabled": true
}
} );
}
these are my states
.state('home.stats', {
url:'/stats',
templateUrl: 'views/stats.html',
controller: 'StatsCtrl',
controllerAs: 'stats'
})
.state('home.posts', {
url:'/posts',
templateUrl: 'views/posts.html',
controller: 'PostsCtrl',
controllerAs: 'posts'
});

Resources