FullCalendar event does not remove when the events array empty - angularjs

js code
(function(){
angular.module('calendarApp',['ngGrid', 'ui.calendar', 'ui.bootstrap'])
.controller('calendarCtrl',function($scope){
$scope.selectedGridItems = [];
$scope.test = [{
"id": 1,
"date": "01/09/2014T00:00:00",
"details": "test1",
"check": false,
"check1": false
}, {
"id": 2,
"date": "02/09/2014T00:00:00",
"details": "test2",
"check": false,
"check1": false
}, {
"id": 3,
"date": "03/09/2014T00:00:00",
"details": "test3",
"check": false,
"check1": false
}, {
"id": 4,
"date": "04/09/2014T00:00:00",
"details": "test4",
"check": false,
"check1": false
}, {
"id": 5,
"date": "05/09/2014T00:00:00",
"details": "test5",
"check": false,
"check1": false
}, {
"id": 6,
"date": "06/09/2014T00:00:00",
"details": "test6",
"check": false,
"check1": false
}, {
"id": 7,
"date": "07/09/2014T00:00:00",
"details": "test7",
"check": false,
"check1": false
}, {
"id": 8,
"date": "08/09/2014T00:00:00",
"details": "test8",
"check": false,
"check1": false
}, {
"id": 9,
"date": "09/09/2014T00:00:00",
"details": "test9",
"check": false,
"check1": false
}, {
"id": 10,
"date": "10/09/2014T00:00:00",
"details": "test10",
"check": false,
"check1": false
}, {
"id": 11,
"date": "11/09/2014T00:00:00",
"details": "test11",
"check": false,
"check1": false
}, {
"id": 12,
"date": "12/09/2014T00:00:00",
"details": "test12",
"check": false,
"check1": false
}, {
"id": 13,
"date": "13/09/2014T00:00:00",
"details": "test13",
"check": false,
"check1": false
}, {
"id": 14,
"date": "14/09/2014T00:00:00",
"details": "test14",
"check": false,
"check1": false
}];
$scope.ngGridOptions = {
data: 'test',
multiSelect: false,
columnDefs: [{
field: "id",
displayName: "ID",
width: "50px"
}, {
field: "date",
displayName: "Date",
width: "100px"
}, {
field: "details",
displayName: "Details"
}, {
field: "check",
displayName: "",
cellTemplate: "<div class='ngCellText'><input type='checkbox' ng-checked='COL_FIELD' ng-model='COL_FIELD' ng-change='selectChange(row,COL_FIELD)' /></div>",
width: "20px"
}, {
field: "check1",
displayName: "",
cellTemplate: "<div class='ngCellText'><input type='checkbox' ng-checked='COL_FIELD' ng-model='COL_FIELD' ng-change='selectChange1(row,COL_FIELD)' /></div>",
width: "20px"
}]
};
/* ----------------Calendar Control----------------- */
$scope.alertOnEventClick=function( event, allDay, jsEvent)
{
debugger;
};
$scope .events = [];
$scope.eventSources = [$scope.events];
$scope.uiConfig = {
calendar: {
height: 450,
editable: false,
disableDragging:false,
header: {
left: 'title',
center: '',
right: 'today prev,next'
},
eventClick:$scope.alertOnEventClick
}
};
/* ---------------------- ends ---------------------- */
$scope.selectChange = function (row, value) {
var className= (value) ? ((row.entity.check1) ? "row-selected-blue-green" : "row-selected-blue") : ((row.entity.check1) ? "row-selected-green" : "");
if (typeof(_.find($scope.events, function (item) {return item.id == moment(row.entity.date,'DD/MM/YYYYThh:mm:ss').format('MMMDDYYYY');})) == 'undefined') {
$scope.events.push({
id: moment(row.entity.date,'DD/MM/YYYYThh:mm:ss').format('MMMDDYYYY'),
title: moment(row.entity.date,'DD/MM/YYYYThh:mm:ss').format('MMMDDYYYY'),
start: moment(row.entity.date,'DD/MM/YYYYThh:mm:ss'),
className: [className]
});
} else {
_.find($scope.events, function (item) {
return item.id == moment(row.entity.date,'DD/MM/YYYYThh:mm:ss').format('MMMDDYYYY');
}).className = [className];
}
var elem = row.elm;
if (row.entity.check || row.entity.check1) {
$(elem).addClass('row-color');
} else if (!row.entity.check && !row.entity.check1) {
var index =$scope.events.indexOf(_.find($scope.events, function (item) {return item.id == moment(row.entity.date,'DD/MM/YYYYThh:mm:ss').format('MMMDDYYYY');}));
$scope.events.splice(index, 1);
$(elem).removeClass('row-color');
}
};
$scope.selectChange1 = function (row, value) {
var className = (value) ? ((row.entity.check) ? "row-selected-blue-green" : "row-selected-green") : ((row.entity.check) ? "row-selected-blue" : "");
if (typeof(_.find($scope.events, function (item) {return item.id == moment(row.entity.date,'DD/MM/YYYYThh:mm:ss').format('MMMDDYYYY');})) == 'undefined') {
$scope.events.push({
id: moment(row.entity.date,'DD/MM/YYYYThh:mm:ss').format('MMMDDYYYY'),
title: moment(row.entity.date,'DD/MM/YYYYThh:mm:ss').format('MMMDDYYYY'),
start: moment(row.entity.date,'DD/MM/YYYYThh:mm:ss'),
className: [className]
});
} else {
_.find($scope.events, function (item) {
return item.id == moment(row.entity.date,'DD/MM/YYYYThh:mm:ss').format('MMMDDYYYY');
}).className = [className];
}
var elem = row.elm;
if (row.entity.check || row.entity.check1) {
$(elem).addClass('row-color');
} else if (!row.entity.check && !row.entity.check1) {
var index = $scope.events.indexOf(_.find($scope.events, function (item) {
return item.id == moment(row.entity.date,'DD/MM/YYYYThh:mm:ss').format('MMMDDYYYY');
}));
$scope.events.splice(index, 1);
console.log($scope.events);
$(elem).removeClass('row-color');
}
};
$scope.rowScroll = function (item) {
$(item.elm).fadeTo(500, 0.5).fadeTo(700, 1.0);
var grid = $scope.ngGridOptions.ngGrid;
var dataIndex = $scope.ngGridOptions.ngGrid.data.indexOf(item.entity);
$scope.ngGridOptions.selectItem(dataIndex, true);
grid.$viewport.scrollTop(dataIndex * grid.config.rowHeight);
};
});
})();
Html code
<div ng-app="calendarApp">
<div ng-controller="calendarCtrl">
<div ng-grid="ngGridOptions" class="gridStyle"></div>
<div ui-calendar="uiConfig.calendar" class="span2 calendar" ng-model="eventSources"></div>
</div>
</div>
FIDDLE LINK

html changes
<div ui-calendar="uiConfig.calendar" class="span2 calendar" ng-model="eventSources" id="calendar"></div>
js change
var item = _.find($scope.events, function (item) {
return item.id == moment(row.entity.date,'DD/MM/YYYYThh:mm:ss').format('MMMDDYYYY');
});
$("div#calendar").fullCalendar('removeEvents',item.id);
$scope.events.splice(($scope.events.indexOf(item)),1);
updated link is working fine. check that link
FIDDLE SOLUTION LINK

Tried all of the above. But only the following worked
$scope.events.length = 0;

Related

Read array inside array into table Material UI

So i have an array of response from backend services as below (array inside an array), i try to figure it how to turn it into table but have some problem on the logic:
"data": [
{
"id": "63ad33c69acfa205d354256b",
"material": "1000000000",
"material_name": "SAMPEL",
"plant": "K111",
"type": "rm",
"current_price": 7718,
"price": []
},
{
"id": "63ad33c69acfa205d354256a",
"material": "1000000000",
"material_name": "SAMPEL",
"plant": "K109",
"type": "rm",
"current_price": 7718,
"price": []
},
{
"id": "63ad33c69acfa205d3542565",
"material": "1000000000",
"material_name": "SAMPEL",
"plant": "K103",
"type": "rm",
"current_price": 37259,
"price": [
{
"date": "januari",
"price": 37258.978184562315
},
{
"date": "februari",
"price": 37258.978184562315
},
{
"date": "maret",
"price": 37258.978184562315
},
{
"date": "april",
"price": 37258.978184562315
},
{
"date": "mei",
"price": 37258.978184562315
},
{
"date": "juni",
"price": 37258.978184562315
},
{
"date": "juli",
"price": 37258.978184562315
},
{
"date": "agustus",
"price": 37258.978184562315
},
{
"date": "september",
"price": 37258.978184562315
},
{
"date": "oktober",
"price": 37258.978184562315
},
{
"date": "november",
"price": 37258.978184562315
},
{
"date": "desember",
"price": 37258.978184562315
}
]
},
]
does it possible to turn it into table as below using material UI datagrid or similar table library?:
any help on this will be very helpful....
https://github.com/ChangeWithCode/datantable
Here I have implemented that you can have a look.
<div className="App">
<table>
<tr>
<th rowspan="2">material</th>
<th rowspan="2">material_name</th>
<th rowspan="2">plant</th>
<th rowspan="2">type</th>
<th rowspan="2">current_price</th>
<th colspan="12">Price</th>
</tr>
<tr>
<td>januari</td>
<td>februari</td>
<td>maret</td>
<td>april</td>
<td>mei</td>
<td>juni</td>
<td>juli</td>
<td>agustus</td>
<td>september</td>
<td>oktober</td>
<td>november</td>
<td>desember</td>
</tr>
{object.data.map((item) => {
return (
<tr>
<td>{item.material}</td>
<td>{item.material_name}</td>
<td>{item.plant}</td>
<td>{item.current_price}</td>
<td>{item.material_name}</td>
{item.price.map((obj) => {
return <td>{obj.price}</td>;
})}
</tr>
);
})}
</table>
</div>
The following solution using material table import MaterialTable from 'material-table';:
<MaterialTable
columns={[
{ title: 'material', field: 'material' },
{ title: 'material_name', field: 'material_name' },
{ title: 'plant', field: 'plant' },
{ title: 'type', field: 'type' },
{
title: 'current_price',
field: 'current_price',
},
{
title: 'price',
field: 'price',
render: (rowData) => (
<MaterialTable
columns={
rowData.price.length > 0
? rowData.price.map((el) => ({ title: el.date, field: 'price' }))
: [
{ title: 'januari', field: '' },
{ title: 'februari', field: '' },
{ title: 'maret', field: '' },
{ title: 'april', field: '' },
{ title: 'mei', field: '' },
{ title: 'juni', field: '' },
{ title: 'juli', field: '' },
{ title: 'agustus', field: '' },
{ title: 'september', field: '' },
{ title: 'oktober', field: '' },
{ title: 'november', field: '' },
{ title: 'desember', field: '' },
]
}
data={rowData.price}
options={{ toolbar: false }}
/>
),
},
]}
data={data}
title="Demo Title"
/>

How to find and update specific value in nested object array in typescript

I have a nested object array with n level like this:
const data = {
"id": null,
"label": "Locations",
"value": "Locations",
"expanded": true,
"children": [
{
"id": "A978919C-E99C-EB11-8F2E-A01D48E35246",
"value": "Tokyo ",
"label": "Tokyo ",
"checked": true,
"children": [
{
"id": "88887069-179A-EB11-9C25-00163EDCFF95",
"isDefault": true,
"locationId": "A978919C-E99C-EB11-8F2E-A01D48E35246",
"parentsId": null,
"createDate": "2021-06-20T19:03:55.190Z",
"updateDate": "2021-10-16T13:36:41.353Z",
"label": "RAJ - Automotive Japan Fa Fusoh",
"checked": true,
"children": [],
"disabled": false
}
]
},
.
.
]
}
I have an object
{
"id": "A978919C-E99C-EB11-8F2E-A01D48E35246",
"value": "Tokyo ",
"label": "Tokyo ",
"checked": false,
"_depth": 1,
"_id": "A978919C-E99C-EB11-8F2E-A01D48E35246",
"_parent": "rdts1-0",
"_children": [
"88887069-179A-EB11-9C25-00163EDCFF95"
],
"_focused": true
}
and I want to edit checked in the object array by using the IDs in the last object and its children, change each checked in object in the object array to false
I used DFS for the children but I didn't get a good result any help please.
Seems like recursion would suffice:
const data = {
id: null,
label: 'Locations',
value: 'Locations',
expanded: true,
children: [
{
id: 'A978919C-E99C-EB11-8F2E-A01D48E35246',
value: 'Tokyo ',
label: 'Tokyo ',
checked: true,
children: [
{
id: '88887069-179A-EB11-9C25-00163EDCFF95',
isDefault: true,
locationId: 'A978919C-E99C-EB11-8F2E-A01D48E35246',
parentsId: null,
createDate: '2021-06-20T19:03:55.190Z',
updateDate: '2021-10-16T13:36:41.353Z',
label: 'RAJ - Automotive Japan Fa Fusoh',
checked: true,
children: [],
disabled: false,
},
],
},
],
}
function setCheckedToFalse(childrenArr) {
// error handling
if (!Array.isArray(childrenArr)) {
return;
}
childrenArr.forEach((child) => {
// set to false
child.checked = false
// recursion for other children
setCheckedToFalse(child.children)
})
}
setCheckedToFalse(data.children)
console.log(data);
Not sure if I correctly understood the question, but the code below the checked value in the data object is set to false in case it exists in object.
const data = {
id: null,
label: 'Locations',
value: 'Locations',
expanded: true,
children: [
{
id: 'A978919C-E99C-EB11-8F2E-A01D48E35246',
value: 'Tokyo ',
label: 'Tokyo ',
checked: true,
children: [
{
id: '88887069-179A-EB11-9C25-00163EDCFF95',
isDefault: true,
locationId: 'A978919C-E99C-EB11-8F2E-A01D48E35246',
parentsId: null,
createDate: '2021-06-20T19:03:55.190Z',
updateDate: '2021-10-16T13:36:41.353Z',
label: 'RAJ - Automotive Japan Fa Fusoh',
checked: true,
children: [],
disabled: false,
},
],
},
],
};
const object = {
id: 'A978919C-E99C-EB11-8F2E-A01D48E35246',
value: 'Tokyo ',
label: 'Tokyo ',
checked: false,
_depth: 1,
_id: 'A978919C-E99C-EB11-8F2E-A01D48E35246',
_parent: 'rdts1-0',
_children: ['88887069-179A-EB11-9C25-00163EDCFF95'],
_focused: true,
};
// Gets all ids (nested ones included) from object
function getIdsHashMap(obj) {
const idsHashMap = {};
const loopThroughChildren = (children = []) => {
children.forEach((el) => {
idsHashMap[el] = true;
if (el._children) {
loopThroughChildren(el._children);
}
});
};
if (obj.id) {
idsHashMap[obj.id] = true;
}
loopThroughChildren(obj._children);
return idsHashMap;
}
// Sets checked in data to false if an id exists in object
function setCheckedValue(obj) {
const idsHash = getIdsHashMap(object);
const loopThgroughChildren = (children) => {
if (!Array.isArray(children)) {
return;
}
children.forEach((child) => {
// Checks, if id exists in hashmap from object
if (idsHash[child.id]) {
child.checked = false;
}
if (child.children) {
loopThgroughChildren(child.children);
}
});
};
if (obj.children) {
loopThgroughChildren(obj.children);
}
return obj;
}
console.log(setCheckedValue(data));

How to populate dropdown based on another dropdown for specific row in react-table v.6

I have two columns with dropdowns. When I choose option from any dropdown of first column, list of options should changes in second column's dropdown in the same row. In reality, it impacts for whole column and makes changes in all dropdowns.
How to make that the changes in left dropdown will impact to next right dropdown only?
This is my code:
const contact = {
"Phone #": [
{ val: 0, text: 'Cell Phone' },
{ val: 1, text: 'Home Phone' },
{ val: 2, text: 'Office Phone 1' },
{ val: 3, text: 'Office Phone 2' },
{ val: 4, text: 'Phone 10' },
{ val: 5, text: 'Phone 2' },
{ val: 6, text: 'Phone 4' },
{ val: 7, text: 'Phone 5' },
{ val: 8, text: 'Phone 6' },
{ val: 9, text: 'Phone 7' },
{ val: 10, text: 'Phone 8' },
{ val: 11, text: 'Phone 9' },
{ val: 12, text: 'Primary Contact Type' }
],
"E-mail": [
{ val: 0, text: 'Credit Card Notices only email' },
{ val: 1, text: 'Email 1' },
{ val: 2, text: 'Email 2' },
{ val: 3, text: 'Email 3' },
{ val: 4, text: 'Email 4' },
{ val: 5, text: 'ePrice Quote only email' },
{ val: 6, text: 'pegasus Tablet Email' },
{ val: 7, text: 'Statement only email Address' }
],
"DTN": [
{ val: 0, text: 'DTN #1' },
{ val: 1, text: 'DTN #2' },
{ val: 2, text: 'DTN #3' }
]
}
And
class ContactDocMaintenance extends Component {
constructor(props) {
super(props);
this.state = {
data: { data },
defValue: false,
contactValue: 'Phone #'
}
}
onChange = ({ target: { value } }) => {
this.setState({ contactValue: value });
}
render() {
const { contactValue } = this.state;
const options = contact[contactValue];
return (
<div className="row">
<div className="col-8">
<div className="row">
<div className="col-12 mt-2">
<ContentCard name="Contact Information" >
<ReactTable
data={data}
keyField="id"
pageSizeOptions={[20, 30, 50, 100, 200, 500]}
columns={[
{
Header: "Status",
accessor: "status",
width: 100,
},
{
Header: "Contact Type",
id: "contactType",
accessor: "contactType",
width: 100,
Cell: row => (<select onChange={this.onChange} margins="m-0" >
< option value="Phone #" > Phone #</option>
<option value="E-mail">E-mails</option>
<option value="DTN">DTN</option>
</select>)
},
{
Header: "Contact Type Description",
accessor: "contactTypeDescription",
width: 200,
Cell: row => (<select margins="m-0" >{options.map((opt) => <option key={opt.val} value={opt.val}>{opt.text}</option>)}</select>)
},
{
Header: "Contact value",
accessor: "contactValue",
width: 100
},
{
Header: "Notification",
accessor: "notification",
width: 100
}
]}
defaultPageSize={10}
className="-highlight"
showPagination={false}
/>
</ContentCard>
</div>
</div>
</div>
</div>
);
}
}
export default ContactDocMaintenance;
Data:
const data = [ {
"status": "",
"contactType": "",
"contactTypeDescription": "",
"contactValue": "(235)253-4524",
"notification": "",
},
{
"status": "",
"contactType": "",
"contactTypeDescription": "",
"contactValue": "(450)454-7878",
"notification": "",
},
{
"status": "",
"contactType": "",
"contactTypeDescription": "",
"contactValue": "(514)777-7777",
"notification": "",
},
{
"status": "",
"contactType": "",
"contactTypeDescription": "",
"contactValue": "(235)253-4524",
"notification": "",
},
{
"status": "",
"contactType": "",
"contactTypeDescription": "",
"contactValue": "(450)454-7878",
"notification": "",
},
{
"status": "",
"contactType": "",
"contactTypeDescription": "",
"contactValue": "(514)777-7777",
"notification": "",
},
{
"status": "",
"contactType": "",
"contactTypeDescription": "",
"contactValue": "(514)777-7777",
"notification": "",
},
{
"status": "",
"contactType": "",
"contactTypeDescription": "",
"contactValue": "(450)454-7878",
"notification": "",
},
{
"status": "",
"contactType": "",
"contactTypeDescription": "",
"contactValue": "(450)454-7878",
"notification": "",
},
{
"status": "",
"contactType": "",
"contactTypeDescription": "",
"contactValue": "(450)454-7878",
"notification": "",
}
]

Annotations not showing on ChartJS - React

The datasets plot fine on my line chart but I am trying to get vertical lines to display on the chart using chartjs-plugin-annotation. From looking at these questions & answers:
SOLVED : ChartJS annotation not displaying
https://github.com/chartjs/chartjs-plugin-annotation/issues/209
react-chartjs-2 vertical line when hovering over chart
Chart.js — drawing an arbitrary vertical line
I thought I had the correct configuration but the lines are not appearing.
LineChart.js
import 'chartjs-plugin-annotation'
import React, { useContext } from 'react'
import { Card, CardBody } from 'reactstrap'
import { Line } from 'react-chartjs-2'
import flatten from 'lodash/flatten'
import { rgbaColor, exchangeChartColors, capitalize, exchanges } from '../../helpers/utils'
import AppContext from '../../context/Context'
import dayjs from 'dayjs'
function getDepositsAndWithdrawals(activity) {
return ['DEPOSIT', 'WITHDRAWAL'].reduce((acc, type) => {
if (activity) {
if (activity.betfair) {
acc[type].betfair = activity.betfair.filter(s => {
return s.legacyData.marketName === type
}).map(s => {
return {
exchange: 'BETFAIR',
type: type,
amount: s.amount,
date: getFormattedDate(s.itemDate)
}
})
}
if (activity.betdaq) {
acc[type].betdaq = activity.betdaq.filter(s => {
return s.PostingCategory === 3 && s.Description.toUpperCase().includes(`${type}:`)
}).map(s => {
return {
exchange: 'BETDAQ',
type: type,
amount: s.Amount,
date: getFormattedDate(s.PostedAt)
}
})
}
if (activity.smarkets) {
const typeToGet = (type === 'DEPOSIT') ? 'deposit' : 'withdraw'
acc[type].smarkets = activity.smarkets.filter(s => {
return s.source === typeToGet
}).map(s => {
return {
exchange: 'SMARKETS',
type: type,
amount: parseFloat(s.money_change),
date: getFormattedDate(s.timestamp)
}
})
}
}
return acc
}, {
DEPOSIT: {},
WITHDRAWAL: {}
})
}
function getFormattedDate(date) {
const parsed = dayjs(date)
const day = parsed
.date()
.toString()
.padStart(2, '0')
// Unsure why have to add 1 but don't care really
const mnth = (parsed
.month() + 1)
.toString()
.padStart(2, '0')
const yr = parsed
.year()
.toString()
.padStart(2, '0')
const hr = parsed
.hour()
.toString()
.padStart(2, '0')
const min = parsed
.minute()
.toString()
.padStart(2, '0')
return `${day}/${mnth}/${yr} # ${hr}:${min}`
}
function getXAxis(balances, annotations) {
const balanceDates = balances.map(entry => {
return getFormattedDate(entry.date)
})
const annotationDates = annotations.map(ann => {
return ann.value
})
return [
...balanceDates,
...annotationDates
]
}
const ProfitsLineChart = props => {
const { isDark } = useContext(AppContext)
const depositsAndWithdrawals = getDepositsAndWithdrawals(props.activity)
const annotations = Object.values(depositsAndWithdrawals).reduce((acc, exs) => {
const newEntries = Object.values(exs).map(entries => {
return entries.map(entry => {
return {
type: 'line',
mode: 'vertical',
drawTime: 'afterDatasetDraw',
scaleID: 'x-axis-0',
value: entry.date,
borderColor: isDark
? exchangeChartColors.dark[entry.exchange.toLowerCase()]
: exchangeChartColors.light[entry.exchange.toLowerCase()],
borderWidth: 2,
label: {
content: `${entry.exchange} ~ ${entry.type} ~ ${entry.amount}`,
enabled: true,
position: 'top'
}
}
})
})
return [
...acc,
...flatten(newEntries)
]
}, [])
const config = {
data(canvas) {
let datasets = exchanges.map(exchange => {
return {
exchange,
data: props.balances.reduce((acc, entry) => {
const entryForExchange = entry.balances.find(balance => {
return balance.exchange.toUpperCase() === exchange.toUpperCase()
})
if (entryForExchange) {
acc.push({
date: entry.date,
balance: entryForExchange.balance
})
}
return acc
}, [])
}
})
let labels = getXAxis(props.balances, annotations)
// If not specified time period, only show most recent (30) entries
if (!props.start && !props.end) {
datasets = datasets.map(ds => {
return {
...ds,
data: ds.data.slice(ds.data.length - 50, ds.data.length)
}
})
labels = labels.slice(labels.length - 50, labels.length)
}
return {
labels,
datasets: datasets.map(set => {
return {
label: capitalize(set.exchange),
borderWidth: 2,
fill: false,
data: set.data.map(s => s.balance.toFixed(2)),
borderColor: isDark ? exchangeChartColors.dark[set.exchange.toLowerCase()] : exchangeChartColors.light[set.exchange.toLowerCase()],
backgroundColor: isDark ? exchangeChartColors.dark[set.exchange.toLowerCase()] : exchangeChartColors.light[set.exchange.toLowerCase()]
}
})
}
},
options: {
annotation: {
annotations
},
responsive: true,
title: {
display: true,
text: 'Balances',
fontSize: 20,
fontStyle: 'bold',
lineHeight: 2.5,
fontColor: rgbaColor('#cccccc', 0.7)
},
legend: {
labels: {
fontSize: 16,
fontStyle: 'italic',
fontColor: rgbaColor('#cccccc', 0.7)
},
display: true,
position: 'bottom'
},
tooltips: {
mode: 'index',
displayColors: true
},
hover: {
mode: 'label'
},
scales: {
xAxes: [
{
display: true,
id: 'x-axis-0',
scaleLabel: {
display: true,
labelString: 'Time',
fontSize: 12,
fontColor: rgbaColor('#cccccc', 0.7)
},
ticks: {
callback: () => '',
fontColor: rgbaColor('#cccccc', 0.7),
fontStyle: 600
}
}
],
yAxes: [
{
display: true,
id: 'y-axis-0',
scaleLabel: {
display: true,
labelString: 'Balance (£)',
fontSize: 14,
fontColor: rgbaColor('#cccccc', 0.7)
},
ticks: {
min: 0,
fontColor: rgbaColor('#cccccc', 0.7),
fontStyle: 600
}
}
]
}
}
}
return !props.balances.length ? (
<Card className="text-center mb-3">
<CardBody className="p-5">
<div className="display-2 text-200">No Data</div>
<p className="lead mt-4 text-800 text-sans-serif font-weight-semi-bold">There are no balances to display.</p>
<hr />
<p>Please edit your time period search (or remove it altogether) to see data</p>
</CardBody>
</Card>
) : (
<Card className="mb-3">
<CardBody className="rounded-soft bg-gradient">
<Line data={config.data} options={config.options} />
</CardBody>
</Card>
)
}
export default ProfitsLineChart
This is the config that is spit out that the chart is using:
{
"options": {
"annotation": {
"annotations": [
{
"type": "line",
"mode": "vertical",
"drawTime": "afterDatasetDraw",
"scaleID": "x-axis-0",
"value": "08/03/2020 # 14:47",
"borderColor": "rgba(239, 131, 0, 0.8)",
"borderWidth": 2,
"label": {
"content": "BETFAIR ~ DEPOSIT ~ 22",
"enabled": true,
"position": "top"
}
},
{
"type": "line",
"mode": "vertical",
"drawTime": "afterDatasetDraw",
"scaleID": "x-axis-0",
"value": "03/03/2020 # 23:04",
"borderColor": "rgba(119, 0, 255, 0.8)",
"borderWidth": 2,
"label": {
"content": "BETDAQ ~ DEPOSIT ~ 26.57",
"enabled": true,
"position": "top"
}
},
{
"type": "line",
"mode": "vertical",
"drawTime": "afterDatasetDraw",
"scaleID": "x-axis-0",
"value": "19/03/2020 # 17:57",
"borderColor": "rgba(68, 254, 59, 0.8)",
"borderWidth": 2,
"label": {
"content": "SMARKETS ~ DEPOSIT ~ 21",
"enabled": true,
"position": "top"
}
},
{
"type": "line",
"mode": "vertical",
"drawTime": "afterDatasetDraw",
"scaleID": "x-axis-0",
"value": "27/03/2020 # 12:55",
"borderColor": "rgba(239, 131, 0, 0.8)",
"borderWidth": 2,
"label": {
"content": "BETFAIR ~ WITHDRAWAL ~ -10",
"enabled": true,
"position": "top"
}
},
{
"type": "line",
"mode": "vertical",
"drawTime": "afterDatasetDraw",
"scaleID": "x-axis-0",
"value": "27/03/2020 # 13:02",
"borderColor": "rgba(119, 0, 255, 0.8)",
"borderWidth": 2,
"label": {
"content": "BETDAQ ~ WITHDRAWAL ~ -10",
"enabled": true,
"position": "top"
}
},
{
"type": "line",
"mode": "vertical",
"drawTime": "afterDatasetDraw",
"scaleID": "x-axis-0",
"value": "01/03/2020 # 09:45",
"borderColor": "rgba(68, 254, 59, 0.8)",
"borderWidth": 2,
"label": {
"content": "SMARKETS ~ WITHDRAWAL ~ -26.57",
"enabled": true,
"position": "top"
}
}
]
}
},
"responsive": true,
"title": {
"display": true,
"text": "Balances",
"fontSize": 20,
"fontStyle": "bold",
"lineHeight": 2.5,
"fontColor": "rgba(204,204,204,0.7)"
},
"legend": {
"labels": {
"fontSize": 16,
"fontStyle": "italic",
"fontColor": "rgba(204,204,204,0.7)"
},
"display": true,
"position": "bottom"
},
"tooltips": {
"mode": "index",
"displayColors": true
},
"hover": {
"mode": "label"
},
"scales": {
"xAxes": [
{
"display": true,
"id": "x-axis-0",
"scaleLabel": {
"display": true,
"labelString": "Time",
"fontSize": 12,
"fontColor": "rgba(204,204,204,0.7)"
},
"ticks": {
"fontColor": "rgba(204,204,204,0.7)",
"fontStyle": 600
}
}
],
"yAxes": [
{
"display": true,
"id": "y-axis-0",
"scaleLabel": {
"display": true,
"labelString": "Balance (£)",
"fontSize": 14,
"fontColor": "rgba(204,204,204,0.7)"
},
"ticks": {
"min": 0,
"fontColor": "rgba(204,204,204,0.7)",
"fontStyle": 600
}
}
]
}
}
I can't think as to why this is not working as intended. getXAxis ensures that the string timestamps of the annotations are added to the X-Axis as well. I'm lost for ideas
Look at this:
https://github.com/reactchartjs/react-chartjs-2/issues/201#issuecomment-579630734
and here, for vertical line instead of horizontal, write
mode: 'vertical',

EXTJS 5.1 VERY SIMPLE TreeStore from JSON

I have looked around but I still don't understand how to create treestore properly.
I have this very simple json that I get from a server:
{
"Results": [
{
"name": "John",
"age": 23,
"cars": [
{
"name": "Clio",
"brand": "Renault"
},
{
"name": "Class S",
"brand": "Mercedes"
}
]
},
{
"name": "Michel",
"age": 42,
"cars": [
{
"name": "Qashqai",
"brand": "Nissan"
}
]
}
]
}
I have my two models:
Ext.define('Person', {
extend: 'Ext.data.Model',
fields: [ 'name', 'age']
});
Ext.define('Car', {
extend: 'Ext.data.Model',
fields: [ 'name', 'brand']
});
Now I know that I have to create a tree store, but in all example that I have seen, there is always a "children" property in the json, which I don't have.
How to create a tree store with the following json?
Thanks a lot in advance :) !!
You could always build the correct formatted object for the data like the following:
Ext.application({
name: 'Fiddle',
launch: function () {
var myTreeData = {
"Results": [{
"name": "John",
"age": 23,
"cars": [{
"name": "Clio",
"brand": "Renault"
}, {
"name": "Class S",
"brand": "Mercedes"
}]
}, {
"name": "Michel",
"age": 42,
"cars": [{
"name": "Qashqai",
"brand": "Nissan"
}]
}]
},
modifiedData = {
expanded: true,
children: []
};
myTreeData.Results.forEach(function (result) {
var newChildrenArray = [];
result.cars.forEach(function (car) {
var newChild = {
text: car.name,
leaf: true
};
newChildrenArray.push(newChild);
});
var person = {
text: result.name,
leaf: (newChildrenArray.length > 0 ? false : true),
children: newChildrenArray
};
modifiedData.children.push(person);
});
var store = Ext.create('Ext.data.TreeStore', {
root: modifiedData
});
Ext.create('Ext.tree.Panel', {
title: 'Simple Tree',
width: 200,
height: 150,
store: store,
rootVisible: false,
renderTo: Ext.getBody()
});
}
});
Demo here: https://fiddle.sencha.com/#fiddle/j05

Resources