score:0
please try this:
import { component, oninit } from '@angular/core';
import {router, activatedroute,params} from '@angular/router';
import {chart} from 'chart.js'
import {weatherservice} from '../../services/weather.service';
import {weather} from '../../models/weather';
@component({
selector: 'app-viewcities',
templateurl: './chart.component.html',
styleurls: ['./chart.component.css'],
providers:[]
})
export class chartcomponent implements oninit {
chart = [];
public title: string;
public weathers: weather[];
public weatherscity: weather[];
public identity;
public token;
public url: string;
public page;
public prev_page;
public next_page;
public citypassed;
public temperature=[];
public dates=[];
labels: any = [];
data: any = [];
constructor(
private _route:activatedroute,
private _router:router,
private _weatherservice:weatherservice) { }
ngoninit() {
//this.showcityweather();
this.alertmessage();
}
alertmessage(){
alert("by now the chart is not rendered until the console it´s open or you change the zoom(ctrl)+scroll down/up")
}
showcityweather(){
var localstorageretrieve=localstorage.getitem("citytoview");
var city=localstorageretrieve;
this._weatherservice.showwheatherbycity(city).subscribe(
response=>{if(!response){
this._router.navigate(['/']);
}else{
this.weatherscity = response;
console.log(this.weatherscity)
//loop the object and add the data to the chart's array
for(let i=0;i<this.weatherscity.length;i++){
this.temperature.push(this.weatherscity[i].temperature)
this.dates.push(this.weatherscity[i].date) }
}},
error => {
let errormessage = <any>error;
if (errormessage !== null) {
let body = json.parse(error._body);
console.log(body);
}
}
)
}
showchart = false;
ngafterviewinit() {
this.showcityweather();
this.chart=new chart('canvas',{
type:'bar',
data:{
labels:this.dates,
datasets:[{
label: 'temp. in cº',
data:this.temperature,
backgroundcolor: [
],
bordercolor: [
],
borderwidth: 5
}]
},
options: {
scales: {
yaxes: [{
ticks: {
beginatzero:false
}
}]
}
}
})
settimeout(() => {
this.showchart = true;
},100)
}
}
<div class="chart" *ngif="showchart">
<canvas #canvas id="canvas">{{ chart }}</canvas>
</div>
Source: stackoverflow.com
Related Query
- Charts.js does not render chart until I open the console
- Chart.js chart not displaying until I open the browser's console
- React-chart does not render the legend for PIE chart
- Chart.js returns a console error and does not display the chart when using variables as data input
- Chart looks only grey, does not show the color - Chartjs,discordjs
- Chart.js Chart in Angular does not load until resizing browser window
- Bar Chart of ChartJS does not Render
- Chartjs does not render chart when set responsive option to true
- When I added a funnel chart to chartjs all the charts are load compressed until resize page
- ChartJs Memory Leak | Garbage Collection does not clean Chart Object or Arrays after render
- Angular-Charts bar chart does not update when I change the data, series, labels
- Why ChartJS's Bar Chart does not render bar for a specific value?
- Bar chart (chart.js) with only 2 points does not show one of the bars
- ChartJs does not render chart when binding canvas id in Angular
- ChartJs (ver: 2.8.0): Custom tooltip does not hide if clicked (or mouse pointer is moved) outside the chart canvas area
- Chart.js line chart does not render data lines on iOS
- React js with react-chart js, does not render doughnut chart
- chart does not change the values when the variable changes the value
- Adding new data to empty Chart.js chart does not render new data correctly
- 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
- The real time chart sometimes does not display when I switch the target
- Edge browser does not render chart using chart js
- Chart.js - Line chart does not render all points when using Point[] format
- The data that is called in chart does not match the database
- how to not repeat code while creating multiple charts in chart js
- Html chart does not fit a small Android WebView
- Wkhtmltopdf does not render Chart.JS 2.5.0 graph
- Angular-chart.js - Make line chart does not curve
- Vue Chart.js component does not render
- Chart.js update function (chart,labels,data) will not update the chart
More Query from same tag
- Why I don't see the second plot?
- Can I add a callback function to the legend while keeping the original functionality?
- Invalid Date moment.js using Iso yyyy-MM-dd HH:mm:ss
- drawing bar chart with chart.js jQuery
- Angular-Charts - Pie Chart,show labels inside each slice of data
- Display Date Label in axes - chart js/ng2 charts
- how to make doughnut chart portions, buttons
- Change data onclick with ChartJS
- How do I make the y-axis intersect the x-axis at 0 in chart.js
- null values for instead of date causes the browser to crash while using chart js
- Chart.js - Timeline
- Chartjs blocks jumping to a section in ASP.NET MVC 5
- How to create a line on a chart using chartjs-plugin-annotation
- jQuery convert hex to rgba
- ChartJS hover/tooltips: selecting the correct points in the datasets based on x-value
- Datas put one on each other on chart.js
- ChartJs - Round borders on a doughnut chart with multiple datasets
- Laravel passing orders to Chart.js
- Chart Data Not Updating for Both Graphs?
- How to retain spacing between bars for two different bar charts in Chart.js 2
- I want to use an object to help create a chart with Chartjs
- Alter angular js chart wrapper to support drawing custom lines
- Updating chartJS with dynamic data
- ChartJS show value in legend (Chart.js V3.5)
- Hide x-axis when it has no value on chart.js
- Multi colored line chart angular and primeng
- Unable to change default values in chart.js
- cant resize range of Y axis of chart in HTML/PHP
- how to display datetime list in graph using chart.js
- How to display labels outside the pie chart border?