Google Charts Display Issue - charts

I'm facing an issue that the column name is not showing in the placeholders outside the graph. The image is attached. I'm using appian tool. I have column data in chartColData variable & rowData in chartRowData. All the data seems to be correct, but if you think I'm missing column labels from here, kindly point out.
local!chartColData: {
{
type: "string",
id: "Month",
rowDataKey: "Month"
},
{
type: "number",
id: "Bolivia",
rowDataKey: "Bolivia"
},
{
type: "number",
id: "Ecuador",
rowDataKey: "Ecuador"
},
{
type: "number",
id: "Balanced",
rowDataKey: "Balanced"
}
},
local!chartRowData:{
{
Month: "2018",
Bolivia: 165,
Ecuador: 938,
Balanced: 650
},
{
Month: "2019",
Bolivia: 768,
Ecuador: 1120,
Balanced: 546
},
{
Month: "2020",
Bolivia: 897,
Ecuador: 1167,
Balanced: 793
},
{
Month: "2021",
Bolivia: 1392,
Ecuador: 1110,
Balanced: 638.5
},
{
Month: "2022",
Bolivia: 136,
Ecuador: 969,
Balanced: 739
}
}

Related

How to Create Nested Level Map Schema Structure in MongoDB

I was trying to create an object structure with dynamic year and months inside it & followed by data inside each month.
My expectation
{
"2022": {
"january": {
"cards": [
{
"name":"Card Name",
"amount":100,
"date": "2021-07-06T20:30:00.000Z"
}
]
},
"february": {
"cards": [
{
"name":"Card Name",
"amount":100,
"date": "2021-07-06T20:30:00.000Z"
}
]
}
},
"2023": {
"March": {
"cards": [
{
"name":"Card Name",
"amount":100,
"date": "2021-07-06T20:30:00.000Z"
}
]
}
},
}
I have found one level on the map scheme
const DynamicSchema = new Schema({
year: {
type: Map,
of: String,
}
});
I was able to create this ✅
{
"year": {
"2022": "test"
}
}
When trying with the below schema but ended up with an error❌
const DynamicSchema = new Schema({
year: {
type: Map,
of: [Map],
month: {
type: Map,
of: [Map],
}
}
});
Request payload:
{
"year": {
"2022": {
"month": "34"
}
}
}
"error": "Cast to string failed for value "{ month: '34' }" (type Object) at path "year.$*""
Is my structure possible with MongoDB or not? if yes any hint would be helpful
Your payload itself is wrong:
{
"year": {
"2022": {
"month": "34"
}
}
}
You have defined your schema like this:
const DynamicSchema = new Schema({
year: {
type: Map,
of: [Map],
month: {
type: Map,
of: [Map],
}
}
});
Notice that month is defined as a map here. However, you are passing a string for it 34, in your payload. So, the conversion of 34 to map fails, hence you get the error. Try sending a map, in your payload:
{
"year": {
"2022": {
"month": {
"Jan": "34"
}
}
}
}

Mongodb: making a "groupBy" inside an aggregation and $project

My first question. Tried to find the answer but couldn't.
I have a dataset like the following:
{
_id: "6294d59455be467837cb6262",
text: 'Primeiro post',
image: '15bee21f99c0c879ecee4633f25eaa91',
width: 327,
height: 245,
location: 'Porto Alegre, Rio Grande do Sul',
poster: { name: 'J R', avatar: 'c633219c7fbacd09db9a9d54986b36b9' },
reactions: [
{ filename: 'image1', userId: 23 },
{ filename: 'image2', userId: 12 },
]
},
{
_id: "6294d59455be656589cb62825",
text: 'Segundo post',
image: '15bee21f99c0c879ecee4633f25423sgf',
width: 327,
height: 245,
location: 'Porto Alegre, Rio Grande do Sul',
poster: { name: 'J R', avatar: 'c633219c7fbacd09db9a9d54986b36b9' },
reactions: [
{ filename: 'image3', userId: 23 },
{ filename: 'image2', userId: 12 },
{ filename: 'image2', userId: 56 },
{ filename: 'image7', userId: 9 },
]
},
...
I want to retrieve all the fields, along with 2 things:
if the userId passed to the query is on the userId of the array 'reactions' - that's done in the reactionsByMe field I created with a $filter (query below);
group by 'filename' with the quantity on each of the registers that are returned;
I have the following working aggregate query:
[
{ $match: { 'createdBy.companyId': req.userInfo.companyId, type: 'post' } },
{
$project: {
reactionsByMe: {
$filter: {
input: '$reactions',
as: 'reaction',
cond: { $eq: ['$$reaction.userId', req.userInfo.userId] }
},
},
text: 1,
image: 1,
width: 1,
height: 1,
location: 1,
poster: 1,
}
},
]
I just don't know how to make a group inside the $project.
Any help appreciated! Thanks.
Edit: the expected output:
{
_id: "6294d59455be467837cb6262",
text: 'Primeiro post',
image: '15bee21f99c0c879ecee4633f25eaa91',
width: 327,
height: 245,
location: 'Porto Alegre, Rio Grande do Sul',
poster: { name: 'J R', avatar: 'c633219c7fbacd09db9a9d54986b36b9' },
reactions: [
{ _id: 'image1', count: 3 },
{ _id: 'image2', count: 5 },
]
}
With the "reactions" property giving me the total of each image in each document

How to place label on top of each horizontal bar in echarts?

I'm trying to make an horizontal histogram with y labels on top of each bar with the really nice libray echarts. Here is an example:
Here is where I am with this jsfiddle https://jsfiddle.net/795f84o0/6/ :
Echarts documentation is really good but I did not found a way to put these labels (sankey, funnel, gauge....) on top on each bar :/
Do you have any idea how I can do it? Thank you for your help!
var chartDom = document.getElementById('main');
var myChart = echarts.init(chartDom);
var option;
var builderJson = {
"all": 10887,
"charts": {
"map": 3237,
"lines": 2164,
"bar": 7561,
"line": 7778,
"pie": 7355,
"scatter": 2405,
"candlestick": 1842,
"radar": 2090,
"heatmap": 1762,
"treemap": 1593,
"graph": 2060,
"boxplot": 1537,
"parallel": 1908,
"gauge": 2107,
"funnel": 1692,
"sankey": 1568
},
"components": {
"geo": 2788,
"title": 9575,
"legend": 9400,
"tooltip": 9466,
"grid": 9266,
"markPoint": 3419,
"markLine": 2984,
"timeline": 2739,
"dataZoom": 2744,
"visualMap": 2466,
"toolbox": 3034,
"polar": 1945
},
"ie": 9743
};
option = {
xAxis: [{
type: 'value',
max: builderJson.all,
}],
yAxis: [{
data: Object.keys(builderJson.charts),
axisLabel: {
show: false,
},
},
{
data: Object.keys(builderJson.charts),
axisLabel: {
show: true,
},
},
],
series: [{
type: 'bar',
data: Object.keys(builderJson.charts).map(function (key) {
return builderJson.charts[key];
})
}]
};
option && myChart.setOption(option);
All right, I got it after two hours...
Just posting a screenshot to show the result:
The fiddle and the code :
var chartDom = document.getElementById('main');
var myChart = echarts.init(chartDom);
var option;
var builderJson = {
"all": 100,
"charts": {
"pie": 1,
"scatter": 1,
"candlestick": 1,
"radar": 2,
"heatmap": 3,
"treemap": 6,
"graph": 7,
"boxplot": 7,
"parallel": 8,
"gauge": 9,
"funnel": 15,
"sankey": 30
},
};
option = {
xAxis: [{
type: 'value',
max: builderJson.all,
axisLabel: {
show: false,
},
splitLine: {
show: false
}
},
],
yAxis: [{
data: Object.keys(builderJson.charts),
axisLabel: {
show: false,
},
splitLine: {
show: false
},
axisLine: {
show: false
},
axisTick: {
show: false,
}
},
],
series: [{
type: 'bar',
stack: 'chart',
barCategoryGap: 30,
barWidth: 20,
label: {
position: [0, -14],
formatter: '{b}',
show: true
},
itemStyle: {
borderRadius: [0, 2, 2, 0],
},
data: Object.keys(builderJson.charts).map(function (key) {
return builderJson.charts[key];
})
},
{
type: 'bar',
stack: 'chart',
barCategoryGap: 30,
barWidth: 20,
itemStyle: {
color: 'whitesmoke'
},
label: {
position: 'insideRight',
formatter: function(params) { return 100 - params.value + '%'},
show: true
},
data: Object.keys(builderJson.charts).map(function (key) {
return builderJson.all - builderJson.charts[key];
})
}
]
};
option && myChart.setOption(option);

MongoDB Aggregate by date on many fields

I have the following schema (abbreviated!)
{
date: {
_id: false,
day: { type: Number },
month: { type: Number },
year: { type: Number },
},
flightTimes: {
_id: false,
totalTime: Number,
...
},
loggedTimes: {
_id: false,
P1: {
type: Number,
},
P2: {
type: Number,
},
...
},
customFields: [
{
_id: false,
value: String,
type: {
type: String,
enum: ["text", "number", "time", "yesno", "paragraph"],
required: true,
},
},
],
}
I am trying to produce the following output using aggregation, but struggling.
{
total: [10,20,30],
P1: [45, 55, 12],
P2: [0, 12, 15],
}
Where the 1st item in the total array is the sum of any documents where Month = 1 (January), the second is the sum for February etc.
Any suggestions on how to proceed? For bonus points: the array should have a 0 if no documents match the current month. For more bonus points: how could I create an additional array for the sum of values in each custom field where type = time.
Ultimately looking to produce a graph with Charts.JS which shows the sum per month for each category of time.

Changing dateformat in stockcharts from amchart

I created a stockchart from amchart and saved it here: jsfiddle
Now I want to change (a) the date format of the chart cursor to "DD.MM.YYYY" and (b) the date format of the category axis to german format, e.g. "01. Mai 2018". I assume that (a) can somehow be solved with "categoryBalloonDateFormat", but I wasn't able to find the correct place to put it.
chart.ChartCursor.categoryBalloonDateFormat = "DD.MM.YYYY";
Unfortunately this doesn't work.
For (b) I have no clue at all.
For (a) you have to set it in the chartCursorSettings.categoryBalloonDateFormats array for the desired period(s) represented in your chart. If your data is daily, at least set the DD and WW periods (daily and weekly), but depending on the amount of data, you might want to set the MM (monthly) period as well. For example:
chart.chartCursorSettings.categoryBalloonDateFormats = [
{period:"YYYY", format:"YYYY"},
{period:"MM", format:"MMM, YYYY"},
{period:"WW", format:"DD.MM.YYYY"},
{period:"DD", format:"DD.MM.YYYY"},
{period:"hh", format:"JJ:NN"},
{period:"mm", format:"JJ:NN"},
{period:"ss", format:"JJ:NN:SS"},
{period:"fff", format:"JJ:NN:SS"}
]
Similarly for (b), you have to set the categoryAxesSettings.dateFormats array in the same manner as categoryBalloonDateFormats:
chart.categoryAxesSettings.dateFormats = [
{period:"YYYY", format:"YYYY"},
{period:"MM", format:"MMM, YYYY"},
{period:"WW", format:"DD.MM.YYYY"},
{period:"DD", format:"DD.MM.YYYY"},
{period:"hh", format:"JJ:NN"},
{period:"mm", format:"JJ:NN"},
{period:"ss", format:"JJ:NN:SS"},
{period:"fff", format:"JJ:NN:SS"}
]
Demo:
var chart = AmCharts.makeChart("chartdiv", {
"type": "stock",
"theme": "light",
"categoryAxesSettings": {
"dateFormats": [{
period: "YYYY",
format: "YYYY"
},
{
period: "MM",
format: "DD.MM.YYYY"
},
{
period: "WW",
format: "DD.MM.YYYY"
},
{
period: "DD",
format: "DD.MM.YYYY"
},
{
period: "hh",
format: "JJ:NN"
},
{
period: "mm",
format: "JJ:NN"
},
{
period: "ss",
format: "JJ:NN:SS"
},
{
period: "fff",
format: "JJ:NN:SS"
}
]
},
"chartCursorSettings": {
"categoryBalloonDateFormats": [{
period: "YYYY",
format: "YYYY"
},
{
period: "MM",
format: "DD.MM.YYYY"
},
{
period: "WW",
format: "DD.MM.YYYY"
},
{
period: "DD",
format: "DD.MM.YYYY"
},
{
period: "hh",
format: "JJ:NN"
},
{
period: "mm",
format: "JJ:NN"
},
{
period: "ss",
format: "JJ:NN:SS"
},
{
period: "fff",
format: "JJ:NN:SS"
}
],
"valueBalloonsEnabled": true
},
"dataSets": [{
"fieldMappings": [{
"fromField": "value",
"toField": "value"
}],
"dataProvider": generateChartData(),
"categoryField": "date"
}],
"panels": [{
"stockGraphs": [{
"valueField": "value",
"type": "smoothedLine"
}]
}]
});
function generateChartData() {
var chartData = [];
var firstDate = new Date(2012, 0, 1);
firstDate.setDate(firstDate.getDate() - 1000);
firstDate.setHours(0, 0, 0, 0);
for (var i = 0; i < 30; i++) {
var newDate = new Date(firstDate);
newDate.setDate(i);
var a = Math.round(Math.random() * (40 + i)) + 100 + i;
chartData.push({
date: newDate,
value: a
});
}
return chartData;
}
html,
body {
width: 100%;
height: 100%;
margin: 0px;
}
#chartdiv {
width: 100%;
height: 100%;
}
<script src="//www.amcharts.com/lib/3/amcharts.js"></script>
<script src="//www.amcharts.com/lib/3/serial.js"></script>
<script src="//www.amcharts.com/lib/3/themes/light.js"></script>
<script src="//www.amcharts.com/lib/3/amstock.js"></script>
<div id="chartdiv"></div>
Thanks - that worked! In addition if someone wants to change the month names to another language:
AmCharts.monthNames = [
'Januar',
'Februar',
'März',
'April',
'Mai',
'Juni',
'Juli',
'August',
'September',
'Oktober',
'November',
'Dezember'];
AmCharts.shortMonthNames = [
'Jan.',
'Feb.',
'März',
'April',
'Mai',
'Juni',
'Juli',
'Aug.',
'Sept.',
'Okt.',
'Nov.',
'Dez.'];