How to change colour of single bar in Material UI when using BarChart?

I’m using the following code to make a Graph:

const namesArray = Object.values(tableData).map(item => item.name);
  const valuesArray = Object.values(tableData).map(item => item.value);

  return (
    <Box>
      <SimpleCard title="Cell Voltages">
        <BarChart
          width={750}
          height={300}
          series={[
            { data:valuesArray, id: 'cId'},
          ]}
          xAxis={[{ data: namesArray, scaleType: 'band' }]}
        />
      </SimpleCard>
    </Box>
  );

And I’m getting this as output:
Graph output

However, I need to change the colour of a particular bar in this graph (currently highest and lowest values), but I can’t seem to find any way to do this. I also didn’t understand the documentation of the API on their website properly. What should I do to get the result I want?

Thank You.

how to check if a tab opened using window.open() is still running or shut or refreshed?

 const newWindow = window.open(
      "",
      "_blank",
      "width=800,height=600,left=2000,top=0"
    );

    if (newWindow) {
      const specificDivContent = document.getElementById(
        `slide-${slideIndex}`
      ).innerHTML;

above is the code i am using to create a new tab and write an existing div onto that tab. i would like to call an api when the new window that is opened is refreshed or closed.
tried using these listeners below.

 window.addEventListener("beforeunload", function(event) {
    // Prevent the user from leaving the page.
    console.log('tried closing the window')
    event.preventDefault();
  });
  
  function checkWindowClosed() {
    if (window.closed) {
      console.log('window closed')
    } else console.log('still open')
  }
  
  setInterval(checkWindowClosed, 1000);

Loading a txt file, splitting it using `split(“|”)` and then displaying it on screen [closed]

I’ve got a txt file like this below:

                                         .-/+ossooooooo+/:.                                         
                                   `:osydhyo++:     :yyyyydN@ho:`                                   
                                :sho:``.       .+o``d@h./N@@@@@@@@s:                                
                             -s@dd-           :--@s@@@@@@@@@@@@@@@@@Ny:                             
                           /dho`.              ///N@yy::@@@@N+y@dNhd@N@@+`                          
                         /ho`                 `@@@/-   `:::sdosNdd@@@o@@@N+                         
                       .h+                   :o@@@@@@@@/:---:::::o@@@@@@@@@@-                       
                      /h.                 `+s@@@@@@@@@@@@@@@@@@@@dy@@@@Nd@@@@o                      
                     oy`                  :@@@@@@@@@@@@@@@@@@@@@@Nyyo@@@yNdsh@s                     
                    +h:                 -od@@@@@@@@@@@@@@@@@@@@@@@@N.y@@@@@:`+@s                    
                   -@``                 y@@@@@@@@@@@@@@@@@@@@@@@@@@@N@-d@@N-``o@:                   
                   h/                   y@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@h--.```.s@                   
                  .NN@y.`                 hh@@@@@@dhhhN@@@@@@@@@@@@@@@@@@@s````-N:                  
                  /dN@@@o`                 `yyyyyy    syN@@@@@@@@@@@@@@@@h+`````so                  
                  o@@@@@@s//                            h@@@@@@@@@@@@@Nd+-``````oy                  
                  +N@@@@@@@No++                         h@@@@@@@@@@@@@d:.```````ss                  
                  .N@@@@@@@@@@@`                        /+N@@@@@@@@@@@s`````````d:                  
                   dh@@@@@@@@N/`                          @@@@@@@@@@@@/````````:@                   
                   -@o@@@@@@@@-                         yh@@@@@@@@@@@N.ydy````.d/                   
                   oy:@@@@@NNs                         ./@@@@@@@@@N-.:@N:````sy                    
                     syh@@@@d`                           o@@@@@@@Nd+``y+`````oy                     
                      +hh@@@N-                           oh@@@@Nd/`````````.ys                      
                       -hhN@@`                            oN+++:-`````````/d:                       
                         +ddd.                            ..````````````:yo`                        
                          `+@d:                             ``````````/yo`                          
                             :yh/                         `````````:sy/                             
                               `/ss+-                   ```````-+ss/`                               
                                  ./oss+:-`   `-::::///++oyyso/.                                   
                                        `-:+oooyhhhhhyso+/-`                                        
|
                                         .-/+ossooooooo+/:.                                         
                                   `:osydhhs++/.    ./hsyyh@@ho:`                                   
                                :sdy:` .`       .+o .@@y.o@@@@@@@@s:                                
                             -sNh@o`           ::.@y@@@@@@@@@@@@@@@@Ny:                             
                           /dds-``              -//@Nyy+-N@@@N+h@@Nh@N@@+`                          
                         /ds.                   d@@s:   `:::odssNd@@@hy@@N+                         
                       .ho`                   -:N@@@@@@@y:---::::/o@@@NN@@@@-                       
                      /d.                   :o@@@@@@@@@@@@@@@@@@@@@y@@@@N@@@@o                      
                     oh`                    d@@@@@@@@@@@@@@@@@@@@@@yho@@@y@hyNs                     
                    +h-`                  +o@@@@@@@@@@@@@@@@@@@@@@@@@-o@@@@@.:@s                    
                   -@``                  `@@@@@@@@@@@@@@@@@@@@@@@@@@@N@:h@@d.`-@:                   
                   h/ `                  .d@@@@@@@@@@@@@@@@@@@@@@@@@@@@@d--.```/@                   
                  .Ny@@+.`                 :h@@@@@@Nhhhd@@@@@@@@@@@@@@@@@@@o````@:                  
                  /hh@@@@+`                  -yyyyyo   `yh@@@@@@@@@@@@@@@@h/````so                  
                  oh@@@@@@s//                            `@@@@@@@@@@@@@@@o-`````oy                  
                  +h@@@@@@@@@o++.                        `@@@@@@@@@@@@@N/.``````ss                  
                  .N@@@@@@@@@@@@+                        `+s@@@@@@@@@@@d````````d:                  
                   doN@@@@@@@@@+-                          :@@@@@@@@@@@o```````:@                   
                   -@-@@@@@@@@@+                         :h@@@@@@@@@@@@-s@s```.d/                   
                    oy d@@@@@@Nd                         `.d@@@@@@@@@/.:N@-```sy                    
                     sy+@@@@@d`                           `N@@@@@@@ds``s/````oy                     
                      +h+N@@@@-                           -yN@@@Ndo````````.ys                      
                       -hod@@h                             -@s++/-````````/d:                       
                         +hy@o                             `-```````````:yo`                        
                          `+h@+                             ``````````/yo`                          
                             :yd+`                        `````````:sy/                             
                               `/ss+- `                 ```````-+ss/`                               
                                   ./osyo:-`   ``:::////++osyso/.                                   
                                        `-:+oooyhhhhhyso+/-`                                        
|
                                        .-/+osysoooooo+/:.                                         
                                   `:osyhdhy+++:`    -sdyhh@@ho:`                                   
                                :odd/` `.        -oo [email protected]@@@@@@@s:                                
                             -sN@h@:            -:`Ny@@@@@@@@@@@@@@@Ny:                             
                           /dNyo .               .//h@yyo-d@@@Nod@@@hNN@+`                          
                         /@y:                    +@@d:`  `-//+dyoNd@@Nyd@N+                         
                       .dy.                    `:y@@@@@@@@:---::::/o@@@@@@@@-                       
                      /d-                    `oy@@@@@@@@@@@@@@@@@@@NyN@@@@N@@o                      
                     oh.                     :@@@@@@@@@@@@@@@@@@@@@@yhoN@NhNy@s                     
                    +h`/                   .oh@@@@@@@@@@@@@@@@@@@@@@@@/o@@@@o.hs                    
                   -@```                   o@@@@@@@@@@@@@@@@@@@@@@@@@@N@/h@@s`.@:                   
                   ho ``                   odN@@@@@@@@@@@@@@@@@@@@@@@@@@@@--.``:@                   
                  .N/@@@:.`                  ohN@@@@@@hhh@@@@@@@@@@@@@@@@@@@/```d:                  
                  /h/@@@@@+.                   +yyyyy:   /yd@@@@@@@@@@@@@@Ny:```so                  
                  oyd@@@@@@y//.                            +@@@@@@@@@@@@@@o-````oy                  
                  +hh@@@@@@@@@y++/                         +@@@@@@@@@@@@@/.`````ss                  
                  .No@@@@@@@@@@@@d                         -+d@@@@@@@@@@@```````d:                  
                   d/y@@@@@@@@@@y:                           h@@@@@@@@@@y``````:@                   
                   -@`o@@@@@@@@@y                          shN@@@@@@@@@@:s@+``.d/                   
                    oy -@@@@@@@@N.                         ./@@@@@@@@@+.:Nd.``sy                    
                     sy.@@@@@@@`                            s@@@@@@@@y``s:```oy                     
                      +h-d@@@@@-                            s@@@@@ds```````.ys                      
                       -h/o@@@s                             `@h++/-```````/d:                       
                         +h+d@:                             `-``````````:yo`                        
                          `+ydy.                            ``````````/yo`                          
                             :sdo.                        `````````:sy/                             
                               `/ss+-                   ```````-+ss/`                               
                                   ./ooyo/-`    `.:::///++ooyso/.                                   
                                        `-:+oooshhhhhyso+/-`                                        

I wanted to first load it into my index.js file, and then splitting it using split("|"). I don’t know how to import it to my JS.

I want to display every frame of this (frames are seperated by ‘|’ pipe character) with a small delay between frames on screen. (I also don’t know exactly how to put delay between the frames. Please help me with that, too)

I tried loading the file using the XMLHttpRequest() approach, but I noticed that this has been deprecated. The code below is how I used this approach:

function readTextFile(file) {
    let rawFile = new XMLHttpRequest();
    rawFile.open("GET", file, false);
    rawFile.onreadystatechange = function () {
        if (rawFile.readyState === 4) {
            if (rawFile.status === 200 || rawFile.status == 0) {
                let allText = rawFile.responseText;
                allTextLines = allText.split("|");
            }
        }
    };
    rawFile.send(null);
    return null;
}

readTextFile("earth-anim.txt");

I even tried loading the txt file using FileReader() like here:

let reader = new FileReader();
let data = ["earth.anim.txt"];

reader.onload = function () {
    allTextLines = reader.result.split("|");
};

reader.readAsText(data);

But I get this error:

index.js:27 Uncaught TypeError: Failed to execute 'readAsText' on 'FileReader': parameter 1 is not of type 'Blob'.
    at index.js:27:8

I also tried setTimeout() to put delay between the frames (with for loop), but it didn’t work well. I used this approach like this:

for (let index = 0; index < allTextLines.length; index++) {
    if (index === allTextLines.length) {
        index = 0;
    } else {
        setTimeout(() => {
            preEl.textContent = allTextLines[index];
        }, 1000);
    }
}

How to Block the navigation in react router dom v6?

Actually, In our application we were showing modal if form is not saved with help of history.block() in react router dom v5. But Latest version v6 its removed. Please find the acutally code below. Help me to achieve same this lastest version 6.

  useEffect(() => {
    if (show) {
      history.block((prompt, action) => {
        // Define a call back for history.block if the user navigates to any other route
        // action is POP when user hits back button
        if (action !== 'POP') {
          if (!prompt.pathname.includes(match.url) && !ALLOWED_PATHS.includes(prompt.pathname)) {
            setCurrentPath(prompt.pathname);
            setShowPrompt(true);

            return 'true';
          }
        }
      });
    } else {
      // defining an empty call back would remove any blocking of route navigation
      history.block(() => {});
    }

    return () => {
      history.block(() => {});
    };
  }, [history, show, match.url, ALLOWED_PATHS]);

Adjusting the css scroll bar track to move it x px to right and y px down

I have an HTML table which has overflow: auto. I get two scroll bars: horizontal and vertical.

I have made the first row and first column sticky, ie. they do not move with the scroll.

The problem is the scroll bar track is starting from the first row vertically and first column horizontally. I want the scroll bar track to be placed or to be started from the second column horizontally and second row vertically

I should get the scroll bar to be like this in the image shown here

Why is my JS-program behaving differently with/without the two ‘problem lines’?

The problem lines are in the bottom.


<!DOCTYPE html>
<html ><head><meta charset='utf-8'/>
 <style type="text/css"><!-- #containerID { position: relative; } #canvasID { border: 1px solid #000; } #imageTemp { position: absolute; top: 1px; left: 11px; } --></style>
<div id="containerID" style="touch-action:none; width: 100px; height: 500px; overflow: auto;">
<canvas id='canvasID'  width='80' height='80' style='margin-left:10px;background:white;border:solid black 1px; touch-action:none; '>
  Your browser does not support canvas element.
</canvas>
</div>
<script type='text/javascript'>
  var el = document.getElementById("canvasID");
  var elcontainer = document.getElementById("containerID");
  var ctx = el.getContext('2d');
  var startpuntX, startpuntY, eindpuntX, eindpuntY;
  var startDrawing = false;
  var container = el.parentNode;     // Add the temporary canvas.
  var containerHandletje = document.getElementById('containerID');
  var ongoingTouches = new Array();
  var huidigeKleur = 'black';
  var huidigeDikte = 2;
  var selectie = document.getElementById('drawingtoolID');
    elcontainer.setAttribute("style", 'width: '+(window.innerWidth-12)+'px; height: '+(window.innerHeight-80)+'px; overflow: auto;');
    el.height = window.innerHeight-90;
    el.width = window.innerWidth-42;
    canvaslayer = document.createElement('canvas');
    canvaslayer.id     = 'imageTemp';
    canvaslayer.width  = el.width;
    canvaslayer.height = el.height;
    canvaslayer.style = 'touch-action:none;';
    container.appendChild(canvaslayer);
    ctxlayer = canvaslayer.getContext('2d');
    ctxlayer.lineCap = 'round';
    ctx.lineWidth = 1;
    ctx.lineJoin = 'round';
    ctx.lineCap = 'round';
  ctx.fillStyle = 'white'
  ctx.fillRect(0, 0, el.width, el.height);
  ctx.lineWidth = huidigeDikte;
canvaslayer.removeEventListener('pointerdown', handleStart, false);
canvaslayer.removeEventListener('pointerup', handleEnd, false);
canvaslayer.removeEventListener('pointercancel', handleCancel, false);
canvaslayer.removeEventListener('pointermove', handleMove, false);
canvaslayer.addEventListener('pointerdown', handleLineStart, false);
canvaslayer.addEventListener('pointerup', handleLineEnd, false);
canvaslayer.addEventListener('pointermove', handleLineMove, false);
function handleStart(evt) {
    ongoingTouches.push(copyTouch(evt));
    ctx.beginPath();
    ctx.moveTo(evt.clientX - el.offsetLeft + pageXOffset + containerHandletje.scrollLeft, evt.clientY - 0.1 - container.offsetTop + pageYOffset + containerHandletje.scrollTop);
    ctx.lineTo(evt.clientX - el.offsetLeft + pageXOffset + containerHandletje.scrollLeft, evt.clientY - container.offsetTop + pageYOffset + containerHandletje.scrollTop);
    ctx.stroke();
}
function handleMove(evt) {
  var idx = ongoingTouchIndexById(evt.pointerId);
  if (idx >= 0) {
    ctx.beginPath();
    ctx.moveTo(ongoingTouches[idx].pageX - el.offsetLeft + pageXOffset + containerHandletje.scrollLeft, ongoingTouches[idx].pageY - container.offsetTop+pageYOffset + containerHandletje.scrollTop);
    ctx.lineTo(evt.clientX - el.offsetLeft + pageXOffset + containerHandletje.scrollLeft, evt.clientY - container.offsetTop+pageYOffset + containerHandletje.scrollTop);
    ctx.stroke();
    ongoingTouches.splice(idx, 1, copyTouch(evt));  // swap in the new touch record
  }
}
function handleEnd(evt) {
  var idx = ongoingTouchIndexById(evt.pointerId);
  if (idx >= 0) {
    ctx.beginPath();
    ctx.moveTo(ongoingTouches[idx].pageX - el.offsetLeft + pageXOffset + containerHandletje.scrollLeft, ongoingTouches[idx].pageY - container.offsetTop + pageYOffset);
    ctx.lineTo(evt.clientX - el.offsetLeft + pageXOffset + containerHandletje.scrollLeft, evt.clientY - container.offsetTop + pageYOffset + containerHandletje.scrollTop);
    ongoingTouches.splice(idx, 1);  // remove it; we're done
  }
}
function handleCancel(evt) {
alert('BOE-CANCEL'); 
  var idx = ongoingTouchIndexById(evt.pointerId);
  ongoingTouches.splice(idx, 1);  // remove it; we're done
}
function copyTouch(touch) {
  return { identifier: touch.pointerId, pageX: touch.clientX, pageY: touch.clientY };
}
function ongoingTouchIndexById(idToFind) {
  for (var i = 0; i < ongoingTouches.length; i++) {
    var id = ongoingTouches[i].identifier;
    if (id == idToFind) { return i; }
  }
  return -1;
}
function handleLineStart(evt)
{
startpuntX = evt.clientX - el.offsetLeft + pageXOffset + containerHandletje.scrollLeft;
startpuntY = evt.clientY - container.offsetTop + pageYOffset + containerHandletje.scrollTop;
ctxlayer.lineWidth = huidigeDikte;
ctxlayer.strokeStyle = huidigeKleur;
ctxlayer.fillStyle = huidigeKleur;
startDrawing = true;
ctxlayer.stroke();
ctxlayer.beginPath();
handleLineMove(evt);
}
function handleLineMove(evt)
{
var x,y,w,h,hokDx,xi,yi,asX,asY,asXeind,asYeind,fontsize,dzx,dzy,situatie;
if (startDrawing)
{
eindpuntX = evt.clientX - el.offsetLeft + pageXOffset + containerHandletje.scrollLeft;
eindpuntY = evt.clientY - container.offsetTop + pageYOffset + containerHandletje.scrollTop;
ctxlayer.clearRect(0, 0, el.width, el.height);
ctxlayer.beginPath();
ctxlayer.moveTo(startpuntX,startpuntY);
x = Math.min(startpuntX,  eindpuntX);
y = Math.min(startpuntY,  eindpuntY);
w = Math.abs(startpuntX - eindpuntX);
h = Math.abs(startpuntY - eindpuntY);
ctxlayer.strokeRect(x,y,w,h);
ctxlayer.stroke();
ctxlayer.beginPath();
}
}
function handleLineEnd(evt)
{
{
startDrawing = false;
var dummy = ctx.getImageData(3,3,5,5); // problem line
var dummy = ctx.getImageData(3,3,5,5); // problem line
ctx.drawImage(canvaslayer, 0, 0);
ctxlayer.clearRect(0, 0, el.width, el.height);
}
}
</script>
</body></html>

I ripped off all the lines not necessary to show the problem.

Without the two lines: I can draw multiple rectangles on the ctx
With the two lines: Each rectangle is overwritten by the next rectangle.

There are no more details. But It seems necessary to write more lines because I have too much code in my question.

extract information from a pdf converted to image

I have scanned a form and filled it with data by hand, now I have created the form with javascript and I am trying to read from a pdf in which there are images the data of the text boxes of that image so that they are shown in the boxes of the form I have created.
I have created a class that converts the pdf into an image and it is the image that I have to read to get the coordinates of the image from the form.

I need to create a class with java and read the coordinates of those boxes that are filled to appear in my form but I do not know how to do it. My browser is google, how can I read the exact coordinates where each box is located and get the information inside each box?

The important thing is to show in the form what is inside each text box.

how to get the object by array of object and arraylist based on condition using javascript

I have array of object arrobj and arrlist prgList,

I need to fetch the name from the arrobj based on the programs in the list using javascript.

If the program prg exists in the arrobj , fetch and should display as show in expectd output

tried

var lists=[]
var result =arrobj.find(e=> e.prg.includes(prgList) ? lists.push(e))); // bit stuck

varr arrobj=[
  {id:1, name: "user1", prg: ["onex", "twox", "threex"]},
  {id:2, name: "user2", prg: ["onex", "threex"]},
  {id:3, name: "user3", ["twox", "threex"]}
]

var prgList =["onex", "twox", "threex"]

Expected Output:

 {
   onex: ["user1", "user2"],
   twox: ["user3"],
   threex: ["user1", "user2", "user3"]
 }

How to pass data through a Link in React? [duplicate]

I was trying to create an e-commerce app where I have a page with a list of products and on clicking on one of the products it goes into a separate product detail page. But I’m getting null data in the product details page.

import React, { useEffect, useState } from "react";
import Card from "../Cards/Card";
import "./SustainabilityProducts.css";
import axios from "axios";
import { Link } from 'react-router-dom';

function SustainabilityProducts() {
  const [data, setData] = useState([]);

  const sustainabilityProductsData = async () => {
    const result = await axios.get(`http://localhost:8081/products/category?productCategory=Sustainable Products`);
    setData(result.data);
  };

  useEffect(() => {
    sustainabilityProductsData();
  }, []);

  return (
    <div className="sustainabilityProducts">
      <div className="headingText">
        <div>
          <h3 className="heading">Sustainable Products</h3>
        </div>
        <div className="Description">
          <p classname='page-description' style={{ color: "#C9C9C9", paddingLeft: "5%" }}>
            Your finances and investments can also be green. We offer various
            financial products that are environmentally friendly.
          </p>
        </div>
        <div>
          <h5 className="heading-secondary">Select a Type</h5>
        </div>
      </div>
      <div className="cardsList">
        {data.map((card) => (
          <div className="cards" key={card.productId}>
            <Link to={{
              pathname: '/product-details', 
              state: { productTitle: card.productName }
            }}>
              <Card
                img={card.imageUrl}
                title={card.productName}
                desc={card.productDescription}
              />
            </Link>
          </div>
        ))}
      </div>
    </div>
  );
}

export default SustainabilityProducts;
import React from 'react'
import car from '../../Images/car.png';
import leaf from "../../Images/leaf.jpg";
import './ProductDetails.css';
import { useLocation } from 'react-router-dom';

function ProductDetails() {

  const location = useLocation();
  console.log('Location State:', location.state);
  const productTitle = location.state && location.state.productTitle;

  console.log('Product Title:', productTitle);


  return (
    <div className='basic'>
      <img style={{ width: "100%" }} src={car} alt="car"></img>
      <br />
      <br />
      <div className='basic1'>
        <h1>{productTitle}</h1>
        <img src={leaf} alt="leaf"></img>
        <br />
        <br />
        <h4>
          APR: 5.29%
          <br />
          Term: 60 months
          <br />
          Loan amount: Up to $120,000
          <br />
          Interest rate: 2.79%
        </h4>
        <br />
        <ul className='basic2'>
          <li>Driving an electric vehicle means you would be contributing to environmental sustainability since electric vehicles release fewer harmful carbon dioxide emissions.</li>
          <br /><li>The costs of owning an EV are typically less than a gasoline-powered vehicle.</li>
          <br /> <li>Savings may include a lower cost to charge your electric vehicle (when compared fuel costs) as well as savings on maintenance costs, since EVS typically need less maintenance.</li>
        </ul>
      </div>
      <br />
      <br />
      <div style={{ alignSelf: "center", marginLeft: "-78px" }}><button className='basic3' >Apply Now </button></div>

    </div>
  )
}

export default ProductDetails

These are the two pages. I’m trying to load the product name for now from the API data.