score:171

Accepted answer

guh i solved it, sorry about the question. but i guess i'll leave an answer in case anyone else runs into my problem.

var ctx = document.getelementbyid("barchart");
    var mychart = new chart(ctx, {
        type: "bar",
        data: {
            labels: ["label 1", "label 2"], 
            datasets: [{
                label: "my label",
                backgroundcolor: "rgba(159,170,174,0.8)",
                borderwidth: 1,
                hoverbackgroundcolor: "rgba(232,105,90,0.8)",
                hoverbordercolor: "orange",
                scalestepwidth: 1,
                  data: [4, 5]
            }]
        },
        options: { 
            legend: {
                labels: {
                    fontcolor: "blue",
                    fontsize: 18
                }
            },
            scales: {
                yaxes: [{
                    ticks: {
                        fontcolor: "green",
                        fontsize: 18,
                        stepsize: 1,
                        beginatzero: true
                    }
                }],
                xaxes: [{
                    ticks: {
                        fontcolor: "purple",
                        fontsize: 14,
                        stepsize: 1,
                        beginatzero: true
                    }
                }]
            }
        }
    });
   <!-- edit:
   chart.js recently released new version v3.x
   which is not backwards compatible with v2.x
   -->

<!--<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>-->

   <!-- above link gets you latest version of chart.js (at v3.3.2 now)
        hence snippet didn't work propperly anymore :-(
   -->

<script src="https://cdn.jsdelivr.net/npm/chart.js@2.9.4"></script>

   <!-- above link gets you v2.9.4
        and snippet works agian  :-)
   -->

<div>
    <canvas id="barchart" height="140"></canvas>
</div>

score:1

inside the dataset, assign a color to the attribute bordercolor.

data: {
    labels: [1, 2, 3, 4, 5],
    datasets: [
        {
            data: temp,
            label: "temperature",
            backgroundcolor: "rgba(219, 0, 0, 1)",
            bordercolor: "rgba(219, 0, 0, 1)",
            fill: false
        },
        {
            data:rh,
            label: "humidity",
            fill: false
        },
        {
            data:lux,
            label: "luminosity",
            fill:false
        }
    ]
}

i've been working with a line graph and backgroundcolor sets the color of the specific points on the line graph, and then bordercolor sets the color of the line itself as well as the legend label associated with that dataset.

score:30

good question and good answer from @phantomsalt

his answer works perfectly well with ....... chart.js v2.xx
i modified his good code to work with .. chart.js v3.xx

(v3.xx is not backwards compatible with v2.xx)

// var ctx = document.getelementbyid("barchart")
const ctx = document.getelementbyid("barchart").getcontext("2d"); // added '.getcontext("2d")'

const mychart = new chart(ctx, {
  type: "bar",
  data: {
    labels: ["label 1", "label 2"],
    datasets: [{
      label: "my label",
      backgroundcolor: "rgba(159,170,174,0.8)",
      borderwidth: 1,
      hoverbackgroundcolor: "rgba(232,105,90,0.8)",
      hoverbordercolor: "orange",
      scalestepwidth: 1,
      data: [4, 5]
    }]
  },
  options: {
    plugins: {  // 'legend' now within object 'plugins {}'
      legend: {
        labels: {
          color: "blue",  // not 'fontcolor:' anymore
          // fontsize: 18  // not 'fontsize:' anymore
          font: {
            size: 18 // 'size' now within object 'font {}'
          }
        }
      }
    },
    scales: {
      y: {  // not 'yaxes: [{' anymore (not an array anymore)
        ticks: {
          color: "green", // not 'fontcolor:' anymore
          // fontsize: 18,
          font: {
            size: 18, // 'size' now within object 'font {}'
          },
          stepsize: 1,
          beginatzero: true
        }
      },
      x: {  // not 'xaxes: [{' anymore (not an array anymore)
        ticks: {
          color: "purple",  // not 'fontcolor:' anymore
          //fontsize: 14,
          font: {
            size: 14 // 'size' now within object 'font {}'
          },
          stepsize: 1,
          beginatzero: true
        }
      }
    }
  }
});
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
  <!-- gets you the latest version of chart.js, now at v3.3.2 -->

<div>
  <canvas id="barchart" height="140"></canvas>
</div>


Related Query

More Query from same tag