The last two labels display over each other as shown in the image below. How do I fix this?
Here's some lorem ipsum so stackoverflow doesn't complain about my post being mostly code: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer pharetra porta pretium. Suspendisse vitae congue turpis, eu condimentum turpis. Cras a ultrices velit. Sed semper efficitur felis, et porttitor sapien vestibulum ac. Sed viverra porttitor arcu, ac finibus ligula ultrices non. Nullam quis porttitor elit. Maecenas fringilla erat sed libero luctus efficitur vel sit amet massa. Proin hendrerit metus in nibh fringilla malesuada. Proin turpis turpis, tempor non venenatis eu, fringilla in nunc. Proin ultricies neque sit amet nisi posuere sagittis. Vivamus erat massa, hendrerit nec nibh vitae, commodo faucibus felis. Maecenas a urna diam.
Options:
var options = {
scales: {
xAxes: [{
gridLines:{
display:false,
},
type:"time"
}],
yAxes: [{
ticks:{
stepSize:10000
}
}]
}
};
Data:
{
label: "My Dataset",
fill: false,
lineTension: 0.1,
borderColor: "#8CCEC2",
backgroundColor: "#8CCEC2",
borderCapStyle: 'butt',
borderJoinStyle: 'miter',
pointRadius:0,
data: [
{
x:moment((new Date()).toISOString()).subtract(1,"days")
,y:9000
},
{
x:moment((new Date()).toISOString()).subtract(2,"days")
,y:11000
},
{
x:moment((new Date()).toISOString()).subtract(3,"days")
,y:8000
},
{
x:moment((new Date()).toISOString()).subtract(4, "days")
,y:10000
},
{
x:moment((new Date()).toISOString()).subtract(5, "days")
,y:9000
}
],
spanGaps: false
}
Unfortunately, chart.js has trouble sometimes auto-fitting a time scale x-axis because of all the format variations and possibilities. You can do one of two things to solve this. Either expand the size of the chart container (so that there is more room to render the chart) or configure the time scale manually to optimize how it looks.
In this specific case I used the time.unit property to display the scale in units of 'days'. Here is the relevant config:
scales: {
xAxes: [{
gridLines: {
display: false,
},
type: "time",
time: {
unit: 'day',
}
}],
yAxes: [{
ticks:{
stepSize: 10000
}
}]
}
Here is a codepen to demonstrate what I mean.
Try scales.xAxes[0].time.round = 'day'
This fixed it for me.
before:
after:
e.g.,
scales: {
xAxes: [{
type: "time",
time: {
format: "MM/DD/YYYY",
round: 'day',
tooltipFormat: 'll'
},
scaleLabel: {
display: true,
}
}],
}
Related
I have dataset like this:
{
country: "NO",
population: 200,
color: "blue",
"Manager": "['Jim Brown']"
},
{
country: "AE",
population: 200,
color: "red",
"Manager": "['Jim', 'Arnold']"
},
{
country: "AE",
population: 200,
color: "green",
"Manager": "['Jim Brown', 'Sam']"
},
I am trying to filter only the values that have Manager equal to Jim. So the result should only contain list that have exact matching string. In this case should only return list with Jim but not Jim Brown.
I tried using regexMatch:
{
"$regexMatch": {
"input": "Manager",
"regex": "/^Jim$/",
}
}
However it is not working.
Here is my playground with minimal reproducible example:
https://mongoplayground.net/p/kU2tH1YjO1F
I am testing my feet in Swift and am trying to access certain objects which are part of a nested array.
The structure of the array looks something like this:
[ "Title": "Book Title", "Type": "Fiction", "Chapters": [
{"Title": "Chapter 1 Title", "Content": "Lorem ipsum dolor sit amet...", "Keyword": "foo"},
{"Title": "Chapter 3 Title", "Content": "Lorem ipsum dolor sit amet...", "Keyword": "foo"},
{"Title": "Chapter 5 Title", "Content": "Lorem ipsum dolor sit amet...", "Keyword": "foo"},
...
],
[ "Title": "Book Title", "Type": "Fiction", "Chapters": [
{"Title": "Chapter 2 Title", "Content": "Lorem ipsum dolor sit amet...", "Keyword": "foo"},
{"Title": "Chapter 3 Title", "Content": "Lorem ipsum dolor sit amet...", "Keyword": "foo"}
],
...]
The array is loaded from a plist file and is loaded something like this:
var myArr: Array<Any>
myArr = NSArray(contentsOfFile: path!) as! [Dictionary<String, Any>]
I am having difficulty accessing specific children of the chapters array.
let bookNum = 1
let chapNum = 3
let s: Dictionary = myArr[bookNum] as! Dictionary<String, Any>
if let s1 = (s["Chapters"] as AnyObject)[chapNum] {
if let obj = s1 as! Dictionary<String, Any> {
print("/(obj["Title"])")
}
}
I get the error, that "Initializer for conditional binding must have optional type, not Dictionary".
In general I am getting the feeling that I am not doing this correctly. The problem is, that the exact structure of the array is not known. Theoretically a Book could be listed without chapters.
Thanks for help in advance.
You have already specified the myArr type as [Dictionary<String, Any>], so there is no need to explicitly specify the type of s because if you access object from myArr it should only dictionary nothing else.
let s = myArr[bookNum]
Now Chapters is also Array of dictionary so you need to type cast it that and then access the chapter according to you want.
if let chapters = s["Chapters"] as? [Dictionary<String, Any>] {// OR [[String:Any]]
if chapNum < chapters.count {
print(chapters[chapNum]["Title"])
}
}
First I don't know what's it called. But how do you change its color from gray to white? Or is it even possibe?
It is possible to either remove the grid lines or have them display in a different color.
In both options.scales.xAxes and options.scales.yAxes you can add
gridLines: {
display: false ,
color: "#FFFFFF"
},
(obviously you do not need to assign a colour if you are not disaplying them)
var chartColors = {
red: 'rgb(255, 99, 132)',
orange: 'rgb(255, 159, 64)',
yellow: 'rgb(255, 205, 86)',
green: 'rgb(75, 192, 192)',
blue: 'rgb(54, 162, 235)',
purple: 'rgb(153, 102, 255)',
grey: 'rgb(231,233,237)'
};
var randomScalingFactor = function() {
return (Math.random() > 0.5 ? 1.0 : -1.0) * Math.round(Math.random() * 100);
}
var MONTHS = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
var config = {
type: 'line',
data: {
labels: ["January", "February", "March", "April", "May", "June", "July"],
datasets: [{
label: "My First dataset",
backgroundColor: chartColors.red,
borderColor: chartColors.red,
data: [
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor()
],
fill: false,
}, {
label: "My Second dataset",
fill: false,
backgroundColor: chartColors.blue,
borderColor: chartColors.blue,
data: [
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor()
],
}]
},
options: {
responsive: true,
title: {
display: true,
text: 'Chart.js Line Chart'
},
tooltips: {
mode: 'label',
},
hover: {
mode: 'nearest',
intersect: true
},
scales: {
xAxes: [{
display: true,
gridLines: {
display: false
},
scaleLabel: {
display: true,
labelString: 'Month'
}
}],
yAxes: [{
display: true,
gridLines: {
display: false
},
scaleLabel: {
display: true,
labelString: 'Value'
}
}]
}
}
};
var ctx = document.getElementById("canvas").getContext("2d");
window.myLine = new Chart(ctx, config);
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.2.1/Chart.js"></script>
<div style="width:100%;">
<canvas id="canvas"></canvas>
</div>
Since v3 the scales have been changed so if you want your gridlines to have a different color you will need to configure it in options.scales[scaleID].grid.color:
var options = {
type: 'line',
data: {
labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
datasets: [{
label: '# of Votes',
data: [12, 19, 3, 5, 2, 3],
borderColor: 'pink'
},
{
label: '# of Points',
data: [7, 11, 5, 8, 3, 7],
borderColor: 'orange'
}
]
},
options: {
scales: {
y: {
grid: {
color: 'white'
}
},
x: {
grid: {
color: 'red'
}
}
}
}
}
var ctx = document.getElementById('chartJSContainer').getContext('2d');
new Chart(ctx, options);
<body>
<canvas id="chartJSContainer" width="600" height="400"></canvas>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.6.0/chart.js"></script>
</body>
Try this:
options: {
scales: {
x: {
display: true,
grid: {
display: false
},
},
y: {
display: true,
grid: {
display: false
},
}
}
}
I would like to change font size and border colors for this chart. Hence I don't know how to do it, I tried to put these options at different places but nothing seems to work. I can't get the logic of the binding between angular-chart options and Chart.js options, is there a common way to manipulate them?
Here's the directive:
<canvas class="chart chart-line" chart-y-axes="axes" chart-data="data" chart-labels="labels"
chart-series="series" chart-options="options" chart-legend="true" chart-colours="colours"></canvas>
Here are the scope definitions:
$scope.labels = ["January", "February", "March", "April", "May", "June", "July"];
$scope.series = ['Series A', 'Series B'];
$scope.axes = ["y-axis-1", "y-axis-2"];
$scope.data = [
[65, 59, 80, 81, 56, 55, 40],
[28, 48, 40, 19, 86, 27, 90]
];
$scope.colours = [{
fillColor: 'rgba(151,187,205,0.2)',
strokeColor: 'rgba(151,187,205,1)',
pointColor: 'rgba(151,187,205,1)',
pointStrokeColor: '#fff',
pointHighlightFill: '#fff',
pointHighlightStroke: 'rgba(151,187,205,0.8)'
}]
$scope.options = {
datasetFill: false,
showLines: true,
elements:
{
line:
{
fill: false,
tension: 0.0001
},
point:
{
radius: 0
}
},
scales:
{
yAxes: [
{
type:"linear",
id:$scope.axes[0],
gridLines:
{
display: false
}
},
{
type:"linear",
id:$scope.axes[1],
position: "right",
gridLines:
{
display: false
},
scaleLabel:
{
display: true
}
}]
},
};
Changing the colors through chart-colors just doesn't work.
Since you have 2 series, make sure you have 2 entries in $scope.colours i.e.
...
$scope.colours = [{
fillColor: 'rgba(151,187,205,0.2)',
strokeColor: 'red',
pointColor: 'rgba(151,187,205,1)',
pointStrokeColor: '#fff',
pointHighlightFill: '#fff',
pointHighlightStroke: 'rgba(151,187,205,0.8)'
}, {
fillColor: 'rgba(151,187,205,0.2)',
strokeColor: 'blue',
pointColor: 'rgba(151,187,205,1)',
pointStrokeColor: '#fff',
pointHighlightFill: '#fff',
pointHighlightStroke: 'rgba(151,187,205,0.8)'
}]
...
Fiddle - http://jsfiddle.net/cpdh1g19/ (the color for the first line will change after 2 seconds)
By the look of the options, you're using chart.js 2.0, you need to use the latest angular-chart.js.
Note the attribute is now chart-colors and the color properties have changed in chart.js 2.0.
To preface this, I'm new to Ember and using Mirage to mock a JSON-API compliant backend, but I've hit a snag on what I think would be a common scenario. Ideally, I'm looking to create a single view that lists posts and the comments for each post underneath. The trouble comes when I want to display the author associated with each comment. So, I must clearly be doing something wrong here, since Ember knows how to fetch the direct associations for the Post model, but anything deeper than that is undefined.
In my route, I fetch all posts and that knows to then request the relationship data from the proper Mirage routes.
// app/routes/index.js
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return this.store.findAll('post');
}
});
This is the response that Ember receives from Mirage when requesting all posts.
{
"data": [
{
"type": "posts",
"id": "1",
"attributes": {
"title": "Vero quas non inventore eos vel rerum nesciunt nemo molestiae.",
"body": "Eum minima beatae ullam nam id ut quia.\nPorro quidem blanditiis provident qui ex voluptas temporibus officia quos.\nDeleniti aut soluta placeat illo.\nId aut dolorem illo fugit corrupti commodi.\nPorro nesciunt enim debitis.\nMinima architecto velit corporis excepturi eos qui.",
},
"relationships": {
"author": {
"data": {
"type": "users",
"id": "10"
}
},
"comments": {
"data": []
}
}
},
{
"type": "posts",
"id": "2",
"attributes": {
"title": "Id quae est omnis dolorum quaerat aut sed corrupti voluptatem.",
"body": "Est ipsa voluptas quia quae nihil ipsum assumenda itaque nihil.\nTotam aut quia.\nRerum maxime cum distinctio harum dolorem dolores dicta.\nNesciunt id et minima velit omnis eius itaque ad.",
},
"relationships": {
"author": {
"data": {
"type": "users",
"id": "1"
}
},
"comments": {
"data": []
}
}
},
{
"type": "posts",
"id": "3",
"attributes": {
"title": "Provident et eius est.",
"body": "Neque autem deserunt.\nAb repellendus nemo et aut sunt veritatis facere asperiores soluta.\nEt placeat id dicta sint.\nHarum temporibus eos labore.",
},
"relationships": {
"author": {
"data": {
"type": "users",
"id": "8"
}
},
"comments": {
"data": []
}
}
},
{
"type": "posts",
"id": "4",
"attributes": {
"title": "A similique explicabo itaque dolor vel possimus aut praesentium veritatis.",
"body": "Inventore et ipsum ut porro.\nUt sed est unde illo nulla id doloribus accusamus voluptatum.\nTempora officiis ut enim porro et est qui.\nSit qui minima iste eaque cupiditate molestiae ut omnis magni.",
},
"relationships": {
"author": {
"data": {
"type": "users",
"id": "4"
}
},
"comments": {
"data": []
}
}
},
{
"type": "posts",
"id": "5",
"attributes": {
"title": "Et in consequatur ut autem et.",
"body": "Qui voluptatem harum aut amet possimus architecto eos commodi.\nNumquam cupiditate fugit.\nQuod consequatur minima aspernatur nobis qui eligendi qui corporis necessitatibus.\nIste velit perferendis non dolore ipsum perspiciatis quia.\nAut delectus et porro cupiditate laboriosam dolorem.\nEaque ipsa rerum ipsam placeat voluptatem enim.",
},
"relationships": {
"author": {
"data": {
"type": "users",
"id": "1"
}
},
"comments": {
"data": [
{
"type": "comments",
"id": "4"
}
]
}
}
},
{
"type": "posts",
"id": "6",
"attributes": {
"title": "Exercitationem quo perferendis.",
"body": "Dolor ut voluptates placeat ullam.\nOmnis aut et.\nIste est tenetur deleniti ea incidunt eos voluptas veniam iusto.",
},
"relationships": {
"author": {
"data": {
"type": "users",
"id": "3"
}
},
"comments": {
"data": [
{
"type": "comments",
"id": "1"
},
{
"type": "comments",
"id": "5"
},
{
"type": "comments",
"id": "9"
}
]
}
}
},
{
"type": "posts",
"id": "7",
"attributes": {
"title": "Officia ea quod natus corrupti.",
"body": "Et quia qui occaecati aspernatur voluptatem error in.\nDoloremque rerum sed autem minima quidem reiciendis.\nPossimus dolores voluptas voluptate rerum veniam dicta.\nNemo dolore perspiciatis harum dolorem soluta ab consectetur animi sed.",
},
"relationships": {
"author": {
"data": {
"type": "users",
"id": "1"
}
},
"comments": {
"data": [
{
"type": "comments",
"id": "3"
}
]
}
}
},
{
"type": "posts",
"id": "8",
"attributes": {
"title": "Quia ea cum vel repudiandae.",
"body": "Excepturi dolores sed modi est asperiores deleniti.\nTempore architecto recusandae nostrum culpa expedita iure voluptatibus accusantium nemo.\nQuia est voluptatum nulla earum culpa.",
},
"relationships": {
"author": {
"data": {
"type": "users",
"id": "7"
}
},
"comments": {
"data": [
{
"type": "comments",
"id": "2"
},
{
"type": "comments",
"id": "7"
},
{
"type": "comments",
"id": "8"
}
]
}
}
},
{
"type": "posts",
"id": "9",
"attributes": {
"title": "Nam fugit in voluptatibus et.",
"body": "Aut nihil atque tempore beatae voluptas.\nOptio voluptatum qui debitis omnis dolor maiores cumque.\nUt dolorem est magnam eveniet.\nMagni porro occaecati ex autem.\nPorro et alias beatae nemo laboriosam ut sint magnam quis.\nMollitia deserunt culpa non.",
},
"relationships": {
"author": {
"data": {
"type": "users",
"id": "9"
}
},
"comments": {
"data": [
{
"type": "comments",
"id": "10"
}
]
}
}
},
{
"type": "posts",
"id": "10",
"attributes": {
"title": "Aut delectus nobis voluptate.",
"body": "Alias impedit itaque at rerum enim.\nVoluptas itaque quaerat qui optio quo.\nNihil voluptatem quos nihil pariatur sapiente tempore necessitatibus quia et.\nSed consectetur modi dolorum sunt ex odit at.\nVoluptas numquam totam dolores ipsam rerum.\nEt hic eum sunt et.",
},
"relationships": {
"author": {
"data": {
"type": "users",
"id": "1"
}
},
"comments": {
"data": [
{
"type": "comments",
"id": "6"
}
]
}
}
}
]
}
After getting all posts and the top-level relation models, Ember doesn't go any deeper so I'm left with an undefined comment.author in my template. Is there some way I can tell Ember to fetch the nested models that I need or am I going about this all wrong?
EDIT
This is the structure of my models and the templates for them. Hopefully, it will help give some more context.
Post model:
// app/models/post.js
import DS from 'ember-data';
export default DS.Model.extend({
title: DS.attr('string'),
body: DS.attr('string'),
createdAt: DS.attr('date', {
defaultValue() { return new Date(); }
}),
author: DS.belongsTo('user'),
comments: DS.hasMany('comment')
});
Comment model:
// app/models/comment.js
import DS from 'ember-data';
export default DS.Model.extend({
body: DS.attr('string'),
createdAt: DS.attr('data', {
defaultValue() { return new Date(); }
}),
author: DS.belongsTo('user'),
post: DS.belongsTo('post')
});
User model:
// app/models/user.js
import DS from 'ember-data';
export default DS.Model.extend({
firstName: DS.attr('string'),
lastName: DS.attr('string'),
posts: DS.hasMany('post'),
comments: DS.hasMany('comment'),
fullName: Ember.computed('firstName', 'lastName', function() {
return `${this.get('firstName')} ${this.get('lastName')}`;
})
});
Index template:
// app/templates/index.hbs
{{#each model as |post|}}
{{post-content post=post}}
{{/each}}
Post template:
// app/templates/components/post-content.hbs
<div class="post-main">
<h5 class="post-author-name">{{post.author.fullName}}</h5>
<div class="post-timestamp">
<h5 class="time-in-words">{{moment-from-now post.createdAt interval=1000}}</h5>
</div>
<div class="post-content">
<h2 class="post-title">{{post.title}}</h2>
<p class="post-body">{{post.body}}</p>
</div>
<div class="post-actions">
<h6>Comments ({{post.comments.length}})</h6>
</div>
</div>
<ul class="post-comments">
{{#each post.comments as |comment|}}
{{post-comment comment=comment}}
{{/each}}
</ul>
Comment template:
// app/templates/components/post-comment.hbs
<!-- This is blank -->
<h5>{{comment.author.fullName}}</h5>
<!-- This is not blank -->
<p>{{comment.body}}</p>