ng2-google-charts component is undefined

I’m using ng2-google-charts with Ionic 6. I’m trying to redraw the gauge chart once the data is updated.

Here is the code that I’m using:

showGauge(value: number) {
    this.gaugeChart = {
      chartType: GoogleChartType.Gauge,
      dataTable: [
        ['PSI', Number(value.toFixed(2))]
      ],
      firstRowIsData: true,
      options: {
        height: 300,
        max: 175,
        chartArea: { height: '200' }
      },
    };

    let c = this.gaugeChart.component;
    c.draw();
  }

But I get the following error, which indicates that the chart component is undefined. How can I solve this and redraw the chart?

Here’s the error:
Error

Can I build and return an array with the setTimeout function? [duplicate]

I have a javascript function that calls setTimeout within a loop. I want to sort some numbers (using a trivial method) from an input based on their values by using the digit as the interval and return the new, sorted array. For example:

function x(nums) {
    let arr = []
   for (let i = 0; i < nums.length; i++) {
    setTimeout(() => {
        arr.push(nums[i])
    }, nums[i])
   }
    return arr
}

console.log(x([2, 3, 1, 4]))

I expect this code to return [1, 2, 3, 4] but it is returning an empty array [] instead. When I use async / await it returns the promise. Is it possible to return the expected output without async / await? When I console.log(arr) within the setTimeout (after the push method), it builds the correct arr and pushes the elements as expected without returning the final result. For this reason, I assume I am not understanding how the setTimeout function works exactly and hoped someone could explain. Thanks.

My topbar duplicates since adding axios and importing the user image with axios and react

I would like to know why my “topbar” is duplicated when I only want one. And it’s since I did my import of the user image via axios and added the .map in the return. I really don’t understand why if someone could help me that would be nice. Thanks in advance
enter image description here

import "./topbar.css"
import { Search } from '@mui/icons-material'
import { useState, useEffect, Fragment } from 'react'
import axios from "axios"


function Home() {

const [user, setPosts] = useState([])



useEffect(() => {
    console.log("chargement ok")
    const fetchData = async () => {
    const result = await axios.get(
    'http://localhost:4200/api/user/')
    setPosts(result.data)
    }
    fetchData();
}, [])


    return (
        <Fragment>
            { user
            ? user.map((users,topbar) => ( <div key={topbar} className="topBarContainer">
                            <div className="topBarLeft">
                                <span className="logo">Groupomania</span>
                            </div>
                            <div className="topBarCenter">
                                <div className="searchBar">
                                    <Search className="searchIcon" />
                                    <input placeholder="Vous cherchez quelque chose ?" className="searchInput" />
                                </div>
                            </div>
                            <div className="topBarRight">
                                <div className="topBarLinks">
                                    <span className="topBarLink">Page d'acceuil</span>
                                    <span className="topBarLink">Deconnexion</span>
                                </div>
                                <img src={users.picture} alt="Photo de profil de l'utilisateur" className="topBarImg" />
                            </div>
                        </div>))
                    : (<p></p>)
            }
        </Fragment>
        )
}
    
export default Home

Discord.js is it possible to send message components before and after an embed?

I want to send an Embed that has an Action Row before and after the embed, while also keeping the whole thing ephemeral. The usage is for a bot menu where the top buttons would be constant and have stuff like a leaderboard and help menu while the bottom buttons would change depending on the users role. If it isn’t possible, no big deal I can send them both after but it would go a long way in helping the user navigate through our embeds.

Alguem pode me ajudar? Quando eu clico pra pesquisar no chrome ele dá esses erros ao lado. Já no opera ele abre normalmente [closed]

my4.js:1 Access to XMLHttpRequest at ‘https://www.micromoney.com.br/contrachequeonlineapp/arquivos/00067/mat/cc000670520221_55505171320.html’ from origin ‘http://www.micromoney.com.br’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.
_0xa77881 @ my4.js:1
(anônimo) @ my4.js:1
dispatch @ jquery-1.9.1.min.js:3
v.handle @ jquery-1.9.1.min.js:3
my4.js:1 HEAD https://www.micromoney.com.br/contrachequeonlineapp/arquivos/00067/mat/cc000670520221_55505171320.html net::ERR_FAILED 200
_0xa77881 @ my4.js:1
(anônimo) @ my4.js:1
dispatch @ jquery-1.9.1.min.js:3
v.handle @ jquery-1.9.1.min.js:3
my4.js:1 Uncaught DOMException: Failed to execute ‘send’ on ‘XMLHttpRequest’: Failed to load ‘https://www.micromoney.com.br/contrachequeonlineapp/arquivos/00067/mat/cc000670520221_55505171320.html’.
at _0xa77881 (http://www.micromoney.com.br/contrachequeonlineapp/js/my4.js:1:8677)
at HTMLAnchorElement. (http://www.micromoney.com.br/contrachequeonlineapp/js/my4.js:1:4010)
at HTMLAnchorElement.dispatch (http://www.micromoney.com.br/contrachequeonlineapp/js/jquery-1.9.1.min.js:3:28337)
at v.handle (http://www.micromoney.com.br/contrachequeonlineapp/js/jquery-1.9.1.min.js:3:25042)

Angular error with mat-select form control: Error: No value accessor for form control with name: ‘level’

I am trying to setup a basic form using a drop down list for a form control. I can get it to work with other kinds of inputs but never mat-select.

Any help would be greatly appreciated as this is eating up my entire day.

HTML

<div [formGroup]="formSubmission">
  <mat-form-field appearance="fill">
  <mat-label>Level</mat-label>
    <mat-select 
    formControlName="level"
    >
      <mat-option [value]=1>1</mat-option>
      <mat-option [value]=2>2</mat-option>
    </mat-select>
</mat-form-field>

Component

import { Component, OnInit, ViewChild } from '@angular/core';
import {FormControl, Validators, FormGroup, FormBuilder} from '@angular/forms';

@Component({
  selector: 'test',
  templateUrl: '.test.html',
  styleUrls: ['.test.scss']
})
export class TestComponent implements OnInit {

  formSubmission: FormGroup;

  constructor(
    ) {  
      this.formSubmission = new FormGroup(
        {
          level: new FormControl({value: '', disabled: false}, [ Validators.required]),
        }
      )
    }

  async ngOnInit() {
    this.formSubmission.statusChanges.subscribe( (status) => {
      console.log(status); //status will be "VALID", "INVALID", "PENDING" or "DISABLED"
      if (status === 'VALID') {
      } else {
      }
    })
   
    }
}

I am currently receiving the following in my console:

Error: No value accessor for form control with name: ‘level’

Check if current seconds is inbetween start and end time [duplicate]

I have a video player which is returning seconds while playing video. Now I have startTime and endTime which are in HH:mm:ss:ss format (eg. 00:06:29:50). I want to check if the current second is in between the startTime and endTime.

I tried to convert seconds and startTime/Endtime into unix format using dayJS but it won’t work. Can someone please provide me a better idea?

Javascript reduce() on array of objects, with entries being simple variables and array as well

I’m trying to use a reduce function in order to iterate through an array of objects and to get an output summing up the data shown inside of the array of objects (a kind of duplicate remover in fact).

On data such as :

mainData = [
   {data : {name: "item1", color: "red", type: ["metal", "wood"]}, id: 1},
   {data : {name: "item2", color: "green", type: ["wood"]}, id: 2},
   {data : {name: "item3", color: "green", type: ["wood", "stone", "marble"]}, id: 3},
   {data : {name: "item4", color: "red", type: ["stone"]}, id: 4}
]

when using the function :

const getValues = (data, key) => {
    return data.reduce((acc, item) => {
        if(acc.indexOf(item.data[key]) > -1) {
            return [...acc]
        } else {
            return [...acc, item.data[key]]
        }
    }, [data[0].data[key]]) //initial value
}

It will fork fine if I call this getValues function getValues(mainData, "color") for the color key,
giving the following output : ["red", "green"], which is expected.

But if i call the function with getValues(mainData, "type"), this function will ignore most of the values from the array type value from the key type.

I tried to solve it by using a for loop limited by data["type"].length just before the if...else condition of the reduce function, like this :

const getValues = (data, key) => {
    return data.reduce((acc, item) => {
        for(let i = 0; i < item.data[key].length; i++) {
            if(acc.indexOf(item.data[key][i]) > -1) {
                return [...acc]
            } else {
                return [...acc, item.data[key][i]]
            }
        }
    }, [data[0].data[key][0]])
}

But it does not work either.

Anyone has an idea of how to solve this ?

What is Historical Forex Data and How can I get it?

This is what I read on TraderMade.

When it comes to forex trading a lot of time and effort is needed to develop insight into the markets, many market participants have been in the game for many years and have first-hand experience of market patterns, from this they have developed instincts based on past experience.

Subconsciously what these experienced traders are doing is recalling what the markets have done in the past and predicting a repeat of this action. For traders new to the markets they do not have this experience so need to look for insight in other ways for this, they can use the raw historical data, in theory, the data is just a record of how the market behaves.

Read the full blog on the website https://tradermade.com/blog/historical-forex-data-explained-and-how-can-i-get-it/

Javascript filter a big array of objects with the values in a single object

I am trying to filter a result set returned from an API call. The result set contains an array of strongly typed objects. I’ll call this resultsArray for the sake of this question.

The values I’m attempting to filter the resultsArray with come from n criteria found in a second object we’ll call filterObject. The property names in the filterObject are the same as the property names in the resultsArray. So, during the iteration process of the resultsArray when a matching property is encountered in the two entities, and the value in resultsArray matches the value in filterObject, that matching row from resultsArray is accepted.

Effectively, if no criteria has been entered into the filterObject the entire resultsArray is returned and displayed. Entering criteria will refine the results to the point where only the records matching all of the criteria entered will be displayed.

Here’s what I have in the filterObject:

const filterObject = {
  usdotnumber: '13',
  mcnumber: null,
  mxnumber: null,
  ffnumber: null,
  vatnumber: '12345',
  nvocc: null,
};

In “real life”, the values are supplied by a UI form, so all properties could be null, which would cause all records returned from the API call to be displayed. However, using the example above, all returned records would be filtered and only those with the usdotnumber = 13 and vatnumber = 12345 would be displayed.

I’ve tried to implement various solutions found during web searches, but I can’t seem to find one that compares an object to an array of objects for the filtering. Most of them are object to object or array to array. It’s enough of a distinction that the errors I’m encountering are things like “key is not indexable” on the filterObject which, of course, is correct because it’s not an indexable entity. It’s only one item with multiple properties and their associated values.

Populate next empty text input based on a button click

I have a simple set of buttons that may be clicked in any order. When clicked the button should fill the next available text box.

So far I have only been able to make the button click populate the text box that is in focus. This only really fulfils half of my task.

At the moment I am only looking for vanilla JS solutions rather than JQuery if possible.

<body>

    <div class="buttons">

        
        <button class="btn" id="txt1" onclick="addText('txt1')">txt1</button>
        <button class="btn" id="txt2" onclick="addText('txt2')">txt2</button>
        <button class="btn" id="txt3" onclick="addText('txt3')">txt3</button>
        <button class="btn" id="txt3" onclick="addText('txt3')">txt3</button>
        <button class="btn" id="txt4" onclick="addText('txt4')">txt4</button>
        <button class="btn" id="txt5" onclick="addText('txt5')">txt5</button>
       
    </div>

    <div class="textBoxes">
          <input type="text" class="inputs" id="box1" placeholder="WPT 1" onfocus="field=this;" autofocus>
          <input type="text" class="inputs" id="box2" placeholder="WPT 2" onfocus="field=this;">  
          <input type="text" class="inputs" id="box3" placeholder="WPT 3" onfocus="field=this;">  
          <input type="text" class="inputs" id="box4" placeholder="WPT 4" onfocus="field=this;">  
          <input type="text" class="inputs" id="box5" placeholder="WPT 5" onfocus="field=this;">  


  

var field = 0;
function addText(txt){
if(field === 0) return false;
field.value = txt;
}

console.log shows that the prop has attributes name and number, but they are undefined

So I have the following code, where I would like to return the number of pages in a book inside of the Part component in the return props.pages. The console.log(props) prints out the attributes of the book (name and pages). However when accessing them in the Part component via props.pages or props.name it returns undefined?

How would I go about fixing this

const Part = (props) => {
  console.log(props);
  return <p>{props.pages}</p>;
};

const Content = (props) => {
  console.log(props);
  return <Part props={props} />;
};


const App = () => {
  const book1 = {
    name: "Harry Potter",
    pages: 108,
  };


  return (
    <div>
      <Content book={book1} />
    </div>
  );
};

export default App;

Google Charts – avoid showing negative values ​on axis

Even including vAxis: {minValue:0} didn’t work

How can I do to avoid showing negative values in the yAxis?

This happens when no value exists.
In this case I don’t want negative values ​​to appear on the axis

google.charts.load('current', {packages: ['corechart','bar'],'language': 'pt'});
 google.charts.setOnLoadCallback(drawChart);
 
  function drawChart() {

            var arrayToData = [['Date','','Data',{role: 'style'},{role:'tooltip', 'p': {'html': true}}]];

            arrayToData.push(['01/06', 0,0,'','']);
                    arrayToData.push(['02/06', 0,0,'','']);
                    arrayToData.push(['03/06', 0,0,'','']);

            var data = new google.visualization.arrayToDataTable(arrayToData);

            var options = google.charts.Bar.convertOptions(
                {
                tooltip: {isHtml: true},
                chartArea: {
                    height: '100%',
                    width: '100%',
                    top: 38,
                    left: 15,
                    right: 100,
                    bottom: 48
                },
                vAxis: {
               
                    viewWindow:{
                        min: 0
                    }
                },
                yAxis:{
                viewWindowMode: "explicit",
                viewWindow:{
                        min: 0
                    }
                },
                

                series: {
                    0: {enableInteractivity: false,targetAxisIndex: 0, visibleInLegend: false, pointSize: 0, lineWidth: 0,type: 'line',textStyle: {fontSize: 0}},
                    1: { targetAxisIndex: 1, }
                },
                vAxes: {
                    0: {textPosition: 'none'},
                    1: {},
                },

            });
            
        var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
                chart.draw(data, options);
         
      
        }
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
  <div id="chart_div"></div>

I’ve tried several alternatives and none have been successful.