Chart.js + Intel XDK - android

I'm triyng to add a chart to my Android app using Chart.js
At Intel-XDK emulator this works perfectly, but if I try run it using App Preview or if I build the apk I can't see the chart.
function Skills(){
document.getElementById("MinhasHabilidades").style.display = 'block';
document.getElementById("inicio").style.display = 'none';
var ChartData = {
labels: ["Ler", "Ouvir", "Escrever", "Falar"],
datasets: [{
fillColor: "rgba(0,128,255,0.5)",
strokeColor: "rgba(220,220,220,0.8)",
highlightFill: "rgba(220,220,220,0.75)",
highlightStroke: "rgba(220,220,220,1)",
data: [9, 13, 4, 12]
}]
};
var ctx = document.getElementById("myChart").getContext("2d");
window.myBar = new Chart(ctx).Radar(ChartData, {responsive: true});
}
When I call the "new Chart(ctx)..." the function stop.

Related

how to Extend highchart plot band outside graph using android wrapper

I have a requirement to extend my plot band outside the graph and give a shape. Need to achieve the portion marked in the attached screenshot. using highchart android wrapper. While searching for the solution, I found the jsfiddle I would like to do the same thing using the android wrapper; I am using highchart library of version 6.1.4
targetimage
Link : https://jsfiddle.net/BlackLabel/e52smy16/
<script src="https://code.highcharts.com/highcharts.js"></script>
<div id="container"></div>
const renderCustomPlotBand = function(chart) {
let ren = chart.renderer,
customOptions = chart.yAxis[0].options.customPlotBand,
from = customOptions.from,
to = customOptions.to,
xEnd = chart.plotLeft + chart.plotSizeX,
xBeginig = chart.plotLeft - 40,
point1 = [xEnd, chart.yAxis[0].toPixels(from)],
point2 = [xBeginig, chart.yAxis[0].toPixels(from)],
point3 = [xBeginig, chart.yAxis[0].toPixels(to)],
point4 = [xEnd, chart.yAxis[0].toPixels(to)],
textWidth = chart;
if (customOptions.enabled) {
chart.customPlotBand = ren.g('customPlotBand').add().toFront()
chart.customText = ren.g('customText').add().toFront();
ren.path(['M', point1[0], point1[2], 'L', point2[0], point2[2], point3[0], point3[2], point4[0], point4[2]])
.attr({
'stroke-width': 1,
stroke: 'red'
}).add(chart.customPlotBand);
ren.label(customOptions.text, point2[0] - 10, point2[2] - 17).attr({
padding: 5,
fill: 'white',
rotation: -90
}).add(chart.customText);
chart.customText.translate(0, -(point2[2] - point3[2]) / 2 + chart.customText.element.getBBox().height - 3)
}
}
Highcharts.chart('container', {
chart: {
marginLeft: 80,
events: {
render() {
renderCustomPlotBand(this)
}
}
},
yAxis: [{
//Declere your custom plotband
customPlotBand: {
enabled: true,
from: 2,
to: 4,
text: 'Target'
},
title: {
text: null
},
lineWidth: 1,
gridLineWidth: 1
}],
series: [{
data: [1, 3, 6, 2, 5]
}]
});```
Unfortunately, there is no option to create a custom plotBand like in the provided example, since the renderer module is not available in the Android wrapper.
The only way of achieving similar behaviour is using static plotBand.
HIYAxis hiyAxis = new HIYAxis();
HIPlotBands plotBands = new HIPlotBands();
plotBands.setColor(HIColor.initWithName("red"));
plotBands.setFrom(2);
plotBands.setTo(4);
hiyAxis.setPlotBands(new ArrayList<>(Collections.singletonList(plotBands)));
options.setYAxis(new ArrayList<>(Collections.singletonList(hiyAxis)));

How to download and get offline tiles in ionic 3 android app?

I am trying to develop a hybrid ol3 map application using ionic3 with angularjs. I have generated xyz tiles of the map service which I was able to use for online maps. When I tried using them for download to a local directory of mobile and use them I am facing issues. Kindly provide any help which is much appreciated. I I could not trace any errors. Kindly suggest me how to check if any errors to test the maps.
//For downloading the image from server and stores it into mobile directory.
this.file.createDir(this.file.externalRootDirectory, 'Offline/Maps/custom_', true).then((files) => {
this.file.createDir(this.file.externalRootDirectory, 'Offline/Maps/custom_/02_02', true).then((files) => {
}).catch((err) => {
});
}).catch((err) => {
});
const imageURL = 'https://server.com/documents/ionic/path_track/maps/0041_0041.jpeg';
const fileTransfer: FileTransferObject = this.transfer.create();
const imageName = imageURL.split('/').pop();
//alert(imageName+"#"+this.file.externalRootDirectory);
//alert(imageName);
fileTransfer.download(imageURL, this.file.externalRootDirectory+'Offline/Maps/custom_07/02_02/'+imageName).then((entry) => {
//loader.dismiss();
//this.showOfflineButton = true;
}, (error) => {
let alert = this.alertCtrl.create({
message: 'Map is not downloaded '+JSON.stringify(error),
buttons: ['Ok'],
enableBackdropDismiss: false,
cssClass:'alert-error'
});
alert.present();
});
//For retrieving image from the mobile directory and to display into mobile app.
var config = {
"bounds": {
"left" : 68.1060582899974,
"bottom" : 6.72246026992798,
"right" : 97.7525939941406,
"top" : 37.0967391635301
}
};
var bounds = [config.bounds.left, config.bounds.bottom, config.bounds.right, config.bounds.top];
var resolutions = [
0.1186495269281333,
0.0593247634640666,
0.0296623817320333,
0.0148311908660167,
0.0074155954330083,
0.0037077977165042,
0.0018538988582521,
0.000926949429126,
0.000463474714563,
0.0002317373572815,
0.0001158686786408,
0.0000579343393204,
0.0000289671696602,
0.0000144835848301,
0.000007241792415
];
var projection_epsg_no = 4326
var layername = 'seamless_xyz1';
var tileGrid = new ol.tilegrid.TileGrid({
extent: bounds,
resolutions: resolutions,
origin: ol.extent.getTopLeft(bounds),
projection: 'EPSG:4326',
tileSize: [256, 256]
});
var view = new ol.View({
extent: [55.948355423604156, 4.853611184459009, 101.73937104860416, 38.07626743445901],
zoom: 10,
center: [78.48695, 17.41217],
projection: 'EPSG:4326',
resolutions: resolutions
});
var tms_source = new ol.source.XYZ({
projection: 'EPSG:4326',
tileGrid: tileGrid,
url: this.file.externalRootDirectory+'/Offline/Maps/custom_{z}/{x}/{-y}.jpeg'
//url: this.file.externalRootDirectory+'/Offline/Maps/custom_07/02_02/0041_0043.jpeg' (If I am giving static image name then its coming fine but not able to do it dynamically.)
});
var basegroup = new ol.layer.Tile({
source: tms_source,
extent: bounds
});
var mapview;
if(this.Source_lat == undefined || this.Source_long == undefined){
this.current_location1 = 'Location is not available.';
mapview = new ol.View({
projection: 'EPSG:4326',
center: [82.491,21.899],
extent: [66.2329, 7.68083, 98.2223, 39.03874],
maxZoom:16,
minZoom: 8,
zoom: 8
});
}else{
this.current_location1 = this.Source_lat+', '+this.Source_long;
mapview = new ol.View({
projection: 'EPSG:4326',
center: [this.Source_long,this.Source_lat],
extent: [66.2329, 7.68083, 98.2223, 39.03874],
maxZoom:10,
minZoom: 10,
zoom: 10
});
}
map = new ol.Map({
target: 'offline_map',
controls: ol.control.defaults({
zoom: false,
attribution: false,
rotate: false
}),
layers: [basegroup, jsonLayer_net1, jsonLayer_net],
overlays: [jsonoverlay],
view: mapview
});
Thanks in advance

titanium appcelerator camera not found on samsung s-series or google pixel devices

I am developing a mobile app using Appcelerator Titanium Alloy. The code below opens the camera, allows the user to take a picture, and attaches it to an email template successfully on all iOS devices and the majority of Android devices I have been able to test with, including Motorola, LG, Panasonic, Samsung (not s-series works fine). When I attempt to open the camera on certain devices (so far only Samsung S7 & Google Pixel, but my access to devices is limited), I get an error:
[ERROR] : TiMedia: (KrollRuntimeThread) [12968,135705] Failed to create external storage directory.
I see that error in Appcelerator studio, and on the device I see the pop-up message "Please run this test on a device", which means it must be returning true at the line if (error.code == Titanium.Media.NO_CAMERA) below.
I have already requested external storage permissions and camera permissions at this point. I can't figure out why this only occurs on certain devices, and it does not seem to be specific to a certain version of Android OS. Any help would be appreciated.
var takePic = Ti.UI.createButton({
width : 127,
height : 42,
bottom : 50,
left : 8,
title : 'Take a picture',
color : "#fff",
backgroundColor : "#555555",
borderColor : "#FFFFFF",
borderRadius : "10px",
borderWidth : "1px"
});
takePic.addEventListener('click', function(e) {
var win = Titanium.UI.createWindow({//Open Camera
});
Titanium.Media.showCamera({
success : function(event) {
if (event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO) {
win = Titanium.UI.currentWindow;
if (osName == "android") {
var img_view = Titanium.UI.createImageView({
height : '100%',
width : '100%',
});
win.add(img_view);
}
try {
picURL = event.media;
picRaw = event.media;
pictureSet = true;
$.videoButton.enabled = false;
$.videoButton.backgroundColor = "#DDDDDD";
$.savePic.show();
format = "Picture";
} catch(e) {
alert("An Error:" + e.message);
}
} else {
var alert = createErrorAlert({
text : "An error occured getting the media. Please check file size and format and try again."
});
$.yesLatLon.add(alert);
alert.show();
}
},
cancel : function() {
//called when user cancels taking a picture
},
error : function(error) {
//called when there's an error
var a = Titanium.UI.createAlertDialog({
title : 'Camera'
});
if (error.code == Titanium.Media.NO_CAMERA) {
a.setMessage('Please run this test on device');
} else {
a.setMessage('Unexpected error: ' + error.code);
}
a.show();
},
saveToPhotoGallery : true,
allowEditing : false,
autohide : true, //Important!
mediaTypes : [Ti.Media.MEDIA_TYPE_PHOTO]
});
alert.hide();
});

How to export multiple modules from single JS file in Cordova/PhoneGap Plugin?

I am developing a custom Cordova plugin. For some reason, I am restricted to expose all my JS objects through single JavaScript file only. Below sample JS replicating my Problem
My JS have 2 objects apple and orange, I have to export them from single file
var apple = function() {
type: "macintosh",
color: "red",
getInfo: function () {
return this.color + ' ' + this.type + ' apple';
};
var orange = function() {
color: "red2",
show: function () {
alert("test type 2 also passed dude !----");;
}
};
I am exporting them like this
var apple1 = new apple();
module.exports = apple1;
var orange1 = new orange();
module.exports = orange1;
My problem is orange1 is overriding apple1 export. How to export both apple1 and orange1 using module.exports? or there any other way?
Please provide me some inputs. Any samples are most welcome.
Following approach worked for me.
var apple1 = new apple();
var orange1 = new orange();
var myExports = module.exports;
myExports .apple1 = apple1;
myExports .orange1 = orange1;

Titanium create calendar event

I am trying to create calendar event in my Titanium App for Android Platform. For that I am using below code, It does't give any error also didn't to create any calendar events
var calendars = Ti.Android.Calendar.selectableCalendars;
var names =[];
for (var i = 0; i<calendars.length; i++) {
names.push(calendars[i].name);
}
var calendarDialog = Titanium.UI.createOptionDialog({
title: 'Select a Calendar',
options: names,
cancel:1
});
calendarDialog.addEventListener('click', function(e){
var ci = e.index+1;
var calendar = Ti.Android.Calendar.getCalendarById(ci);
var eventBegins = new Date(2011, 12, 26, 12, 0, 0);
var eventEnds = new Date(2011, 12, 26, 14, 0, 0);
var hasReminder = true;
var details = {
title: 'i m testing',
description: 'message',
begin: eventBegins,
end: eventEnds,
hasAlarm:true,
allDay:true
};
var event = calendar.createEvent(details);
if (hasReminder)
{
var reminderDetails = {
minutes: 10,
method: Ti.Android.Calendar.METHOD_ALERT
};
event.createReminder(reminderDetails);
}
alert('Event was created!');
});
calendarDialog.show();
Anyone help me to solve this issue.. My Titanium SDK version is 1.7.5, I have tried this in Android 2.3 Phone
The following link might help you.
https://github.com/codememan/Titanium-Calendar
you need to add the necessary file in your project then you can import and run the Code from the .js file.

Categories

Resources