score:7
Accepted answer
I hope this answer would be helpful for those who have the same problem with gradient as me!
So what worked for me is to create an event listner on chart and call my function changeColor when the event chart is emitted.
Here is the code in my controller:
var changeColor = function(chart){
var ctx = chart.chart.ctx;
var gradient = ctx.createLinearGradient(0, 0, 0, 400);
gradient.addColorStop(0, 'rgba(243, 103, 101,0.5)');
gradient.addColorStop(1, 'rgba(0, 89, 179,0.5)');
chart.chart.config.data.datasets[0].backgroundColor = gradient;};
$scope.$on('chart-create', function (evt, chart) {
if(chart.chart.canvas.id === 'base2') {
changeColor(chart);
chart.update();
}
HTML code
<canvas id="base2" class="chart-base" chart-type="type2" chart-data="data2" chart-labels="labels2" chart-colors="colors2" chart-options="options2" >
</canvas>
Source: stackoverflow.com
Related Query
- Extending Existing Chart Types angular chart js using chart js 2.0
- using gradient colors in angular-chart.js
- Create multiple dynamic stacked chart using chart.js in Angular 10?
- Show labels on each sector to polar chart using angular js chart
- How to show percentage (%) using chartjs-plugin-labels ( Pie chart ) in angular 2/8
- Configure Pie Chart Colors Using Chart.js and PHP
- Using two JSON objects to make Chart.JS Bar Chart Dynamic in Typescript / Angular
- Chart JS - Grid colors and gradient fill not showing
- How to send data to chart js using angular
- how to increase space between legend and chart in chartjs (ng2charts ) using angular
- Using Different Colors In a Chart
- Chart.js chart doesn't render when using Angular 2
- Chart.js in Angular 10: Specified colors not shown in multi-series bar chart (instead random colors)
- How to make the background color of the chart as gradient using Chart.js
- How to display the values inside the pie chart of PrimeNG (chart) using JavaScript or Angular
- Bar Chart in Angular JS Using Chartjs
- How to show symbols after the label and before the numeric value using chart.js Bar chart in Angular
- How to assign specific colors to data items in a doughnut chart in Angular Chart?
- I am using chart js to draw a chart. I did everything right but i don't know why the x axis and y axis label is not comming in chart. code below
- Angular using PrimeNG charjs problem with font colors
- Building Multiple Charts Using Chart JS in an Angular Application
- How Can I Get An Instance of a ChartJS Bar Chart Using Angular
- How to display Json object in chart js consisting of lists created using Django rest framework in angular application
- How to take data from an API and create a chart on that using Chart.js and Angular 8?
- how to create line chart using chart.js in angular 2+
- Pie chart not working using angular and ng2-charts
- How to run Chart.js samples using source code
- Angular 4: Different color for bar in bar chart dynamically using ChartJS
- Custom dataset object not setting chart.js bar chart colors in Angular 6
- How to add text inside the doughnut chart using Chart.js?
More Query from same tag
- Chart load time and animation slow on mobile device
- ChartJS keeps adding one day to X axis. I cannot find a reason. Any suggestion?
- Bollinger bands in React application with a library
- Chart.JS - Polar area - Legend hover style and margin
- chart.js with null data point in dataset
- is there anything wrong with this If Condition in Javascript code?
- Chartjs: How can I group datasets closer if I have maxBarThickness set?
- Convert FirestoreCollection into an array?
- Chartjs backgroundColor for line chart does not appear in Vue app
- How to update data Chart in async way in Angular Chart.js?
- Dashed line for missing data in Chart.JS (spanGaps style)
- Charts.js tooltip overlapping text on chart
- Catch event of show and hide dataset at chart.js
- chartjs time cartesian axis adapter and date library setup
- $scope.chart undefined in angular-chart
- Number value format with comma and two decimal points
- Chart.js add border around line chart, and yAxis unit title ([s])
- How to draw a range label on x axis using chartJS
- Using public data for dynamic data
- How to set min max for x axis depend on data with Chartjs and Spring Boot?
- Angular protractor tests timeout on pages containing Chart.js
- How to update only new data in Chart.JS?
- How to display data by current month and display no data message if data not exists
- Vue3 does not show line-chart
- How do I use ChartJS with a background color in the space between two line charts?
- chartjs x-axis category label (with data from tabletop.js)
- ChartJS options with Chartkick
- Render pie chart datasets out of 100% -- Chart.JS
- How to add a chart with a table in Chart.js?
- How can I display both values as labels when hovering over chart.js