How to get gradient in treemap using echarts - gradient

I have a single hierarchy and based on values, I want gradient based on values on my map. I have used echarts for this. The solution given in their examples is hard to implement for getting a gradient. I have used React JS to achieve this. Here's my code along with json here -
import React, {useEffect} from 'react';
// import the core library.
import ReactEchartsCore from 'echarts-for-react/lib/core';
import ReactEcharts from "echarts-for-react";
// then import echarts modules those you have used manually.
import echarts from 'echarts/lib/echarts';
import 'echarts/lib/chart/treemap';
import 'echarts/lib/component/tooltip';
import 'echarts/lib/component/title';
var treemapData = [
{
"name": "abcdaaaaaaaaaaaaaaaaa",
"value": 250,
},
{
"name": "xyzxyzxyzxyzxyzzz",
"value": 525,
},
{
"name": "mnopmnopmnop",
"value": 1120,
},
{
"name": "vsuuuuuuuuuvu",
"value": 216,
},
{
"name": "1232342343434",
"value": 400,
},
{
"name": "timetimetime",
"value": 297,
},
{
"name": "placeplaceplace",
"value": 208,
},
{
"name": "countrycountry",
"value": 1203,
}
];
function TreemapEcharts() {
return (
<ReactEcharts
option={{
series: [{
type: 'treemap',
data: treemapData,
label: {
normal: {
textStyle: {
ellipsis: true
},
position: 'insideCenter',
formatter: function (params) {
var arr = [
'{name|' + params.name + '}',
'{value|' + params.value + '}'
];
return arr.join('\n');
},
rich: {
name: {
fontSize: 14,
color: '#fff'
},
value: {
fontSize: 14,
color: '#fff'
},
}
}
},
levels: [
{
itemStyle: {
normal: {
borderWidth: 2,
borderColor: '#fff',
gapWidth: 2
}
}
},
],
}]
}}
style={{ height: '300px', width: '50%' }}
/>
)
}
export default TreemapEcharts
Please let me know how can we add a gradient where color varies from darkest shade to lightest shade of one color here.

In case anyone is still wondering, you should take a look at their document regarding level: https://echarts.apache.org/en/option.html#series-treemap.levels.
Basically, you need to configure a color range and set colorMappingBy to "value". You should have something like this for your level config:
{
color: ["#942e38", "#aaa", "#269f3c"],
colorMappingBy: "value",
itemStyle: { ... }
}
To fine-tune your visualization, you can convert your value to an array, with the second element in the array being a value scaled to the desired saturation and map your color to that value by setting visualDimension to 1 (index value of the element the array), and manually set visualMin and visualMax values.
You can also take a look at their example: https://echarts.apache.org/examples/zh/editor.html?c=treemap-visual.

Related

Chart Js Stacked Bar Chart with Multiple levels or categories

I am trying to create a chart in ng2-charts that will have multiple labels, so for example the x access would have categories of all the Months, above that it will be broken down into each week, and then the bar sections would be something like rainy days, dry days, and snowy days.
I have found their documentation here https://www.chartjs.org/docs/latest/samples/bar/stacked-groups.html and have their example working, but need to expand on that to add another level, is that possible?
The following is what I was able to get figured out. This code will allow create a chart with 3 categories on the x axis divided into 4 categories each. This isn't the full code set, but should hopefully give others an idea on how to proceed if they are stuck.
<canvas baseChart
*ngIf="!loading"
[datasets]="myChartData.chartData"
[options]="barChartOptions"
[legend]="barChartLegend"
[chartType]="barChartType"
>
</canvas>
The following is the code that is used to set the bar chart options from data being returned by the api
this.barChartOptions = {
responsive: true,
scales: {
xAxes: [
{
id: 'xAxis1',
type: 'category',
labels: this.myChartData.xAxis1Labels,
},
{
id: 'xAxis2',
type: 'category',
labels: this.myChartData.xAxis2Labels,
offset: true
},
],
yAxes: [
{
ticks: {
beginAtZero: true,
callback: function(value: number) {if (value % 1 === 0) {return value;}}
}
}
]
},
title: {
display: true,
text: this.myChartData.title,
},
legend: {
labels: {
filter: function (item, chart) {
return item.text !== undefined && item.text !== null;
},
},
},
tooltips: { enabled: false },
hover: { mode: null },
};
This is the model that the api is returning:
import { ChartData } from "chart.js";
export class myChartData {
chartData: Array<ChartData>;
rankXAxisLabels: Array<string>;
namcXAxisLabels: Array<string>;
title: string;
}
Lastly, this is the format of the chartData Array that is being built by the api:
[
{
"data": [1,0,9,0,4,0,5,8,0,0,0,0],
"label": "firstPartOfBar",
"stack": "dataStack",
"backgroundColor": "red",
"hoverBackgroundColor": "red",
"xAxisID": "xAxis1"
},
{
"data": [1,0,8,0,5,0,0,0,0,0,6,7],
"label": "Second Part of Bar",
"stack": "dataStack",
"backgroundColor": "blue",
"hoverBackgroundColor": "blue",
"xAxisID": "xAxis1"
},
{
"data": [4,0,2,0,1,0,0,0,12,14,16,0],
"label": "Third Part of stack",
"stack": "dataStack",
"backgroundColor": "green",
"hoverBackgroundColor": "green",
"xAxisID": "xAxis1"
}
]

How to Set Corner Radius in Power BI Custom Theme?

I am trying to define a custom theme for my Power BI reports. I have been able to 'show' the border and set the color by importing the theme JSON. I cannot find out how to define the corner radius in the custom JSON file. Here is what I've tried:
{
"name": "Radius Theme",
"tableAccent": "#284861",
"visualStyles": {
"*": {
"*": {
"border": [{
"show": true,
"radius": "5D",
"color": { "solid": { "color": "#00FF00" } }
}]
}
}
}
}
Trying to reverse engineer, using the Power BI Desktop editor, I setup one visualization with rounded corners and saved the PBIX. When I crack open the PBIX file and check out the Layout contents, I see the following the appears to define the visualization border properties with a radius of '10D', just like I set in the UI.
"border": [
{
"properties": {
"show": {
"expr": {
"Literal": {
"Value": "false"
}
}
},
"radius": {
"expr": {
"Literal": {
"Value": "10D"
}
}
},
"color": {
...
Remove the quotes and the "D" from the radius value and it will work.
"border": [{
"show": true,
"radius": 10,
"color": { "solid": { "color": "#00FF00" } }
}],

Ag-grid not display nested json

I have json. I want render it to ag-grid. All fields work correctly, but i cannot render possible_positions items. What i make wrong?
[
{
"id": 1,
"surname": "Иванов",
"stop_sheet_status_id": 1,
"status_treatment": {
"id": 1,
"display_name": "active",
"created_at": "2017-09-08T06:50:19.043Z",
"updated_at": "2017-09-08T06:50:19.043Z"
},
"nationality": {
"id": 1,
"display_name": "nationality",
"created_at": "2017-09-08T06:50:16.441Z",
"updated_at": "2017-09-08T06:50:16.441Z"
},
"possible_positions": [
{
"id": 1,
"display_name": "programmer",
"created_at": "2017-09-08T06:50:17.883Z",
"updated_at": "2017-09-08T06:50:17.883Z"
},
{
"id": 2,
"display_name": "engineer",
"created_at": "2017-09-08T06:50:17.964Z",
"updated_at": "2017-09-08T06:50:17.964Z"
},
{
"id": 3,
"display_name": "worker",
"created_at": "2017-09-08T06:50:18.053Z",
"updated_at": "2017-09-08T06:50:18.053Z"
}
]
}
]
example.js
{
headerName: "treatment date", field: "treatment_date",
width: 100, pinned: true
},
{
headerName: "nat display ", field: "nationality.display_name",
width: 180, pinned: true
},
{
headerName: "position", field:
"possible_positions[0].display_name",
width: 180, pinned: true
}...
You'll need to define a value getter for that column. The default method for getting a value assumes that the data is only in nested objects, not arrays. Which is why nationality.display_name works for the column nat display.
This is how you can define a valueGetter
{
headerName: "position",
valueGetter: params => params.data.possible_positions[0].display_name,
width: 180, pinned: true
}
Actually, looking into the source code, you might be able to get away with this:
{
headerName: "position", field:
"possible_positions.0.display_name",
width: 180, pinned: true
}
Since the source splits the provided field name on ., then digs through the objects recursively using bracket notation.

Zingchart bar chart starting at y axis -50

When I am trying to create a barchart for mobile, the y axis actually starts from the middle of the screen, hence i am unable to see my chart completely. For viewing the chart, i need to zoom out the device by 20%, or i need to set a plotarea y value as -50. Can someone let me know where am i going wrong?
Graph is seen when added the below code:
plotarea:{
adjustLayout: 1,
marginTop:'dynamic',
backgroundFit: "y",
"y": -50
}
Attached image can be seen here:
1st: Without zoom, 2nd: With 20% zoom out, 3rd: with y as -50
Complete code is here:
var myConfig = {
type: "bar",
backgroundColor: "transparent",
plotarea:{
adjustLayout: 1,
marginTop:'dynamic',
backgroundFit: "y"
//"y": -50
},
plot:{
"rules": [
{
"rule": "%i==0",
"background-color": "#ACD373",
"placement": "in"
},
{
"rule": "%i==1",
"background-color": "#B7B7B7",
"placement": "in"
},
{
"rule": "%i==2",
"background-color": "#FF6E5B",
"placement": "in"
},
{
"rule": "%i==3",
"background-color": "#6DCFF6",
"placement": "in"
},
{
"rule": "%i==4",
"background-color": "#F9AD81",
"placement": "in"
},
{
"rule": "%i==5",
"background-color": "#898989",
"placement": "in"
}
],
valueBox:{
fontColor: "#fff",
connector: {
lineWidth: 1
},
"text": "%v",
"font-size": 20,
"font-weight": "normal",
"font-style": "normal"
}
},
"scale-x": {
"label":{
"text":[],
"color": "#fff"
},
item:{
color: "#fff",
},
"guide":{
"line-width":0
},
zooming: true,
"values":[]
},
"scale-y":{
"line-color":"none",
"item":{
"visible": false
},
"tick":{
"line-color":"none"
},
"guide":{
"line-color":"#4A6B89",
"line-width":1,
"line-style":"solid",
"alpha":1
}
},
labels:[
{
//text:"Hold SHIFT to detach<br>multiple slices",
textAlign: "left",
fontColor: "#fff"
}
],
series: [{values:[]}]
};
The same code works perfectly for another chart with the same data set and same width height for the div which is rendering this chart.
Also, i can't make the y value as -50 as i have bound the chart top open another chart on clicking any of the bars. On making y as -50, i am unable to click the bars.
I have updated your tags to be appropriate to your environment, coldfusion. I assume you are using cfchart as well. This means not all properties persist across.
I have adjusted a few properties. They mostly have to do with margins within the plotarea object. My best suggestion is try playing around with margins if margin:'dynamic' does not apply for your build.
demo link
var myConfig = {
type: "bar",
backgroundColor: "#1D3557",
plotarea:{
adjustLayout: 1,
margin:'dynamic',
},
plot:{
"rules": [
{
"rule": "%i==0",
"background-color": "#ACD373",
"placement": "in"
},
{
"rule": "%i==1",
"background-color": "#B7B7B7",
"placement": "in"
},
{
"rule": "%i==2",
"background-color": "#FF6E5B",
"placement": "in"
},
{
"rule": "%i==3",
"background-color": "#6DCFF6",
"placement": "in"
},
{
"rule": "%i==4",
"background-color": "#F9AD81",
"placement": "in"
},
{
"rule": "%i==5",
"background-color": "#898989",
"placement": "in"
}
],
valueBox:{
fontColor: "#fff",
connector: {
lineWidth: 1
},
"text": "%v",
"font-size": 20,
"font-weight": "normal",
"font-style": "normal"
}
},
"scale-x": {
"label":{
"text":'Version',
"color": "#fff"
},
item:{
color: "#fff",
},
"guide":{
"line-width":0
},
zooming: true,
"values":[]
},
"scale-y":{
"line-color":"none",
"item":{
"visible": false
},
"tick":{
"line-color":"none"
},
"guide":{
"line-color":"#4A6B89",
"line-width":1,
"line-style":"solid",
"alpha":1
}
},
zoom: {
preserveZoom:true,
},
labels:[
{
//text:"Hold SHIFT to detach<br>multiple slices",
textAlign: "left",
fontColor: "#fff"
}
],
series: [{values:[15,25,35,45,35,45]}]
};
zingchart.render({
id: 'myChart',
data: myConfig,
height: '100%',
width: '100%'
});
html, body {
height:100%;
width:100%;
margin:0;
padding:0;
}
#myChart {
height:100%;
width:100%;
min-height:150px;
}
.zc-ref {
display:none;
}
<!DOCTYPE html>
<html>
<head>
<script src= "https://cdn.zingchart.com/zingchart.min.js"></script>
</head>
<body>
<div id="myChart"><a class="zc-ref" href="https://www.zingchart.com">Powered by ZingChart</a></div>
</body>
</html>
It might be because, either you would have the font-size that makes chart extend the screen size or try changing the margin it might help, I tried it in the past but with no luck.

LineChart Date Column Not Working - a[jc] is not a function - Google Charts

I wish Google Charts error messages were a little more clear. I'm getting the following error:
Chart not displayed due to error: a[jc] is not a function. Full error object follows.
In the object that follows it doesn't give much additional information.
My columns are specified like this:
chartData.data.cols = [
{
id: "some-date",
label: "Date",
type: "datetime",
},
{
id: "somenumber",
label: "Some Number",
type: "number",
},
];
And my rows are created like this:
var dateObject = new Date("2014-12-06T10:30:00-0800");
var newRow = {
c: [
{
v: dateObject,
},
{
v: arrayItem.predicted_dst,
},
],
}
My options.haxis is:
hAxis: {
title: "Default hAxis Title",
titleTextStyle: {
color: '#728292', //$darkGreyAccent
},
textStyle: {
color: '#728292', //$darkGreyAccent
},
gridlines: {
color: '#ECF0F1', //$lightGreyAccent'
count: -1,
},
direction: -1,
baseline: 1,
baselineColor: '#ECF0F1', //$lightGreyAccent
},
It took me a while to solve this problem so I thought I'd post the situation. It turns out that the baseline:1 was causing the issue.
In my code the baseline 1 was in there as a default for the many other charts I've been creating.
My options now look like this:
hAxis: {
title: "Default hAxis Title",
titleTextStyle: {
color: '#728292', //$darkGreyAccent
},
textStyle: {
color: '#728292', //$darkGreyAccent
},
gridlines: {
color: '#ECF0F1', //$lightGreyAccent'
count: -1,
},
direction: -1,
baselineColor: '#ECF0F1', //$lightGreyAccent
},
I'm not sure why the Google Chart error message is so cryptic, but if anyone else gets this error