Giter Site home page Giter Site logo

Comments (3)

typpo avatar typpo commented on July 17, 2024

Based on the documentation, you are looking for something like this:

{
  type: 'bar',
  data: {
    datasets: [{
      backgroundColor: 'green',
      data: [50]
    }, {
      backgroundColor: 'yellow',
      data: [100]
    }, {
      backgroundColor: 'orange',
      data: [150]
    }, {
      backgroundColor: 'red',
      data: [200]
    }]
  },
  options: {
    scales: {
      xAxes: [{display: false}],
      yAxes: [{display: false}]
    },
    legend: {display: false}
  }
}

https://quickchart.io/chart?c=%7B%0A%20%20type%3A%20%27bar%27%2C%0A%20%20data%3A%20%7B%0A%20%20%20%20datasets%3A%20%5B%7B%0A%20%20%20%20%20%20backgroundColor%3A%20%27green%27%2C%0A%20%20%20%20%20%20data%3A%20%5B50%5D%0A%20%20%20%20%7D%2C%20%7B%0A%20%20%20%20%20%20backgroundColor%3A%20%27yellow%27%2C%0A%20%20%20%20%20%20data%3A%20%5B100%5D%0A%20%20%20%20%7D%2C%20%7B%0A%20%20%20%20%20%20backgroundColor%3A%20%27orange%27%2C%0A%20%20%20%20%20%20data%3A%20%5B150%5D%0A%20%20%20%20%7D%2C%20%7B%0A%20%20%20%20%20%20backgroundColor%3A%20%27red%27%2C%0A%20%20%20%20%20%20data%3A%20%5B200%5D%0A%20%20%20%20%7D%5D%0A%20%20%7D%2C%0A%20%20options%3A%20%7B%0A%20%20%20%20scales%3A%20%7B%0A%20%20%20%20%20%20xAxes%3A%20%5B%7Bdisplay%3A%20false%7D%5D%2C%0A%20%20%20%20%20%20yAxes%3A%20%5B%7Bdisplay%3A%20false%7D%5D%0A%20%20%20%20%7D%2C%0A%20%20%20%20legend%3A%20%7Bdisplay%3A%20false%7D%0A%20%20%7D%0A%7D

image

from quickchart.

randallt avatar randallt commented on July 17, 2024

Does quickchart.io not support the 'indexable' attribute of some of these Chart.js options? We should be able to specify the colors in an array within the dataset, instead of separate datasets.

https://www.chartjs.org/docs/latest/general/options.html#indexable-options
https://www.chartjs.org/docs/latest/charts/bar.html#dataset-properties

When I tried this, it didn't work as expected:

{
type: 'bar',
data: {
datasets: [{
backgroundColor: ['green','yellow','orange','red'],
data: [50,100,150,200]
}]
},
options: {
scales: {
xAxes: [{display: false}],
yAxes: [{display: false}]
},
legend: {display: false}
}
}

https://quickchart.io/chart?c=%7Btype:'bar',data:%7Bdatasets:%5B%7BbackgroundColor:%5B'green','yellow','orange','red'%5D,data:%5B50,100,150,200%5D%7D%5D%7D,options:%7Bscales:%7BxAxes:%5B%7Bdisplay:false%7D%5D,yAxes:%5B%7Bdisplay:false%7D%5D%7D,legend:%7Bdisplay:false%7D%7D%7D

But maybe I got something wrong...

from quickchart.

randallt avatar randallt commented on July 17, 2024

Got it to work. You HAVE to put in empty labels for some reason:

https://quickchart.io/chart?c=%7Btype:%27bar%27,data:%7Blabels:[%27%27,%27%27,%27%27,%27%27],datasets:%5B%7BbackgroundColor:%5B%27green%27,%27yellow%27,%27orange%27,%27red%27%5D,data:%5B50,100,150,200%5D%7D%5D%7D,options:%7Bscales:%7BxAxes:%5B%7Bdisplay:false%7D%5D,yAxes:%5B%7Bdisplay:false%7D%5D%7D,legend:%7Bdisplay:false%7D%7D%7D

from quickchart.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.