Mpdf on Codeigniter can't generate morris line chart - codeigniter

I'm using Mpdf with codeigniter for generating pdf file.
Everything work perfectly except this Morris Line Chart. Mpdf can't generate this line chart , it's shows blank space.
My Controller Look like this.
// load library
$this->load->library('pdf');
$pdf = $this->pdf->load();
$html = $this->load->view('pdf_view', true);
// render the view into HTML
$pdf->WriteHTML(utf8_encode($html));
// write the HTML into the PDF
$output_pdf = '/weekly_report_' . date('Y_m_d') . '.pdf';
$pdf->Output("$output_pdf", 'I');
In View file look like this , I test this view file , it's working correctly but on mpdf not working
<script>
$(function () {
"use strict";
// LINE CHART
var line = new Morris.Line({
element: 'line-chart',
resize: true,
data: [
{"daykey": "9 Jul 2014", "milk_value": 3.00},
{"daykey": "10 Jul 2014", "milk_value": 5.20},
{"daykey": "11 Jul 2014", "milk_value": 2.40},
{"daykey": "12 Jul 2014", "milk_value": 8.00},
{"daykey": "13 Jul 2014", "milk_value": 5.50},
{"daykey": "14 Jul 2014", "milk_value": 9.00},
{"daykey": "15 Jul 2014", "milk_value": 9.50},
],
xkey: 'daykey',
xLabels:'day',
xLabelMargin: 10,
xLabelAngle: 90,
ykeys: ['milk_value'],
labels: ['Milk Production'],
parseTime: false,
lineColors: ['#3c8dbc'],
hideHover: 'auto',
pointSize: '0',
lineWidth: '3',
resize: true
});
});
</script>
I tried also anychart, this one getting same result. How do i embed line chart with mpdf?

mPDF cannot directly plot a SVG generated with Javascript.
You would have to generate the chart SVG source to a string and paste the string to the HTML (or link it as an image). Or try some library that generates static bitmap images.

Related

how can I fetch exifdata(like gps) with filepond?

I am trying to use filepond for my assignment, but I can't get exifdata from photos.
for example, as I expected
File {name: "KakaoTalk_20210727_153219119.jpg", lastModified: 1627367574529, lastModifiedDate: Tue Jul 27 2021 15:32:54 GMT+0900 (Korean Standard Time), webkitRelativePath: "", size: 2319798, …}
exifdata: {ImageWidth: 4000, ImageHeight: 2252, Make: "samsung", Model: "SM-G988N", Orientation: 1, …}
iptcdata: {}
lastModified: 1627367574529
lastModifiedDate: Tue Jul 27 2021 15:32:54 GMT+0900 (Korean Standard Time) {}
name: "KakaoTalk_20210727_153219119.jpg"
size: 2319798
type: "image/jpeg"
webkitRelativePath: ""
I wanted to get exifdata like this with my filepond code like this but I can't find it :(
file: File
lastModified: 1627367574529
lastModifiedDate: Tue Jul 27 2021 15:32:54 GMT+0900 (Korean Standard Time) {}
name: "KakaoTalk_20210727_153219119.jpg"
size: 2319798
type: "image/jpeg"
webkitRelativePath: ""
_relativePath: ""
I really need gps data for my assginment, how could I get it?
this is Vue-filepond code.
<template>
<div id="test">
<br>
<br>
<br>
<br>
<br>
<file-pond
name="test"
ref="pond"
allowImageExifOrientation = "true"
label-idle="Drop files here..."
allowprocess="false"
v-bind:allow-multiple="true"
accepted-file-types="image/jpeg, image/png"
:server="myServer"
instantUpload ="false"
v-bind:files="myFiles"
v-on:init="handleFilePondInit"
imageTransformOutputStripImageHead = "false"
allowImagePreview="true"
imagePreviewHeight="300px"
#initfile="oninitfile()"
#updatefiles="FilePondUpdateFiles"
/>
<br>
<p style="text-align:center">hi</p>
<div v-for="imageFile in imageFiles" :key="imageFile.name" style="text-align:center;">
<img :src="imageFile.src" alt="" style="width: 200px">
</div>
</div>
</template>
methods: {
handleFilePondInit: function () {
console.log("FilePond has initialized");
// FilePond instance methods are available on `this.$refs.pond`
this.$refs.pond.getFiles();
console.log(this.$refs.pond.getFiles())
},
// 파일 staging시
oninitfile() {
console.log("onInit!")
},
FilePondUpdateFiles(files) {
console.log("기본적인 이미지 검색 방식", this.$refs['pond'].file)
console.log(files)
console.log("onAdd!")
this.imageFiles = files
console.log("총 사진 데이터", this.imageFiles)
}
},
thank you for reading and help, have a nice day !
FilePond doesn't read EXIF data it only corrects the orientation header parameter so images can be oriented correctly on older browsers.
You could use Exif-JS combined with FilePond to read EXIF data.
https://github.com/exif-js/exif-js
Use the beforeAddFile hook to read the EXIF data and add it to the file item.
This is a plain JavaScript example which should be straight forward to port to Vue.
FilePond.create({
beforeAddFile: (fileItem) => new Promise(resolve => {
const success = EXIF.getData(fileItem.file, () => {
fileItem.setMetadata('exifdata', EXIF.getAllTags())
// Added EXIF data to file item, we're done
resolve(true);
})
// Can't read EXIF data, don't add file
if (!success) resolve(false);
})
})

Change format date using javascript from timestamp php [duplicate]

This question already has answers here:
How to get current formatted date dd/mm/yyyy in Javascript and append it to an input [duplicate]
(7 answers)
Closed 4 years ago.
can javascript change the date format taken from php like this: 2018-09-22 05:20:48 to like this Saturday,22 September ? iam using vue.js and laravel. because this date is taken from the database using a query i dont know how to get int time and it will be passing to vue component.
Vue Component :
<tr v-for="(category,index) in allCategories">
<td class="v-align-middle"> <img :src="category.images[0].link" class="img-fluid categoriesImg" alt=""> </td>
<td class="v-align-middle">{{category.category}}</td>
<td class="v-align-middle">{{formatDate(category.created_at)}}</td>
</tr>
<script>
import {mapGetters} from 'vuex';
export default {
name:"category",
computed: {
...mapGetters({
allCategories:'allCategories'
}),
},
created(){
// this.$swal('Hello Vue world!!!');
this.$store.dispatch('GetAllCategories');
},
methods:{
formatDate(date){
let tanggal = new Date(date);
return tanggal;
},
}
}
</script>
Result
"2018-09-21T22:20:48.000Z"
momentjs is the best soltion.
Make sure you set the right format (https://momentjs.com/docs/#/parsing/string-format/)
formatDate(date){
let tanggal = moment(date, 'YYYY-MM-DD HH:mm:ss').format('dddd,DD MMMM');
return tanggal;
},
You can use below code :
var monthNames = ["January", "February", "March", "April", "May", "June","July", "August", "September", "October", "November", "December"];
var dayNames=['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
d = new Date(date);
time = dayNames[d.getDay()] + ", " + d.getDate() + monthNames[d.getMonth()] ;
For more information you can checkout the Date in javaScript

Use local months on dc.js barchart

I'm simply trying to use local months on the x-axis of a bar chart.
First I would like to only represent months on x-axis and second I would like to have the months defined in localeFrance.
I have forked a fiddle but I can't make it work :https://jsfiddle.net/xjp2o0wt/6/
so here is my code.
Thanks for your valuable help
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Dashboard</title>
<link rel="stylesheet" href="dc.css">
</head>
<body>
<div id=chart>
here
</div>
<script src="crossfilter.js"></script>
<script src="d3.js"></script>
<script src="dc.js"></script>
<script>
var localeFrance = d3.locale ({
"decimal": "",
"thousands": "",
"grouping": [3],
"currency": ["€ ", ""],
"dateTime": "%a %b %e %X %Y",
"date": "%d/%m/%Y",
"time": "%H:%M:%S",
"periods": ["AM", "PM"],
"days": ["Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi", "Dimanche"],
"shortDays": ["lun", "mar", "mer", "jeu", "ven", "sa", "dim"],
"months": ["Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembrr", "Octobre", "Novembre", "Decembre"],
"shortMonths": ["Jan", "Fev", "Mar", "Avr", "Mai", "Juin", "Juil", "Aou", "Sep", "Oct", "Nov", "Dec"]
});
var dateFormat_in = d3.time.format.utc("%Y-%m-%d");
data=[{year:2017, month:1, value:12},{year:2017, month:2, value:15},{year:2017, month:3, value:12},
{year:2017, month:4, value:16},{year:2017, month:5, value:14}]
data.forEach(function(d) {
d["date"] = dateFormat_in.parse(d["year"]+"-"+d["month"]+"-01");
d["value"] = +d["value"];
});
ndx = crossfilter(data);
timeChart = dc.barChart("#chart");
monthDim = ndx.dimension(d => d3.time.month.utc(d["date"]));
monthGroup = monthDim.group().reduceSum(d=>d.value);
minDate = monthDim.bottom(1)[0]["date"];
maxDate = monthDim.top(1)[0]["date"];
timeChart
.width(480)
.height(320)
.margins({top: 5, right: 30, bottom: 20, left: 50})
.dimension(monthDim)
.group(monthGroup)
.x(d3.time.scale().domain([minDate, maxDate]))
.xUnits(d3.time.months)
//.xUnits(localeFrance.timeFormat("%b"))
.elasticY(true)
.centerBar(true).xAxisPadding(15).xAxisPaddingUnit('month')
.gap(16)
.yAxis().ticks(1);
dc.renderAll();
</script>
I may be mistaken, but d3 doesn't seem to build international locales into the bundle. I'm new to this stuff myself, so I relied on a few other answers on SO which provide a lot more detail:
Localization of d3.js (d3.locale example of usage)
Where can in find the locale objects for d3.js for different countries
How to make localization on months / days for D3js?
We can define the fr_FR locale like so:
var fr_FR = {
"dateTime": "%A, le %e %B %Y, %X",
"date": "%d/%m/%Y",
"time": "%H:%M:%S",
"periods": ["AM", "PM"],
"days": ["dimanche", "lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi"],
"shortDays": ["dim.", "lun.", "mar.", "mer.", "jeu.", "ven.", "sam."],
"months": ["janvier", "février", "mars", "avril", "mai", "juin", "juillet", "août", "septembre", "octobre", "novembre", "décembre"],
"shortMonths": ["janv.", "févr.", "mars", "avr.", "mai", "juin", "juil.", "août", "sept.", "oct.", "nov.", "déc."]
};
var frLocale = d3.locale(fr_FR);
Source: https://github.com/d3/d3-time-format/blob/master/locale/fr-FR.json
Now we need to tell the x axis to use the custom locale:
timeChart.xAxis()
.tickFormat(frLocale.timeFormat('%B'))
.ticks(d3.time.months);
We're also telling it to put ticks on the months; otherwise the d3 axis will try to draw a lot more.
Similarly we have to set xUnits to draw one bar per month (I see you have this in your question, but it was different in your fiddle):
timeChart
.xUnits(d3.time.months)
Unfortunately dc.js takes its x domain very literally, so if you're using .centerBar(true) you also need to offset your min and max date:
minDate = new Date(monthDim.bottom(1)[0]["date"]);
minDate.setDate(15)
maxDate = new Date(monthDim.top(1)[0]["date"]);
maxDate.setDate(15)
Et voilà, you might say. :)
Fork of your fiddle.

“Exporting” a Tributary example that makes use of the tributary object - d3.js

I am implementing the chart in d3.js, how can I "extract" a tributary example that is using the tributary object into HTML and Javascript code. Below is the code what i'm trying to do, but don't get success yet.
I have external JSON file sample.json which i need to use for chart data. Error shows that forEach is not a function. I am stuck what to do.
Please find my jsFiddle for whole code.
// loading sample.json
d3.json("sample.json", function(sample2) {
//var svg = d3.select("body").append("svg");
// date manipulation to format UTC to js Date obj
sample2.forEach(function(d) { d.time = new Date(d.time * 1000); });
// helpers and constants
var margin = {"top": 50, "right": 100, "bottom": 56, "left": 50};
var width = 930 - margin.right - margin.left;
var height = 582 - margin.top - margin.bottom;
var timeFormat = d3.time.format("%c");
var X = width/sample2.length*0.25;
<!DOCTYPE html>
<html>
<head>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="inlet.js"></script>
<link src="style.css" />
</head>
<body>
</body>
</html>
Please let me know what I'm doing wrong with my code. Here is my fiddle http://jsfiddle.net/wLrdgt89/1/
You need to fix these:
Problem:1
{"sample2": [ {"time": 1387212120, "open": 368, "close": 275, "high": 380, "low": 231}, {"time": 1387212130, "open": 330, "close": 350, "high": 389, "low": 310}, {"time": 1387212570, "open": 395, "close": 253, "high": 438, "low": 213} ]}
Your json is an object and not an Array so forEach will not work.
You need to do something like this:
d3.json("sample.json", function(sample2) {
sample2= sample2.sample2
Problem2
Your html body has no svg so you need to append it:
var canvas = d3.select("svg")//this is wrong
var canvas = d3.select("body").append("svg")//add svg to the body
Working code here
Hope this helps!

Flot not showing x-axis label

I graph data as follows but I can't seem to get the axis labels to show:
!function ($) {
var options = {
xaxis: {
mode: "time",
min: start_time,
// max: (new Date()).getTime(),
tickSize: [4, "hour"],
tickLength: 0,
axisLabel: 'Day',
axisLabelUseCanvas: true,
axisLabelFontSizePixels: 12,
axisLabelFontFamily: 'Verdana, Arial, Helvetica, Tahoma, sans-serif',
axisLabelPadding: 3
},
yaxis: {
axisLabel: 'Amount',
axisLabelUseCanvas: true,
axisLabelFontSizePixels: 12,
axisLabelFontFamily: 'Verdana, Arial, Helvetica, Tahoma, sans-serif',
axisLabelPadding: 5
},
}
$.plot($("#placeholder"), [open_emails],options);
}(window.jQuery
I have included the following in my views and they are being loaded
//= require jquery.flot
//= require jquery.flot.symbol.min
//= require jquery.flot.axislabels
The result is as follows:
How can I get the labels to show?
Hiya working demo http://jsfiddle.net/wuALT/
So all you need is to add this:
<script type='text/javascript' src="https://raw.github.com/xuanluo/flot-axislabels/master/jquery.flot.axislabels.js"></script>
and rest code will start identifying the axisLabel.
Read: http://codenachos.com/view/axis-labels-in-flot was a known issue http://code.google.com/p/flot/issues/detail?id=42
This will help and see Day and Amount appearing in the X and Y axis now.

Resources