amCharts Map format currency - amcharts

How would I make this amCharts Map format the min/max value of the legend into a US currency?
var map = AmCharts.makeChart( "chartdiv", {
type: "map",
"theme": "light",
colorSteps: 10,
dataProvider: {
map: "usaLow",
areas: [ {
id: "US-AL",
value: 4447100
}, {
id: "US-AK",
value: 626932
}, {
id: "US-AZ",
value: 5130632
}, {
id: "US-AR",
value: 2673400
}, {
id: "US-CA",
value: 33871648
}, {
id: "US-CO",
value: 4301261
}, {
id: "US-CT",
value: 3405565
}, {
id: "US-DE",
value: 783600
}, {
id: "US-FL",
value: 15982378
}, {
id: "US-GA",
value: 8186453
}, {
id: "US-HI",
value: 1211537
}, {
id: "US-ID",
value: 1293953
}, {
id: "US-IL",
value: 12419293
}, {
id: "US-IN",
value: 6080485
}, {
id: "US-IA",
value: 2926324
}, {
id: "US-KS",
value: 2688418
}, {
id: "US-KY",
value: 4041769
}, {
id: "US-LA",
value: 4468976
}, {
id: "US-ME",
value: 1274923
}, {
id: "US-MD",
value: 5296486
}, {
id: "US-MA",
value: 6349097
}, {
id: "US-MI",
value: 9938444
}, {
id: "US-MN",
value: 4919479
}, {
id: "US-MS",
value: 2844658
}, {
id: "US-MO",
value: 5595211
}, {
id: "US-MT",
value: 902195
}, {
id: "US-NE",
value: 1711263
}, {
id: "US-NV",
value: 1998257
}, {
id: "US-NH",
value: 1235786
}, {
id: "US-NJ",
value: 8414350
}, {
id: "US-NM",
value: 1819046
}, {
id: "US-NY",
value: 18976457
}, {
id: "US-NC",
value: 8049313
}, {
id: "US-ND",
value: 642200
}, {
id: "US-OH",
value: 11353140
}, {
id: "US-OK",
value: 3450654
}, {
id: "US-OR",
value: 3421399
}, {
id: "US-PA",
value: 12281054
}, {
id: "US-RI",
value: 1048319
}, {
id: "US-SC",
value: 4012012
}, {
id: "US-SD",
value: 754844
}, {
id: "US-TN",
value: 5689283
}, {
id: "US-TX",
value: 20851820
}, {
id: "US-UT",
value: 2233169
}, {
id: "US-VT",
value: 608827
}, {
id: "US-VA",
value: 7078515
}, {
id: "US-WA",
value: 5894121
}, {
id: "US-WV",
value: 1808344
}, {
id: "US-WI",
value: 5363675
}, {
id: "US-WY",
value: 493782
} ]
},
areasSettings: {
autoZoom: true
},
valueLegend: {
right: 10,
},
"export": {
"enabled": true
}
} );
#chartdiv {
width : 100%;
height : 500px;
}
<script src="http://www.amcharts.com/lib/3/ammap.js"></script>
<script src="http://www.amcharts.com/lib/3/maps/js/usaLow.js"></script>
<script src="http://www.amcharts.com/lib/3/themes/light.js"></script>
<div id="chartdiv"></div>
I'm currently hardcoding the min/max values to dollar amounts, but I'm unable figure out how to auto format it using amCharts.

You could use value legend's minValue and maxValue properties, to set any formatted text. I.e.:
valueLegend: {
right: 10,
minValue: "$0M",
maxValue: "$3.38M"
}
To do the same automatically, use "init" event to get the maximum value as well as amCharts' global function addPrefix to auto-format the values:
"listeners": [{
"event": "init",
"method": function(event) {
// find out the highest value
var map = event.chart;
var max = map.maxValueReal;
// define function that formats currency
function formatCurrency(val) {
return "$" + AmCharts.addPrefix(
val,
map.prefixesOfBigNumbers,
map.prefixesOfSmallNumbers, {
precision: map.precision,
decimalSeparator: map.decimalSeparator,
thousandsSeparator: map.thousandsSeparator
}
);
}
// update value legend
map.valueLegend.minValue = formatCurrency(0);
map.valueLegend.maxValue = formatCurrency(max);
// update the map
map.validateNow();
}
}]
Here's a working demo.

Related

Return the wrong response if type of is number in the graphql

I tried to run the basic query in the graphql. But the below query is always return the no data if the typeof id is number. incase typeof id is string it returns the correct respone.
{
movie(id: 1) {
id
name
}
}
respone
{
"data": {
"movie": null
}
}
attached my code below
const graphql = require("graphql");
const _ = require("lodash");
const {
GraphQLObjectType,
GraphQLString,
GraphQLSchema,
GraphQLID,
GraphQLInt,
GraphQLList,
} = graphql;
const movies = [
{ name: "book1", genre: "Thriller", id: 1, directorId: 1 },
{ name: "book2", genre: "Horror", id: 2, directorId: 1 },
{ name: "book3", genre: "Historical", id: 3, directorId: 2 },
{ name: "book4", genre: "Thriller", id: 4, directorId: 1 },
{ name: "book5", genre: "Science Fiction", id: 5, directorId: 2 },
{ name: "book6", genre: "Horror", id: 6, directorId: 3 },
{ name: "book7", genre: "Romance", id: 7, directorId: 1 },
];
const directors = [
{ name: "directors1", age: "26", id: 1 },
{ name: "directors2", age: "36", id: 2 },
{ name: "directors3", age: "46", id: 3 },
];
const MovieType = new GraphQLObjectType({
name: "Movie",
fields: () => ({
id: { type: GraphQLID },
name: { type: GraphQLString },
genre: { type: GraphQLString },
director: {
type: DirectorType,
resolve: (parent, args) => {
return _.find(directors, { id: parent.directorId });
},
},
}),
});
const DirectorType = new GraphQLObjectType({
name: "Director",
fields: () => ({
id: { type: GraphQLID },
name: { type: GraphQLString },
age: { type: GraphQLInt },
movies: {
type: MovieType,
resolve: (parent, args) => {
return _.find(movies, { directorId: parent.id });
},
},
}),
});
const RootQuery = new GraphQLObjectType({
name: "RootQueryType",
fields: {
movie: {
type: MovieType,
args: { id: { type: GraphQLID } },
resolve(parent, args) {
console.log(args)
return _.find(movies, { id: args.id });
},
},
director: {
type: DirectorType,
args: {id: {type: GraphQLID}},
resolve(parent, args) {
return _.find(directors, {id: args.id})
}
},
movies: {
type: new GraphQLList(MovieType),
resolve() {
return movies;
},
},
directors: {
type: new GraphQLList(DirectorType),
resolve() {
return directors;
},
},
},
});
module.exports = new GraphQLSchema({
query: RootQuery,
});
not sure what I have missed.

Kendo Schedular Uncaught TypeError: Cannot read property 'getTimezoneOffset' of undefined

<script>
$("#scheduler").kendoScheduler({
startTime: new Date("#DateTime.Now"),
height: 600,
views: [
"day",
{ type: "workWeek", selected: true },
"week",
"month",
"agenda",
{ type: "timeline", eventHeight: 50}
],
timezone: "Etc/GMT",
date: new Date("#DateTime.Now"),
dataSource: {
batch: true,
transport: {
read: {
url: url + "read",
dataType: "json",
type: "GET"
},
update: {
url: url + "update",
dataType: "json",
type: "POST"
},
create: {
url: url + "create",
dataType: "json",
type: "POST"
},
destroy: {
url: url + "destory",
dataType: "json",
type: "POST"
},
parameterMap: function (options, operation) {
return {
models: options.models,
};
}
},
schema: {
model: {
id: "ID",
fields: {
ID: { from: "ID", type: "number" },
Title: { from: "Title", defaultValue: "No title", validation: { required: true } },
Start: { type: "datetime", from:"Start" , format: "{0:dd-MM-yyyy}"},
End: { type: "datetime", from: "End", format: "{0:dd-MM-yyyy}" },
Description: { from: "Description" },
UserID: { from: "UserID", defaultValue: 1 },
IsAllDay: { type: "boolean", from: "IsAllDay" }
}
}
},
filter: {
logic: "or",
filters: [
{ field: "UserID", operator: "eq", value: 1 },
{ field: "UserID", operator: "eq", value: 2 }
]
}
},
resources: [
{
field: "UserID",
title: "Owner",
dataSource: [
{ text: "Alex", value: 1, color: "#f8a398" },
{ text: "Bob", value: 2, color: "#51a0ed" },
{ text: "Charlie", value: 3, color: "#56ca85" }
]
}
]
});
</script>
I've got this problem according the date property in the Kendo UI scheduler. It keeps saying that it's undefined but I'm really sure I defined it as you can see. I've been searching now for a while but I still haven't found the answer. Maybe someone could help me? I can provide every piece of could you would like to see.

Kendo UI scheduler doesn't display data

I am currently working on a kendoscheduler for a sharepoint list. I'm building off of this demo.
I'm populating my demo with the data which is present at this URL, which I have mapped locally. The only difference between the article and my code is that their URL is http://demos.telerik.com/kendo-ui/scheduler/timeline-night but mine is some JSON stored in a local file.
Here is my code:
<script>
$(function () {
$("#scheduler").kendoScheduler({
date: new Date("2013/6/12"),
startTime: new Date("2013/6/12 08:00 PM"),
endTime: new Date("2013/6/12 08:00 PM"),
dateHeaderTemplate: kendo.template("<strong>#=kendo.toString(date, 'D')# - #=kendo.toString(kendo.date.nextDay(date), 'D')#</strong>"),
eventHeight: 50,
majorTick: 360,
views: [ "timeline", "timelineWeek" ],
timezone: "Etc/UTC",
dataSource: {
batch: true,
transport: {
read: {
url: _spPageContextInfo.webAbsoluteUrl + "/_layouts/15/Stomo/Ajax.aspx/GetDataForTimeline",
}
},
schema: {
model: {
id: "meetingID",
fields: {
meetingID: { from: "MeetingID", type: "number" },
title: { from: "Title", defaultValue: "No title", validation: { required: true } },
start: { type: "date", from: "Start" },
end: { type: "date", from: "End" },
startTimezone: { from: "StartTimezone" },
endTimezone: { from: "EndTimezone" },
description: { from: "Description" },
recurrenceId: { from: "RecurrenceID" },
recurrenceRule: { from: "RecurrenceRule" },
recurrenceException: { from: "RecurrenceException" },
roomId: { from: "RoomID", nullable: true },
attendees: { from: "Attendees", nullable: true },
isAllDay: { type: "boolean", from: "IsAllDay" }
}
}
}
},
group: {
resources: ["Rooms"],
orientation: "vertical"
},
resources: [{
field: "roomId",
name: "Rooms",
dataSource: [
{ text: "Meeting Room 101", value: 1, color: "#6eb3fa" },
{ text: "Meeting Room 201", value: 2, color: "#f58a8a" }
],
title: "Room"
}]
});
});
</script>
Here is the response i am getting from my ajax call
[
{
"MeetingID":2,
"RoomID":1,
"Attendees":[
2
],
"Title":"Meeting with customers.",
"Description":"",
"StartTimezone":null,
"Start":"\/Date(1370865600000)\/",
"End":"\/Date(1370872800000)\/",
"EndTimezone":null,
"RecurrenceRule":null,
"RecurrenceID":null,
"RecurrenceException":null,
"IsAllDay":false
},
{
"MeetingID":3,
"RoomID":2,
"Attendees":[
1,
2
],
"Title":"Guided tour for the investors.",
"Description":"",
"StartTimezone":null,
"Start":"\/Date(1370865600000)\/",
"End":"\/Date(1370872800000)\/",
"EndTimezone":null,
"RecurrenceRule":null,
"RecurrenceID":null,
"RecurrenceException":null,
"IsAllDay":false
}]
Do you have any thoughts on how to make this work correctly?

Adding multiple series to Chart

I'm currently trying to build a chart showing number of downloads of a product per date.
A sample of the current code is as follows:
var downloads = [
{ value: 48, date: new Date("2013/11/01") },
{ value: 50, date: new Date("2013/11/02") },
{ value: 55, date: new Date("2013/11/03") },
{ value: 35, date: new Date("2013/11/04") }
];
$("#chart").kendoChart({
dataSource: {
data: downloads
},
series: [{
type: "line",
aggregate: "avg",
field: "value",
categoryField: "date"
}],
categoryAxis: {
baseUnit: "days",
min: new Date("2013/10/31"),
max: new Date("2013/11/10"),
labels: {
dateFormats: {
days: "dd/MM"
}
}
}
});
It works fine if I have to display data for one product only. How would I proceed to display download data for another product, i.e. adding another series to the chart?
Right! I figured it out myself. Here it is:
$("#chart").kendoChart({
seriesDefaults: {
tooltip: {
visible: true,
},
type:"line",
aggregate:"avg",
field:"value",
categoryField:"date"
},
series: [{
name: "Product 1",
data: [{ value: 48, date: new Date("2013/11/01") }, { value: 50, date: new Date("2013/11/02") }]
},
{
name: "Product 2",
data: [{ value: 55, date: new Date("2013/11/03") }, { value: 35, date: new Date("2013/11/04") }]
}],
categoryAxis: {
baseUnit: "days",
min: new Date("2013/10/31"),
max: new Date("2013/11/10"),
labels: {
dateFormats: {
days: "dd/MM"
}
}
}
});

kendo grid how to set the schema.model with a foreign key field

need help about adding a new recort in a kendo grid.
I have a grid with a foreign key field. The grid is populated by a json data with subobject, returned from a webmethod. it looks like this:
[
{
"classe_iva": {
"id_classe_iva": 5,
"desc_classe_iva": "Esente",
"note_classe_iva": null
},
"id_iva": 37,
"desc_iva": "bbb",
"codice_iva": "bbb",
"imposta": 2,
"indetr": 2,
"id_classe_iva": 5,
"note": "dddddfsf",
"predefinito": false,
"id_company": 4
},
{
"classe_iva": {
"id_classe_iva": 6,
"desc_classe_iva": "Escluso",
"note_classe_iva": null
},
"id_iva": 52,
"desc_iva": "o",
"codice_iva": "jj",
"imposta": 1,
"indetr": 1,
"id_classe_iva": 6,
"note": "l",
"predefinito": false,
"id_company": 4
}
]
and this is the schema.model used in the kendo datasource:
model = {
id: "id_iva",
fields: {
id_iva: { type: "string", editable: false },
desc_iva: { type: "string" },
codice_iva: { type: "string" },
imposta: { type: "number" },
indetr: { type: "number" },
id_classe_iva: {type: "string"},
note: { type: "string" },
predefinito: { type: "boolean" },
id_company: { type: "number" }
}
}
.. and below is shown the grid columns format:
toolbar = [{
name: "create",
text: "Aggiungi nuova aliquota IVA"
}];
columns = [
{ field: "desc_iva", title: "Descrizione", width: 45 },
{ field: "codice_iva", title: "Codice", width: 45 },
{ field: "imposta", title: "Imposta", width: 45 },
{ field: "indetr", title: "Indetr", width: 45 },
{ field: "classe_iva.desc_classe_iva", title: "Classe IVA", width: 200, editor: categoryDropDownEditor, template: "#= classe_iva ? classe_iva.desc_classe_iva : 1 #", defaultValue: { id_classe_iva: 1, desc_classe_iva: "Acq. Intra-UE" } },
{ field: "note", title: "Note", width: 45 },
{
command: [{
name: "destroy",
text: "Elimina",
confirmation: "Sei sicuro di voler eliminare questa voce?"
} ,
{
name: "edit",
text: {
edit: "Modifica",
update: "Aggiorna",
cancel: "Cancella"
}
}
]
}
];
Theese settings works fine when i edit a row, and the grid shows the right content into the combobox field.
The problem is when i click on the "add new record" button, because when it tries to add a new row, it doesn't find the subobjects field "classe_iva".
if i change the column.field into this
{ field: "id_classe_iva", title: "Classe IVA", width: 200, editor: categoryDropDownEditor, template: "#= id_classe_iva ? id_classe_iva : 1 #", defaultValue: { id_classe_iva: 1, desc_classe_iva: "Acq. Intra-UE" } },
{ field: "note", title: "Note", width: 45 }
the add button works fine, but when the grid is loaded, the column id_classe_iva doesn't shows me the classe_iva.desc_classe_iva field...
how can i fix the issue??^?
thanks in advance.
to fix this issue, i used a workaround:
the error was thrown because, in the declaration of the field.template there where a not declared variable (classe_iva):
{ field: "id_classe_iva", title: "Classe IVA", width: 200, editor: categoryDropDownEditor, template: "#= classe_iva ? classe_iva.desc_classe_iva : 1 #", defaultValue: { id_classe_iva: 1, desc_classe_iva: "Acq. Intra-UE" } },
then, i declared a global variable
var classe_iva;
in this way, when i add a new record, the code doesn't throw any errors, and by the ternary if, the default value is set.
hope it will help someone.

Resources