Create Chart js chart with filters
I'm using chart.js to create charts.
I get my data from PHP array.
How to add filters to my chart?
Like showing only data between 2 dates or data from one person.
I would like to have this without reloading the page.
This is my code:
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script>
<script>
var mainChart_ctx = document.getElementById("main_chart").getContext("2d");
var mainChart_config = {
type: 'horizontalBar',
data: {
labels: [<?php
foreach($callerdata as $key => $value){
echo "'".$callerdata[$key]['name']." (".(count($callerdata[$key]['outbound']) + count($callerdata[$key]['inbound']) + count($callerdata[$key]['missed'])).")',";
} if(count($callerdata) == 0){echo " ";} ?>
],
datasets: [
{
label: 'Gemiddelde Rinkeltijd',
backgroundColor: '#007bff',
data: [<?php
foreach($callerdata as $key => $value){
echo "'".round($callerdata[$key]['waittime'] / $callerdata[$key]['totalcalls'])."',";
}?>],
borderColor: '#666',
borderWidth: 1
}
]
},
options: {
maintainAspectRatio: false,
tooltips: {
enabled: true,
callbacks: {
label: function(tooltipItem) {
return Number(tooltipItem.xLabel)+ " seconden";
}
}
},
legend: {
display: true
},
scales: {
xAxes: [{
ticks: {
min: 0
},
stacked: true,
scaleLabel: {
display: false,
labelString: 'Gemiddelde rinkeltijd',
fontSize: 14
}
}],
yAxes: [{
ticks: {
stepSize: 10
}
}]
}
}
};
</script>
Also I would like to have the possebility to change it to another type chart like bar chart or line chart.
javascript php chart.js
add a comment |
I'm using chart.js to create charts.
I get my data from PHP array.
How to add filters to my chart?
Like showing only data between 2 dates or data from one person.
I would like to have this without reloading the page.
This is my code:
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script>
<script>
var mainChart_ctx = document.getElementById("main_chart").getContext("2d");
var mainChart_config = {
type: 'horizontalBar',
data: {
labels: [<?php
foreach($callerdata as $key => $value){
echo "'".$callerdata[$key]['name']." (".(count($callerdata[$key]['outbound']) + count($callerdata[$key]['inbound']) + count($callerdata[$key]['missed'])).")',";
} if(count($callerdata) == 0){echo " ";} ?>
],
datasets: [
{
label: 'Gemiddelde Rinkeltijd',
backgroundColor: '#007bff',
data: [<?php
foreach($callerdata as $key => $value){
echo "'".round($callerdata[$key]['waittime'] / $callerdata[$key]['totalcalls'])."',";
}?>],
borderColor: '#666',
borderWidth: 1
}
]
},
options: {
maintainAspectRatio: false,
tooltips: {
enabled: true,
callbacks: {
label: function(tooltipItem) {
return Number(tooltipItem.xLabel)+ " seconden";
}
}
},
legend: {
display: true
},
scales: {
xAxes: [{
ticks: {
min: 0
},
stacked: true,
scaleLabel: {
display: false,
labelString: 'Gemiddelde rinkeltijd',
fontSize: 14
}
}],
yAxes: [{
ticks: {
stepSize: 10
}
}]
}
}
};
</script>
Also I would like to have the possebility to change it to another type chart like bar chart or line chart.
javascript php chart.js
2
You will need to create a menu for filters, send Ajax to refine the search whenever a filter is selected and return back the results by redrawing your chart. You need to make it so the JavaScript sets the data dynamically so it can interact with your changes. This reference might help you how to dynamically update your charts
– Diogo Santo
Nov 15 '18 at 16:57
add a comment |
I'm using chart.js to create charts.
I get my data from PHP array.
How to add filters to my chart?
Like showing only data between 2 dates or data from one person.
I would like to have this without reloading the page.
This is my code:
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script>
<script>
var mainChart_ctx = document.getElementById("main_chart").getContext("2d");
var mainChart_config = {
type: 'horizontalBar',
data: {
labels: [<?php
foreach($callerdata as $key => $value){
echo "'".$callerdata[$key]['name']." (".(count($callerdata[$key]['outbound']) + count($callerdata[$key]['inbound']) + count($callerdata[$key]['missed'])).")',";
} if(count($callerdata) == 0){echo " ";} ?>
],
datasets: [
{
label: 'Gemiddelde Rinkeltijd',
backgroundColor: '#007bff',
data: [<?php
foreach($callerdata as $key => $value){
echo "'".round($callerdata[$key]['waittime'] / $callerdata[$key]['totalcalls'])."',";
}?>],
borderColor: '#666',
borderWidth: 1
}
]
},
options: {
maintainAspectRatio: false,
tooltips: {
enabled: true,
callbacks: {
label: function(tooltipItem) {
return Number(tooltipItem.xLabel)+ " seconden";
}
}
},
legend: {
display: true
},
scales: {
xAxes: [{
ticks: {
min: 0
},
stacked: true,
scaleLabel: {
display: false,
labelString: 'Gemiddelde rinkeltijd',
fontSize: 14
}
}],
yAxes: [{
ticks: {
stepSize: 10
}
}]
}
}
};
</script>
Also I would like to have the possebility to change it to another type chart like bar chart or line chart.
javascript php chart.js
I'm using chart.js to create charts.
I get my data from PHP array.
How to add filters to my chart?
Like showing only data between 2 dates or data from one person.
I would like to have this without reloading the page.
This is my code:
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script>
<script>
var mainChart_ctx = document.getElementById("main_chart").getContext("2d");
var mainChart_config = {
type: 'horizontalBar',
data: {
labels: [<?php
foreach($callerdata as $key => $value){
echo "'".$callerdata[$key]['name']." (".(count($callerdata[$key]['outbound']) + count($callerdata[$key]['inbound']) + count($callerdata[$key]['missed'])).")',";
} if(count($callerdata) == 0){echo " ";} ?>
],
datasets: [
{
label: 'Gemiddelde Rinkeltijd',
backgroundColor: '#007bff',
data: [<?php
foreach($callerdata as $key => $value){
echo "'".round($callerdata[$key]['waittime'] / $callerdata[$key]['totalcalls'])."',";
}?>],
borderColor: '#666',
borderWidth: 1
}
]
},
options: {
maintainAspectRatio: false,
tooltips: {
enabled: true,
callbacks: {
label: function(tooltipItem) {
return Number(tooltipItem.xLabel)+ " seconden";
}
}
},
legend: {
display: true
},
scales: {
xAxes: [{
ticks: {
min: 0
},
stacked: true,
scaleLabel: {
display: false,
labelString: 'Gemiddelde rinkeltijd',
fontSize: 14
}
}],
yAxes: [{
ticks: {
stepSize: 10
}
}]
}
}
};
</script>
Also I would like to have the possebility to change it to another type chart like bar chart or line chart.
javascript php chart.js
javascript php chart.js
asked Nov 15 '18 at 14:45
user10651036
2
You will need to create a menu for filters, send Ajax to refine the search whenever a filter is selected and return back the results by redrawing your chart. You need to make it so the JavaScript sets the data dynamically so it can interact with your changes. This reference might help you how to dynamically update your charts
– Diogo Santo
Nov 15 '18 at 16:57
add a comment |
2
You will need to create a menu for filters, send Ajax to refine the search whenever a filter is selected and return back the results by redrawing your chart. You need to make it so the JavaScript sets the data dynamically so it can interact with your changes. This reference might help you how to dynamically update your charts
– Diogo Santo
Nov 15 '18 at 16:57
2
2
You will need to create a menu for filters, send Ajax to refine the search whenever a filter is selected and return back the results by redrawing your chart. You need to make it so the JavaScript sets the data dynamically so it can interact with your changes. This reference might help you how to dynamically update your charts
– Diogo Santo
Nov 15 '18 at 16:57
You will need to create a menu for filters, send Ajax to refine the search whenever a filter is selected and return back the results by redrawing your chart. You need to make it so the JavaScript sets the data dynamically so it can interact with your changes. This reference might help you how to dynamically update your charts
– Diogo Santo
Nov 15 '18 at 16:57
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53321970%2fcreate-chart-js-chart-with-filters%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53321970%2fcreate-chart-js-chart-with-filters%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
You will need to create a menu for filters, send Ajax to refine the search whenever a filter is selected and return back the results by redrawing your chart. You need to make it so the JavaScript sets the data dynamically so it can interact with your changes. This reference might help you how to dynamically update your charts
– Diogo Santo
Nov 15 '18 at 16:57