I'm trying to use Google PieChart (https://developers.google.com/chart/interactive/docs/gallery/piechart) with PHP (Laravel) and HTML Tag and also JavaScript whose code is as follows:
$(document).ready(function() {
if ($('#dashboard_date_filter').length == 1) {
dateRangeSettings.startDate = moment();
dateRangeSettings.endDate = moment();
$('#dashboard_date_filter').daterangepicker(dateRangeSettings, function(start, end) {
$('#dashboard_date_filter span').html(
start.format(moment_date_format) + ' ~ ' + end.format(moment_date_format)
);
update_statistics(start.format('YYYY-MM-DD'), end.format('YYYY-MM-DD'));
if ($('#quotation_table').length && $('#dashboard_location').length) {
quotation_datatable.ajax.reload();
}
});
update_statistics(moment().format('YYYY-MM-DD'), moment().format('YYYY-MM-DD'));
}
$('#dashboard_location').change( function(e) {
var start = $('#dashboard_date_filter')
.data('daterangepicker')
.startDate.format('YYYY-MM-DD');
var end = $('#dashboard_date_filter')
.data('daterangepicker')
.endDate.format('YYYY-MM-DD');
update_statistics(start, end);
});
});
function update_statistics(start, end) {
var location_id = '';
if ($('#dashboard_location').length > 0) {
location_id = $('#dashboard_location').val();
}
var data = { start: start, end: end, location_id: location_id };
//get purchase details
var loader = '<i class="fas fa-sync fa-spin fa-fw margin-bottom"></i>';
$('.total_purchase').html(loader);
$('.purchase_due').html(loader);
$('.total_sell').html(loader);
$('.invoice_due').html(loader);
$('.total_expense').html(loader);
$('.total_purchase_return').html(loader);
$('.total_sell_return').html(loader);
$('.net').html(loader);
$.ajax({
method: 'get',
url: '/home/get-totals',
dataType: 'json',
data: data,
success: function(data) {
//purchase details
$('.total_purchase').html(__currency_trans_from_en(data.total_purchase, true));
$('.purchase_due').html(__currency_trans_from_en(data.purchase_due, true));
//sell details
$('.total_sell').html(__currency_trans_from_en(data.total_sell, true));
$('.invoice_due').html(__currency_trans_from_en(data.invoice_due, true));
//expense details
$('.total_expense').html(__currency_trans_from_en(data.total_expense, true));
$('.total_purchase_return').html(__currency_trans_from_en(data.total_purchase_return, true));
$('.total_sell_return').html(__currency_trans_from_en(data.total_sell_return, true));
$('.net').html(__currency_trans_from_en(data.net, true));
},
});
}
And the default Google Pie Chart one is:
<html>
<head>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load("current", {packages:["corechart"]});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Task', 'Hours per Day'],
['Work', 11],
['Eat', 2],
['Commute', 2],
['Watch TV', 2],
['Sleep', 7]
]);
var options = {
title: 'My Daily Activities',
pieHole: 0.4,
};
var chart = new google.visualization.PieChart(document.getElementById('donutchart'));
chart.draw(data, options);
}
</script>
</head>
<body>
<div id="donutchart" style="width: 900px; height: 500px;"></div>
</body>
</html>
So how do I modify thearrayToDataTable
function or method of the Google Pie Chartdata
variable above by the response in HTML knowing that the AJAX of my JavaScript code above returns in theupdate_statistics
function ???
Should I do this:
function drawChart() {
var data = google.visualization.arrayToDataTable([
[{{ __('home.purchase_due') }}, <span class="info-box-number purchase_due"><i class="fas fa-sync fa-spin fa-fw margin-bottom"></i></span>],
[{{ __('lang_v1.expense') }}, <span class="info-box-number total_expense"><i class="fas fa-sync fa-spin fa-fw margin-bottom"></i></span>]
]);
???
Please help me to embed the data__('home.purchase_due') }}
and{{ __('lang_v1.expense') }}
with their HTML values (tag:span
) respectively in Pie Chart.
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
Laravel is a free open source PHP framework that came out in 2011. Since then, it has been able to become the framework of choice for web developers. One of the main reasons for this is that Laravel makes it easier, faster, and safer to develop complex web applications than any other framework.
https://laravel.com/
JavaScript is a multi-paradigm language that supports event-driven, functional, and mandatory (including object-oriented and prototype-based) programming types. Originally JavaScript was only used on the client side. JavaScript is now still used as a server-side programming language. To summarize, we can say that JavaScript is the language of the Internet.
https://www.javascript.com/
HTML (English "hyper text markup language" - hypertext markup language) is a special markup language that is used to create sites on the Internet.
Browsers understand html perfectly and can interpret it in an understandable way. In general, any page on the site is html-code, which the browser translates into a user-friendly form. By the way, the code of any page is available to everyone.
https://www.w3.org/html/
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.