JavaScript Spacing and size of horizontal bars in a Victory stack?

I have a simple 3 part horizontal bar chart like so:

enter image description here

You can check it out on CodeSandbox or try out the code:

function App() {
  return (
    <VictoryStack colorScale={['#D0021B', '#F5A623', '#00C16F']}>
      <VictoryBar horizontal data={[{ x: 'progress', y: 50 }]} />
      <VictoryBar horizontal data={[{ x: 'progress', y: 25 }]} />
      <VictoryBar horizontal data={[{ x: 'progress', y: 25 }]} />
    </VictoryStack>
  )
}

I am having issues with 2 parts:

  1. How can I make the height of these 3 bars taller (I guess technically the width because I made it horizontal)?
  2. How can I add a bit of spacing between each bar? Meaning like 2px of space between the red, orange, and green bars.

I've tried a bunch of stuff while looking at the VictoryStack docs and VictoryBar charts, but I haven't been able to get it to work. Any help would be appreciated, thanks!

Answer:1
  1. You can use a property barWidth to set the width of bars:

    <VictoryBar
        horizontal
        barWidth={30}
        data={[{ x: 'progress', y: 50 }]}
    />
    

    Or there is one more way through its style:

    <VictoryBar 
        horizontal 
        style={ { data: { width:30 } } } 
        data={[{ x: 'progress', y: 25 }]}
    />
    
  2. To make spaces between the bars, try playing with the y0 property:

    <VictoryBar
        horizontal
        data={[{ x: 'progress', y: 25, y0: 77 }]}
    />
    

To portray the whole solution here is your slightly refined Sandbox.

Answer:2

Here is a working snipped solution with:

barWidth props for bar height

a style prop is added to in order to simulate margin with borders

https://codesandbox.io/s/7y2ym084o6

import React from "react";
import ReactDOM from "react-dom";
import { VictoryStack, VictoryBar } from "victory";

function App() {
  return (
    <VictoryStack
      style={{
        data: {
          stroke: "rgba(255,255,255,1)",
          strokeWidth: 2
        }
      }}
      colorScale={["#D0021B", "#F5A623", "#00C16F"]}
    >
      <VictoryBar barWidth={30} horizontal data={[{ x: "progress", y: 50 }]} />
      <VictoryBar barWidth={30} horizontal data={[{ x: "progress", y: 25 }]} />
      <VictoryBar barWidth={30} horizontal data={[{ x: "progress", y: 25 }]} />
    </VictoryStack>
  );
}

const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
Answer:3

i am trying to set up an user level authentication using node.js, so i go and do npm install -g jsonwebtoken --save. However, i run into problems when i use require('jsonwebtoken'); and try to compile ...

i am trying to set up an user level authentication using node.js, so i go and do npm install -g jsonwebtoken --save. However, i run into problems when i use require('jsonwebtoken'); and try to compile ...

  1. cannot find module 'node-sass'
  2. cannot find module '@angular/core'
  3. cannot find module '@angular/http'
  4. cannot find module '@angular/compiler-cli'
  5. cannot find module 'typescript'
  6. cannot find module 'express'
  7. cannot find module '@babel/core'
  8. cannot find module '@angular/compiler-cli/ngcc'
  9. cannot find module providing package
  10. cannot find module '@angular-devkit/build-angular/package.json'
  11. cannot find module '../lib/utils/unsupported.js'
  12. cannot find module 'webpack-cli/bin/config-yargs'
  13. cannot find module for path
  14. cannot find module 'rxjs-compat/observable'
  15. cannot find module 'webpack'
  16. cannot find module react
  17. cannot find module angular
  18. cannot find module 'babel-preset-env'
  19. cannot find module '@babel/runtime/helpers/interoprequiredefault'
  20. cannot find module 'babel-preset-es2015'

I just found an unexpected behavior where I have placed a timeStamp (Date) inside a hidden form field. When submitting the (update) form I made some checks on the document delta (because I only want ...

I just found an unexpected behavior where I have placed a timeStamp (Date) inside a hidden form field. When submitting the (update) form I made some checks on the document delta (because I only want ...

  1. javascript date from string
  2. javascript date from timestamp
  3. javascript date from milliseconds
  4. javascript date from epoch
  5. javascript date from utc
  6. javascript date from seconds
  7. javascript date from number
  8. javascript date from ticks
  9. javascript date from datetime
  10. javascript date from string format
  11. javascript date from time
  12. javascript date from year month day
  13. javascript date from json
  14. javascript date from ms
  15. javascript date from now
  16. javascript date from utc timestamp
  17. javascript date from string with timezone
  18. javascript date from string without timezone
  19. javascript date from yyyy-mm-dd
  20. javascript date from mm/dd/yyyy

In this code example: let result = (async (global) => { // other code here (includes await's; thus the async) return 123; })(this); The code works, but the return'ed value is nowhere to be ...

In this code example: let result = (async (global) => { // other code here (includes await's; thus the async) return 123; })(this); The code works, but the return'ed value is nowhere to be ...

  1. possible value of x
  2. possible value of random variable
  3. possible value of position attribute
  4. possible value of the correlation coefficient
  5. possible value of probability
  6. possible value of n
  7. possible value of slope
  8. possible value of quadratic equation
  9. possible value of triangle
  10. possible value of

I have a cylinder bar chart in AmCharts 4 that uses a darker color scheme. The text color for the labels on the bars is black and is not really showing on darker colors. - I am using the javascript ...

I have a cylinder bar chart in AmCharts 4 that uses a darker color scheme. The text color for the labels on the bars is black and is not really showing on darker colors. - I am using the javascript ...