I am using AngularJS v1.6.6 and angular-chart v.1.1.1 to display a chart in my application.
Here is the fiddle: https://jsfiddle.net/elenat82/w9gs3fqt/3/
And here is the code:
HTML:
<div class="container" ng-app="app" ng-controller="ChartCtrl">
<div class="row">
<div class="col-md-6">
<canvas
id="base"
class="chart-base"
chart-data="datas"
chart-labels="labelsdata"
chart-series="series"
chart-type="type"
chart-options="options">
</canvas>
</div>
</div>
JS:
angular.module("app", ["chart.js"])
.controller("ChartCtrl", function($scope) {
$scope.datas = [
[132],
[170],
[2.50],
[45.67],
[154],
[89],
[111],
[160],
[94]
];
$scope.labelsdata = ["today"];
$scope.series = ["label1", "label2", "label3", "label4", "label5", "label6", "label7", "label8", "label9"];
if ($scope.labelsdata.length > 1) {
$scope.type = 'line';
}
else {
$scope.type = 'bar';
}
$scope.options = {
scales: {
yAxes: [
{id: 'y-axis-1',
type: 'linear',
display: true,
position: 'left'},
{id: 'y-axis-2',
type: 'linear' ,
display: true,
position: 'right'}
]
}
}
});
What I would like to do is to display the same Y axe on both sides of the chart, with the same scale, now the left Y axe is ok but the right one shows weird values.... I want right Y axe to be exactly the same I have on the left side. If I understand correctly this http://www.chartjs.org/docs/latest/axes/cartesian/#axis-id you can use separate Y axes for differents datasets but this is not what I want.
Also I would like to have the labels always shown, not only when I hover the bars, now it's hard to figure out what every bar is related to .....
You can define custom ticks for both sides of y-axis
https://jsfiddle.net/w9gs3fqt/13/
var axis_ticks = {
beginAtZero: true,
max:200,
min: 0,
stepSize: 50
};
$scope.options = {
scales: {
yAxes: [
{id: 'y-axis-1',
type: 'linear',
display: true,
position: 'left',
ticks:axis_ticks
},
{id: 'y-axis-2',
type: 'linear' ,
display: true,
position: 'right',
ticks:axis_ticks
}
]
}
}
Related
I'm trying to move the labels out of the pie chart, but I can't move them in any way, is there any way i angular to move them out of the pie chart? (Angular v14)
I don't quite understand the documentation so it would be great if someone could help me understand how to do this.
Typescript code:
#ViewChild('chart') chart!: ChartComponent;
public chartOptions: Partial<ChartOptions>;
constructor() {
this.chartOptions = {
series: [45, 50, 22],
chart: {
type: 'pie',
width: '270px',
},
labels: ['Team A', 'Team B', 'Team C'],
responsive: [
{
breakpoint: 480,
options: {
chart: {
width: 100,
},
},
},
],
legend: {
show: true,
position: 'bottom',
horizontalAlign: 'center',
},
dataLabels: {
offSetY: 50,
// add this part to remove %
enabled: true,
},
};
}
HTML Code:
<div class="chartContainer" style="width: 30%;">
<apx-chart
[series]="chartOptions.series"
[chart]="chartOptions.chart"
[labels]="chartOptions.labels"
[responsive]="chartOptions.responsive"
[legend]="chartOptions.legend"
[dataLabels]="chartOptions.dataLabels">
</apx-chart>
</div>
I tried to put "offset", "offsetY", etc, inside the datalabel, but they didn't move an inch
You can tweak dataLabels and plotOptions.pie.dataLabels in your chartOptions. I give you a basic example (without Angular for practical reasons...):
let options = {
series: [45, 50, 22],
chart: {
type: 'pie',
height: 350
},
labels: ['Team A', 'Team B', 'Team C'],
dataLabels: {
style: {
colors: ['black']
}
},
plotOptions: {
pie: {
dataLabels: {
offset: 60
}
}
}
};
let chart = new ApexCharts(document.querySelector('#chart'), options);
chart.render();
<script src="https://cdn.jsdelivr.net/npm/apexcharts"></script>
<div id="chart"></div>
How do I get it to limit the amount of existing onject in array JSON using Chart.js?
Suppose I have 120 onbject in a single array, then I want to only display only 10 data in Chart.js. My data exist in the firebase, I tried to use limitToLast=10 , however, does not display any data, and this is my code.
<!DOCTYPE html>
<html lang="en">
<head>
<script src="JS/jquery-3.2.1.min.js"></script>
<style>
canvas{
-moz-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
}
</style>
</head>
<body>
<div class="container" style="width: 90%;">
<canvas id="canvas">
</canvas>
</div>
<script>
$.getJSON("https://skripsi-adeguntoro.firebaseio.com/sensor1.json", function (json) {
console.log(json);
var temp = json.map(function(item) {
return item.temp;
});
var time = json.map(function(item) {
return item.time;
});
var date = json.map(function(item) {
return item.date;
});
console.log(date);
console.log(time);
console.log(temp);
var config = {
type: 'bar',
data: {
labels: time,
datasets: [{
label: "My First dataset",
backgroundColor: "rgba(220,220,220,1)",
borderColor: "rgba(220,200,230,1)",
data: temp,
fill: false,
}]
},
options: {
responsive: true,
title:{
display:true,
text:'Chart.js Line Chart'
},
tooltips: {
mode: 'index',
intersect: false,
},
hover: {
mode: 'nearest',
intersect: true
},
scales: {
xAxes: [{
display: true,
scaleLabel: {
display: true,
labelString: 'Time'
}
}],
yAxes: [{
display: true,
scaleLabel: {
display: true,
labelString: 'Temperature'
},
ticks: {
beginAtZero: false,
stepSize: 5
}
}]
}
}
};
window.onload = function() {
var ctx = document.getElementById("canvas").getContext("2d");
window.myLine = new Chart(ctx, config);
};
});
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.4.0/Chart.min.js"></script>
</body>
</html>
Thank for your help.
Hi I'm trying to configure the graph to be without any tooltips or legends, and it look's like all the configured options are ignored. what I'm doing wrong?
it's the js object:
$scope.options = {
segmentShowStroke : false,
elements: { arc: { borderWidth: 0 } , point: {
radius: 0
}},
tooltips:{
enabled:false
},
legend: {
display: false
},
scales: {
yAxes: [
{
id: 'y-axis-1',
type: 'linear',
display: false,
position: 'left'
}
]
}
};
And it's the canvas element :
<canvas id="line" class="chart chart-line"
chart-data="data" chart-labels="labels" chart-options="options"
chart-dataset-override="datasetOverride"
chart-click="onClick" height="40px" width="1000px"
chart-colors="graph.colors" style=" width: 1000px; ;max-height: 40px !important;">
</canvas>
Try this solution
options : {
scales : {
xAxes : [ {
gridLines : {
display : false
}
} ]
}
}
I managed to make it work, only after changing the options from chartjsProvider.setOptions like this
ChartJsProvider.setOptions('line',{
segmentShowStroke : false,
elements: { arc: { borderWidth: 0 } , point: {
radius: 0
}},
tooltips:{
enabled:false
},
legend: {
display: false
},
scales: {
yAxes: [
{
display: false,
}
],
xAxes: [
{
display: false,
}
]
}
});
I want to put a legend, but I don´t know why it doesn´t appear. Also, I want to put the database in the fragments of my pie charts.
myapp.controller('myctrl', function ($scope) {
var data = [
['APP Android', 45.0],
['APP Ios', 26.8],
]
$scope.highchartsNG = {
options: {
chart: { type: 'pie'}
},
legend: {
enabled: true
},
series: [ {
name: 'Avisos',
innerSize: '50%'
},
{
name: 'Plataforma',
size: '80%',
innerSize: '65%',
showInLegend: false,
data: data
}],
loading: false
}
});
This example is public in http://jsfiddle.net/Cp73s/2038/
Check this out
var myapp = angular.module('myapp', ["highcharts-ng"]);
myapp.controller('myctrl', function($scope) {
var data = [
['APP Android', 45.0],
['APP Ios', 26.8],
['Widget Web', 12.8],
['MTC BAckoffice', 8.5],
['Correo electrónico', 6.2],
['Facebook', 6.2],
['Twitter', 6.2],
['Teléfono', 6.2],
['Presencial', 6.2],
]
$scope.highchartsNG = {
options: {
chart: {
type: 'pie'
},
plotOptions: {
pie: {
dataLabels: {
distance: -25 //adjust this value to change label distance
}
}
},
},
title: {
text: '550<br>AVISOS',
align: 'center',
verticalAlign: 'middle'
},
legend: {
enabled: true
},
series: [{
name: 'Avisos',
innerSize: '50%'
}, {
name: 'Plataforma',
size: '80%',
innerSize: '65%',
showInLegend: true,
data: data
}],
loading: false
}
});
Fiddles
fiddle with updated label
Fiddle with updated legend display
I am trying to render charts using the Highcharts js-library. As I am working with AngularJS, I am using an AngularJS directive for HighCharts.
I made everything work fine but due to some weird reason, I am unable to change the yAxis label value.
I get the default value "Values" shown on the chart's y-axis, which I checked is defined in the highcharts.js file under "defaultYAxisOptions".
Html:
<div ng-app="myapp">
<div ng-controller="myctrl">
<highchart id="chart1" config="chart"></highchart>
</div>
</div>
Javascript:
var myapp = angular.module('myapp', ["highcharts-ng"]);
myapp.controller('myctrl', function ($scope) {
$scope.chart = {
options: {
chart: {
type: 'bar'
}
},
xAxis: {
title: {
text: 'x-axix-label'
}
},
yAxis: {
title: {
text: 'y-axix-label'
}
},
series: [{
data: [10, 15, 12, 8, 7]
}],
title: {
text: 'Hello'
},
loading: false
}
});
Sample implementation: http://jsfiddle.net/VwTCn/9/
Can someone please point out the mistake here.
Took me a while, to understand, that highcharts-ng doesn't work, using the original highcharts options structure.
Anyway, for some reason it works, if you put you yAxis config into the options object, like this:
...
options: {
chart: {
type: 'bar'
},
yAxis: {
title: {
text: 'y-axis label'
}
}
},
xAxis: {
title: {
text: 'x-axis label'
}
},
series: [{
...
See example: http://jsfiddle.net/martinczerwi/VwTCn/13/