How to create doughnut highchart using angular JS - angularjs

I want to create a doughnut highchart using angular js.
javascript is-
$(function () {
$('#container').highcharts({
chart: {
plotBackgroundColor: null,
plotBorderWidth: 0,
plotShadow: false
},
title: {
text: 'Browser<br>shares<br>2015',
align: 'center',
verticalAlign: 'middle',
y: 40
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
},
plotOptions: {
pie: {
dataLabels: {
enabled: true,
distance: -50,
style: {
fontWeight: 'bold',
color: 'white',
textShadow: '0px 1px 2px black'
}
},
startAngle: -180,
endAngle: 180,
center: ['50%', '55%']
}
},
series: [{
type: 'pie',
name: 'Browser share',
innerSize: '50%',
data: [
['Firefox', 10.38],
['IE', 56.33],
['Chrome', 24.03],
['Safari', 4.77],
['Opera', 0.91],
{
name: 'Proprietary or Undetectable',
y: 0.9,
dataLabels: {
enabled: false
}
}
]
}]
});
});
html is-
<div id="container" style="min-width: 310px; height: 400px; max-width: 600px; margin: 0 auto"></div>
and I am including these scripts files -
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
How would I convert the above script in angular js. Can anyone help me on this?
I think some directive function needs to be created.I am new to custom directives in angular, can anybody help how we do this in angular for the doughnut highchart?

No need to convert the highcharts in angular as its already exists. No need to inject the dependencies. You can use it directly. Just inject the highcharts
files
<script src="script/chart/highcharts.js"></script>
<script src="script/chart/highcharts-more.js"></script>
<script src="script/chart/drilldown.js"></script>
<script src="script/chart/highcharts-3d.js"></script>
<script src="script/chart/exporting.js"></script>
as per need. and in controller use directly the Highcharts.chart({//code goes here}). Here is the link for donut highchart

Related

How to make google maps search box with Multiple markers and and with different infowindow/info Popup Open onClick

I am trying to make Google Map with multiple markers and search box with different Infowindow of our locations in only one country on click and I am not able to do further,
I have written this Code:-
<html>
<head>
<title>Medplus Clinic Locator</title>
<script src="https://polyfill.io/v3/polyfill.min.js?features=default"></script>
<!-- <link rel="stylesheet" type="text/css" href="./style.css" />
<script type="module" src="./index.js"></script> -->
<link rel="stylesheet" href="map-style.css">
<script src="mapjs.js"></script>
</head>
<style>
/*
* Always set the map height explicitly to define the size of the div element
* that contains the map.
*/
#map {
height: 100%;
}
/*
* Optional: Makes the sample page fill the window.
*/
html,
body {
height: 100%;
margin: 0;
padding: 0;
}
#description {
font-family: Roboto;
font-size: 15px;
font-weight: 300;
}
#infowindow-content .title {
font-weight: bold;
}
#infowindow-content {
display: none;
}
#map #infowindow-content {
display: inline;
}
.pac-card {
background-color: #fff;
border: 0;
border-radius: 2px;
box-shadow: 0 1px 4px -1px rgba(0, 0, 0, 0.3);
margin: 10px;
padding: 0 0.5em;
font: 400 18px poppins, Arial, sans-serif;
overflow: hidden;
font-family: Roboto;
padding: 0;
}
#pac-container {
padding: 10px 5px;
margin-right: 12px;
}
.pac-controls {
display: inline-block;
padding: 5px 11px;
}
.pac-controls label {
font-family: Roboto;
font-size: 12px;
font-weight: 300;
}
#pac-input {
background-color: #fff;
font-family: Roboto;
font-size: 15px;
font-weight: 300;
margin-left: 12px;
padding: 0 11px 0 13px;
text-overflow: ellipsis;
width: 400px;
}
#pac-input:focus {
border-color: #1B5EA9;
}
#title {
color: #fff;
background-color: #1B5EA9;
font-size: 25px;
font-weight: 500;
padding: 6px 12px;
}
</style>
<script>
function initMap() {
const map = new google.maps.Map(document.getElementById("map"), {
center: { lat: 52.632469, lng: -1.689423 },
zoom: 7,
mapTypeControl: false,
});
const card = document.getElementById("pac-card");
map.controls[google.maps.ControlPosition.TOP_RIGHT].push(card);
const center = { lat: 53.81078096004558, lng: -1.5359415045562201 }; /* old { lat: 50.064192, lng: -130.605469 }*/
// Create a bounding box with sides ~10km away from the center point
const defaultBounds = {
north: center.lat + 0.1,
south: center.lat - 0.1,
east: center.lng + 0.1,
west: center.lng - 0.1,
};
const input = document.getElementById("pac-input");
const options = {
bounds: defaultBounds,
componentRestrictions: { country: "uk" },
fields: ["address_components", "geometry", "icon", "name"],
strictBounds: false,
types: ["establishment"],
};
const autocomplete = new google.maps.places.Autocomplete(input, options);
// Set initial restriction to the greater list of countries.
autocomplete.setComponentRestrictions({
country: ["uk"],
});
const southwest = { lat: 5.6108, lng: 136.589326 };
const northeast = { lat: 61.179287, lng: 2.64325 };
const newBounds = new google.maps.LatLngBounds(southwest, northeast);
autocomplete.setBounds(newBounds);
const infowindow = new google.maps.InfoWindow();
const infowindowContent = document.getElementById("infowindow-content");
infowindow.setContent(infowindowContent);
const marker = new google.maps.Marker({
map, anchorPoint: new google.maps.Point(0, -29),
});
autocomplete.addListener("place_changed", () => {
infowindow.close();
marker.setVisible(false);
const place = autocomplete.getPlace();
if (!place.geometry || !place.geometry.location) {
// User entered the name of a Place that was not suggested and
// pressed the Enter key, or the Place Details request failed.
window.alert("No address available for input: '" + place.name + "'");
return;
}
// If the place has a geometry, then present it on a map.
if (place.geometry.viewport) {
map.fitBounds(place.geometry.viewport);
} else {
map.setCenter(place.geometry.location);
map.setZoom(14); // Why 17? Because it looks good.
}
marker.setPosition(place.geometry.location);
marker.setVisible(true);
let address = "";
ma
if (place.address_components) {
address = [
(place.address_components[0] &&
place.address_components[0].short_name) ||
"",
(place.address_components[1] &&
place.address_components[1].short_name) ||
"",
(place.address_components[2] &&
place.address_components[2].short_name) ||
"",
].join(" ");
}
infowindowContent.children["place-icon"].src = place.icon;
infowindowContent.children["place-name"].textContent = place.name;
infowindowContent.children["place-address"].textContent = address;
infowindow.open(map, marker);
});
// Sets a listener on a given radio button. The radio buttons specify
// the countries used to restrict the autocomplete search.
function setupClickListener(id, uk) {
const radioButton = document.getElementById(id);
radioButton.addEventListener("click", () => {
autocomplete.setComponentRestrictions({ country: uk });
});
}
setupClickListener("changecountry-usa", "uk");
setupClickListener("changecountry-usa-and-uot", ["uk"]);
// Set the map's style to the initial value of the selector.
const styleSelector = document.getElementById("style-selector");
map.setOptions({ styles: styles[styleSelector.value] });
// Apply new JSON when the user selects a different style.
styleSelector.addEventListener("change", () => {
map.setOptions({ styles: styles[styleSelector.value] });
});
}
const styles = {
default: [],
silver: [
{
elementType: "geometry",
stylers: [{ color: "#f5f5f5" }],
},
{
elementType: "labels.icon",
stylers: [{ visibility: "off" }],
},
{
elementType: "labels.text.fill",
stylers: [{ color: "#616161" }],
},
{
elementType: "labels.text.stroke",
stylers: [{ color: "#f5f5f5" }],
},
{
featureType: "administrative.land_parcel",
elementType: "labels.text.fill",
stylers: [{ color: "#bdbdbd" }],
},
{
featureType: "poi",
elementType: "geometry",
stylers: [{ color: "#eeeeee" }],
},
{
featureType: "poi",
elementType: "labels.text.fill",
stylers: [{ color: "#757575" }],
},
{
featureType: "poi.park",
elementType: "geometry",
stylers: [{ color: "#e5e5e5" }],
},
{
featureType: "poi.park",
elementType: "labels.text.fill",
stylers: [{ color: "#9e9e9e" }],
},
{
featureType: "road",
elementType: "geometry",
stylers: [{ color: "#ffffff" }],
},
{
featureType: "road.arterial",
elementType: "labels.text.fill",
stylers: [{ color: "#757575" }],
},
{
featureType: "road.highway",
elementType: "geometry",
stylers: [{ color: "#dadada" }],
},
{
featureType: "road.highway",
elementType: "labels.text.fill",
stylers: [{ color: "#616161" }],
},
{
featureType: "road.local",
elementType: "labels.text.fill",
stylers: [{ color: "#9e9e9e" }],
},
{
featureType: "transit.line",
elementType: "geometry",
stylers: [{ color: "#e5e5e5" }],
},
{
featureType: "transit.station",
elementType: "geometry",
stylers: [{ color: "#eeeeee" }],
},
{
featureType: "water",
elementType: "geometry",
stylers: [{ color: "#c9c9c9" }],
},
{
featureType: "water",
elementType: "labels.text.fill",
stylers: [{ color: "#9e9e9e" }],
},
],
/* adding multiple markers */
}
window.initMap = initMap;
</script>
<body>
<div class="pac-card" id="pac-card">
<div>
<div id="title">Find the Medplus nearest Clinic</div>
<div id="country-selector" class="pac-controls">
<input type="radio" name="type" id="changecountry-usa" />
<label for="changecountry-usa">Search by Post Code/Region</label>
<input type="radio" name="type" id="changecountry-usa-and-uot" checked="checked"/>
<label for="changecountry-usa-and-uot">Search by Address</label
>
</div>
</div>
<div id="pac-container">
<input id="pac-input" type="text" placeholder="Enter a location" />
</div>
</div>
<div id="map"></div>
<div id="infowindow-content">
<img src="" width="16" height="16" id="place-icon" />
<span id="place-name" class="title"></span><br />
<span id="place-address"></span>
</div>
<!-- map coloring to sliver -->
<div id="style-selector-control" class="map-control">
<select id="style-selector" class="selector-control">
<option value="silver">Silver</option>
</select>
</div>
<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY"></script>
</body>
</html>
I want to make like this as mentioned (screen shot)
enter image description here
anyone please resolve this if possible, thank you!

Google StreetView in extjs 6

I'm new to extjs and cant find a way to put a google StreetView inside a panel. Can someone point me in the right direction?. I have tried from interpreting an html inside a panel to the old GMapPanel but I doesn't work.
Currently I have this function where the panel shows up but doesn't show the street view
function () {
alert("mostrar street view");
new Ext.Panel({
id: "streetView",
xtype: "map",
constrain: true,
floating: true,
resize: true,
width: 600,
height: 400,
closable: true,
style: {
backgroundColor: "#fff",
//backgroundColor: '#000',
border: "1px solid black",
},
listeners: {
click: Ext.Window({
layout: "fit",
closeAction: "hide",
title: "GPanorama Window",
width: 400,
height: 300,
x: 480,
y: 60,
items: {
xtype: "gmappanel",
gmapType: "panorama",
setCenter: {
lat: 42.345573,
long: -71.098326,
},
},
}),
},
draggable: {
delegate: "div",
},
}).show();
I have also tried placing the property html as follows html:'CODE-BELOW'
<head>
<title>Street View split-map-panes</title>
<script src="https://polyfill.io/v3/polyfill.min.js?features=default"></script>
<style type="text/css">
html,
body {
height: 100%;
margin: 0;
padding: 0;
}
#map,
#pano {
float: left;
height: 100%;
width: 50%;
}
</style>
<script>
function initialize() {
const fenway = { lat: 42.345573, lng: -71.098326 };
const map = new google.maps.Map(document.getElementById("map"), {
center: fenway,
zoom: 14,
});
const panorama = new google.maps.StreetViewPanorama(
document.getElementById("pano"),
{ position: fenway, pov: { heading: 34, pitch: 10 } }
);
map.setStreetView(panorama);
}
</script>
</head>
<body>
<div id="map"></div>
<div id="pano"></div>
<script
src="https://maps.googleapis.com/maps/api/js?key=API-KEY&callback=initialize&libraries=&v=weekly"
async></script>
</body>

Chart.js V2.1.4 does working, with backbone view

I want to use a upgraded version of Chart.js v2.1.4 with Backbone View(working fine with v1.0.2) as because of additional features.But it not working with upgraded version v 2.1.4.
Code snippet are:
define([
'underscore',
'jquery',
'backbone',
'Chart',
'text!templates/dashboard/graph-view-template.html'
], function(_, $, Backbone, Chart, GraphViewTemplate) {
var GraphView = Backbone.View.extend({
template: GraphViewTemplate,
events: {
},
elements: {
},
initialize: function(options){
this.options = options;
},
render: function(){
this.$el.html(this.template);
this.renderTempGraph();
return this;
},
renderTempGraph: function(){
var ctx = this.$el.find("#myChart").get(0).getContext("2d");
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: ["Red", "Blue", "Yellow"],
datasets: [{
label: '# of Votes',
data: [12, 19, 3],
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
'rgba(54, 162, 235, 0.2)',
'rgba(255, 159, 64, 0.2)'
],
borderColor: [
'rgba(255,99,132,1)',
'rgba(54, 162, 235, 1)',
'rgba(255, 159, 64, 1)'
],
borderWidth: 1
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero:true
}
}]
}
}
});
}
return GraphView;
});
<canvas id="myChart" width="400" height="400"></canvas>
after render, canvas element properties look like as
<iframe class="chartjs-hidden-iframe" style="width: 100%; display: block; border: 0px; height: 0px; margin: 0px; position: absolute; left: 0px; right: 0px; top: 0px; bottom: 0px;">
</iframe>
<canvas id="myChart" width="0" height="0" style="width: 0px; height: 0px;"></canvas>

Is there a way for me add a text right after the title in donut chart?

I'm using nvd3js for angular (http://krispo.github.io/angular-nvd3/#/), and I would like to add a text right after the title (in this case the title is 98%) and the text to be added is "done". I was able to make it work so far, but I couldn't seem to make it work. This is my plunkr so far: http://plnkr.co/edit/KSdnFepUaI4MUCwAQJgP?p=preview
chart: {
type: 'pieChart',
height: 100,
width: 200,
donut: true,
x: function(d){return d.key;},
y: function(d){return d.y;},
showLabels: false,
showLegend: false,
title: '89%',
transitionDuration: 500,
tooltips: false,
donutRatio: 1
}
<nvd3 options="options" data="data"></nvd3>
<style>
.nv-pie-title {
text-anchor: middle;
font-size: 95px !important;
fill: #cccccc !important;
}
</style>

Using a form checkbox in a div to control the visibility of a vector layer in OpenLayers

I am trying to toggle the visibility of a vector layer in OpenLayers that displays a gpx trace using a form button defined in the body, and positioned over the map using a div. I don't want to use the built in control as it is by default hidden, and I want to add further info by the checkbox.
<input name="slow" type="checkbox" class="newstext"
id="slow" onClick="slowtrace();" checked>
The function 'slowtrace' is in the head script. 'lgpx2' is the vector layer showing the trace:
function slowtrace()
{if (lgpx2.getVisibility() == true)
{lgpx2.setVisibility(false);}
else
{lgpx2.setVisibility(true);}}
However it doesn't work, giving the error - Reference error: can't find variable: slowtrace.
There are two vector layers showing two gpx traces. I've been trying this with the slow trace 'lgpx2', not the other named 'lgpx', and the upper tick box in the div over the map, corresponding to 'slow run'.
The code for the whole page is:
<html>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<head>
<link rel="stylesheet" href="http://www.carnethy.com/carn.css" type="text/css">
<title>Wed training 20th March 2013 - golf courses</title>
<script src="http://www.openlayers.org/api/OpenLayers.js"></script>
<script src="http://www.openstreetmap.org/openlayers/OpenStreetMap.js"></script>
<script type="text/javascript">
var lat
var lon
var zoom
var latstart=55.92900
var lonstart=-3.19300
var map;
function init() {
map = new OpenLayers.Map ("map", {controls:[
new OpenLayers.Control.Navigation({zoomWheelEnabled : false}),
new OpenLayers.Control.PanZoomBar(),
new OpenLayers.Control.LayerSwitcher(),
new OpenLayers.Control.Attribution()],
maxExtent: new OpenLayers.Bounds(-20037508.34,- 20037508.34,20037508.34,20037508.34),
maxResolution: 156543.0399,
numZoomLevels: 19,
units: 'm',
projection: new OpenLayers.Projection("EPSG:900913"),
displayProjection: new OpenLayers.Projection("EPSG:4326")
} );
layerMapnik = new OpenLayers.Layer.OSM.Mapnik("Mapnik");
map.addLayer(layerMapnik);
layerCycleMap = new OpenLayers.Layer.OSM.CycleMap("CycleMap");
map.addLayer(layerCycleMap);
layerMarkers = new OpenLayers.Layer.Markers("Markers");
map.addLayer(layerMarkers);
//slow run stylemap
var gpxStyles = new OpenLayers.StyleMap({
"default": new OpenLayers.Style({
pointRadius: "1", // sized according to type attribute
label: "${name}",
labelAlign: "rb",
labelOutlineColor: "white",
labelOutlineWidth: 3,
fontSize: 15,
fontFamily: "Arial",
fontColor: "brown",
labelYOffset: 10,
fillColor: "black",
strokeColor: "red",
strokeWidth: 2,
strokeOpacity: 0.8
}),
});
//fast run stylemap
var gpxStyles2 = new OpenLayers.StyleMap({
"default": new OpenLayers.Style({
pointRadius: "1", // sized according to type attribute
label: "${name}",
labelAlign: "rb",
labelOutlineColor: "white",
labelOutlineWidth: 3,
fontSize: 15,
fontFamily: "Arial",
fontColor: "blue",
labelYOffset: 10,
fillColor: "black",
strokeColor: "blue",
strokeWidth: 2,
strokeOpacity: 0.8,
}),
});
// Add the Layer with the GPX Track fast run - ignore this bit
var lgpx = new OpenLayers.Layer.Vector("wed training fast", {
strategies: [new OpenLayers.Strategy.Fixed()],
protocol: new OpenLayers.Protocol.HTTP({
url: "http://www.carnethy.com/maps/wed_training/2013/gpx/20-Mar-13-fast.gpx",
format: new OpenLayers.Format.GPX({extractWaypoints: true, extractRoutes: true, extractAttributes: true})
}),
styleMap: gpxStyles,
projection: new OpenLayers.Projection("EPSG:4326")
});
map.addLayer(lgpx);
// fit map to bounds of window and add start pin
lgpx.events.register("loadend", lgpx, function() {
this.map.zoomToExtent(this.getDataExtent());
var startPoint = this.features[0].geometry.components[0];
layerMarkers.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(startPoint.x, startPoint.y),icon));
});
// Add the Layer with the GPX Track slow run
// This is the layer I am practising on
var lgpx2 = new OpenLayers.Layer.Vector("wed training slow", {
strategies: [new OpenLayers.Strategy.Fixed()],
protocol: new OpenLayers.Protocol.HTTP({
url: "http://www.carnethy.com/maps/wed_training/2013/gpx/20-Mar-13-slow.gpx",
format: new OpenLayers.Format.GPX({extractWaypoints: true, extractRoutes: true, extractAttributes: true})
}),
styleMap: gpxStyles2,
projection: new OpenLayers.Projection("EPSG:4326"),
});
map.addLayer(lgpx2);
// fit map to bounds of window and add start pin
lgpx2.events.register("loadend", lgpx2, function() {
this.map.zoomToExtent(this.getDataExtent());
var startPoint = this.features[0].geometry.components[0];
layerMarkers.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(startPoint.x, startPoint.y),icon));
});
// the non functional function
function slowtrace()
{if (lgpx2.getVisibility() == true)
{lgpx2.setVisibility(false);}
else
{lgpx2.setVisibility(true);}}
var size = new OpenLayers.Size(21, 25);
var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
var icon = new OpenLayers.Icon('http://www.carnethy.com/maps/mapping%20info/small_red_pin.png',size,offset);
var icon2 = new OpenLayers.Icon('http://www.carnethy.com/maps/mapping%20info/small_blue_pin.png',size,offset);
}
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
.mapposn {
display: block;
position: absolute;
left: 0px;
top: 0px;
height: 100%;
width: 100%;
}
#key {
height: 40px;
width: 360px;
position: absolute;
left: 50%;
margin-left: -150px;
font-family: Verdana, Geneva, sans-serif;
font-size: small;
background-color: #FFF;
top: 25px;
padding-left: 10px;
padding-top: 3px;
border: 1px solid #666;
}
#blue {
width: 85px;
display: inline;
left: 105px;
font-size: 2px;
position: absolute;
background-color: #36F;
margin-top: 7px;
}
#red {
width: 85px;
display: inline;
left: 105px;
font-size: 2px;
position: absolute;
background-color: #C30;
margin-top: 7px;
}
-->
</style>
</head>
<body onLoad="init();">
<div class="mapposn" id="map"></div>
<div id="key"><span class="plaintext" style="color:#36F">
<input name="slow" type="checkbox" class="newstext" id="slow" onClick="slowtrace();" checked>
Slow run 6.82 miles (10.98k) </span>
<div id="blue"> </div><br>
<span class="plaintext" style="color:#C30">
<input name="Fast" type="checkbox" class="newstext" id="fast" checked>
Fast run 7.93 miles (12.8k)</span>
<div id="red"> </div>
</div>
</body>
</html>
I've made it work using jquery. It looks in the named div to see whether the checkbox has been unchecked/toggled. I adapted this code from an example so don't really know why it works, or why the previous version didn't. So if anyone can enlighten me? Is there a way to do it without jquery?
Solution:
Add link to jquery src,
take out the onclick event from the checkboxes...
<input name="slow" type="checkbox" class="newstext" id="slow" checked>
...and write the visibility function thus:
$(document).ready(function(){
function slowtrace()
{if (lgpx2.getVisibility() == true)
{lgpx2.setVisibility(false);}
else
{lgpx2.setVisibility(true);}}
function fasttrace()
{if (lgpx.getVisibility() == true)
{lgpx.setVisibility(false);}
else
{lgpx.setVisibility(true);}}
$("#slow").on("change", slowtrace);
$("#fast").on("change", fasttrace);
});

Resources