How to get the month names in kendo chart by using function - kendo-ui

How to create a function to get the month as Jan,feb.. displayed in kendo chart x axis.
var internetUsers = [ {
"Month": "1",
"year": "2010",
"value": 1
}, {
"Month": "2",
"year": "2010",
"value": 2
}, {
"Month": "3",
"year": "2010",
"value": 3
}, {
"Month": "4",
"year": "2010",
"value": 4
}, {
"Month": "5",
"year": "2010",
"value": 5
},
{
"Month": "6",
"year": "2010",
"value": 6
}, {
"Month": "7",
"year": "2010",
"value": 7
}, {
"Month": "8",
"year": "2010",
"value": 8
}];
function createChart() {
$("#chart").kendoChart({
theme: $(document).data("kendoSkin") || "default",
dataSource: {
data: internetUsers,
group: {
field: "year"
},
sort: {
field: "year",
dir: "asc"
}
},
title: {
text: "Sales"
},
legend: {
position: "bottom"
},
seriesDefaults: {
type: "column"
},
series: [{
field: "value"
}],
valueAxis: {
labels: {
format: "{0}$"
},
line: {
visible: false
},
axisCrossingValue: 0
},
categoryAxis: {
field: "Month"
},
tooltip: {
visible: true,
format: "{0}%",
template: "#= series.name #: #= value #"
}
});
}
$(document).ready(function() {
setTimeout(function() {
// Initialize the chart with a delay to make sure
// the initial animation is visible
createChart();
$("#example").bind("kendo:skinChange", function(e) {
createChart();
});
}, 400);
});
</script>

You could use kendoui's time format function:
kendo.toString(new Date(2000, value, 1), "MMMM"); // if value = 9, it would output September
Check out kendoui's date format page. It is VERY helpful.
http://docs.telerik.com/kendo-ui/getting-started/framework/globalization/dateformatting

First add an array to hold the month names, like so:
var monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug"];
then modify the categoryAxis to use this array
categoryAxis: {
field: "Month",
labels: {
template: "#=monthNames[value - 1]#"
},
},

Related

Threejs: How do I add a random jpg texture over a 3d model

I am new to threejs and I wanted to know if I can add a random jpg picture as my texture. I figured out how to add materials to my model, but I cant really figure out how to add texture. This is a spinet of my json model and my code for changing texture:
"textures": [],
"animations": [{
"fps": 29,
"tracks": [{
"type": "vector3",
"keys": [{
"value": [0.000392,0.249157,-0.004437],
"time": 0
},{
"value": [0.000392,0.249157,-0.004437],
"time": 120
},{
"value": [0.000392,0.249157,-0.004437],
"time": 240
},{
"value": [0.000392,0.249157,-0.004437],
"time": 360
}],
"name": "CameraPreset.position"
},{
"type": "vector3",
"keys": [{
"value": [1,1,1],
"time": 0
},{
"value": [1,1,1],
"time": 120
},{
"value": [1,1,1],
"time": 240
},{
"value": [1,1,1],
"time": 360
}],
"name": "CameraPreset.scale"
},{
"type": "quaternion",
"keys": [{
"value": [0,0.707107,0.707107,0],
"time": 0
},{
"value": [-0.612372,-0.353553,-0.353553,0.612372],
"time": 120
},{
"value": [-0.612372,0.353553,0.353553,0.612372],
"time": 240
},{
"value": [-0,0.707107,0.707107,0],
"time": 360
}],
"name": "CameraPreset.quaternion"
}],
"name": "default"
}],
"materials": [{
"uuid": "36DB0D58-F5EE-366F-9C7F-307076036ACA",
"side": 2,
"blending": "NormalBlending",
"name": "lambert1",
"specular": 1508356,
"shininess": 50,
"emissive": 0,
"ambient": 12531511,
"depthTest": true,
"color": 12531511,
"vertexColors": false,
"depthWrite": true,
"type": "MeshPhongMaterial"
}],
"images": [],
"metadata": {
"generator": "io_three",
"type": "Object",
"version": 4.4
}
This is where I loaded my Json model:
var mesheto;
var loader = new THREE.ObjectLoader();
loader.load(
'models/shirt.json',
function (object) {
globalObject = object;
object.name = 'shirt';
mesheto = object;
scene.add(object);
GameLoop();
}
);
This is the onclick function that changes the texture:
function loadimg(string) {
globalObject.traverse( function ( child ) {
console.log("clicked");
if (child instanceof THREE.Mesh) {
console.log(child instanceof THREE.Mesh);
child.material.map = THREE.TextureLoader('../img/models/check.jpg');
child.material.needsUpdate = true;
}
});
// polo_model.material.map = THREE.TextureLoader('models/check.jpg');
}
You have to add a .load to your new THREE.TextureLoader().load("name of your texture.jpg").

amCharts, adjusting yAxis limits using amCharts

I am trying to plot error bars using amCharts API. I am not able to set the yAxis limit as a result of which, my error bars are tiny compared to actual bars.
var valueAxis = new AmCharts.ValueAxis();
var chart = AmCharts.makeChart("chartdiv", {
"type": "serial",
"theme": "none",
"dataProvider": [{
"year": "C",
"value": 85.07 ,
"error": 0.57,
"lower": 84.50,
"upper": 85.64
}, {
"year": "V1",
"value": 84.67 ,
"error": 0.58,
"lower": 84.09,
"upper":85.25
}, {
"year": "V2",
"value": 86.76 ,
"error": 0.58,
"lower": 86.18,
"upper":87.34
}, {
"year": "V3",
"value": 84.55 ,
"error": 0.58,
"lower": 83.97,
"upper":85.13
}],
"balloon": {
"textAlign": "left"
},
"valueAxes": [{
"id":"v1",
"axisAlpha": 0
}],
"startDuration": 1,
"graphs": [{
"balloonText": "value:<b>[[value]]</b><br>error:<b>[[error]]</b><br>lower:<b>[[lower]]</b><br>upper:<b>[[upper]]</b>",
"labelText": "[[value]]",
"type": "column",
"bullet": "yError",
"bulletColor": "#000",
"errorField": "error",
"lineThickness": 2,
"valueField": "value",
"bulletAxis": "v1",
"fillAlphas": 1
}],
"chartCursor": {
"cursorAlpha": 0,
"cursorPosition": "mouse",
"graphBulletSize": 1,
"zoomable": false
},
"categoryField": "year",
"categoryAxis": {
"gridPosition": "start",
"axisAlpha": 0,
"min":60
},
"exportConfig": {
"menuTop":"20px",
"menuRight":"20px",
"menuItems": [{
"icon": 'http://www.amcharts.com/lib/3/images/export.png',
"format": 'png'
}]
}
});
Here is the jsFiddle
http://jsfiddle.net/amcharts/hD58C/utm_source=website&utm_medium=embed&utm_campaign=hD58C

How to implement drill down in Stacked Bar Chart(amchart)

We have implemented stacked bar chart using amchart. We have displaying the top 5 selling products in the charts.When drill down charts, the product manufactures details will display on the chart.
You can use chart's event clickGraphItem when the user clicks on a column. Then dynamically update chart's dataProvider property and call validateData() method to take in new data.
Here's a complete working demo. It has more stuff in it than just what I mentioned above, like for instance updating labels of current level being displayed, as well as back button to go up a level in drill-down.
var chartData = [{
"category": 2009,
"income": 23.5,
"url":"#",
"description":"click to drill-down",
"months": [
{ "category": 1, "income": 1 },
{ "category": 2, "income": 2 },
{ "category": 3, "income": 1 },
{ "category": 4, "income": 3 },
{ "category": 5, "income": 2.5 },
{ "category": 6, "income": 1.1 },
{ "category": 7, "income": 2.9 },
{ "category": 8, "income": 3.5 },
{ "category": 9, "income": 3.1 },
{ "category": 10, "income": 1.1 },
{ "category": 11, "income": 1 },
{ "category": 12, "income": 3 }
]
}, {
"category": 2010,
"income": 26.2,
"url":"#",
"description":"click to drill-down",
"months": [
{ "category": 1, "income": 4 },
{ "category": 2, "income": 3 },
{ "category": 3, "income": 1 },
{ "category": 4, "income": 4 },
{ "category": 5, "income": 2 },
{ "category": 6, "income": 1 },
{ "category": 7, "income": 2 },
{ "category": 8, "income": 2 },
{ "category": 9, "income": 3 },
{ "category": 10, "income": 1 },
{ "category": 11, "income": 1 },
{ "category": 12, "income": 3 }
]
}, {
"category": 2011,
"income": 30.1,
"url":"#",
"description":"click to drill-down",
"months": [
{ "category": 1, "income": 2 },
{ "category": 2, "income": 3 },
{ "category": 3, "income": 1 },
{ "category": 4, "income": 5 },
{ "category": 5, "income": 2 },
{ "category": 6, "income": 1 },
{ "category": 7, "income": 2 },
{ "category": 8, "income": 2.5 },
{ "category": 9, "income": 3.1 },
{ "category": 10, "income": 1.1 },
{ "category": 11, "income": 1 },
{ "category": 12, "income": 3 }
]
}];
var chart = AmCharts.makeChart("chartdiv", {
"type": "serial",
"theme": "none",
"pathToImages": "/lib/3/images/",
"autoMargins": false,
"marginLeft": 30,
"marginRight": 8,
"marginTop": 10,
"marginBottom": 26,
"titles": [{
"text": "Yearly data"
}],
"dataProvider": chartData,
"startDuration": 1,
"graphs": [{
"alphaField": "alpha",
"balloonText": "<span style='font-size:13px;'>[[title]] in [[category]]:<b>[[value]]</b> [[additional]]</span> <br>[[description]]",
"dashLengthField": "dashLengthColumn",
"fillAlphas": 1,
"title": "Income",
"type": "column",
"valueField": "income","urlField":"url"
}],
"categoryField": "category",
"categoryAxis": {
"gridPosition": "start",
"axisAlpha": 0,
"tickLength": 0
}
});
chart.addListener("clickGraphItem", function (event) {
if ( 'object' === typeof event.item.dataContext.months ) {
// set the monthly data for the clicked month
event.chart.dataProvider = event.item.dataContext.months;
// update the chart title
event.chart.titles[0].text = event.item.dataContext.category + ' monthly data';
// let's add a label to go back to yearly data
event.chart.addLabel(
"!10", 25,
"Go back to yearly >",
"right",
undefined,
undefined,
undefined,
undefined,
true,
'javascript:resetChart();');
// validate the new data and make the chart animate again
event.chart.validateData();
event.chart.animateAgain();
}
});
// function which resets the chart back to yearly data
function resetChart() {
chart.dataProvider = chartData;
chart.titles[0].text = 'Yearly data';
// remove the "Go back" label
chart.allLabels = [];
chart.validateData();
chart.animateAgain();
}
#chartdiv {
width : 100%;
height : 300px;
}
<script type="text/javascript" src="https://www.amcharts.com/lib/3/amcharts.js"></script>
<script type="text/javascript" src="https://www.amcharts.com/lib/3/serial.js"></script>
<div id="chartdiv"></div>

Why thekendo column chart on x-axis values are getting displayed not in order

JS Bin
<div id="example" class="k-content">
<div class="chart-wrapper">
<div id="chart"></div>
</div>
<script>
var internetUsers = [ {
"Month": "1",
"year": "2010",
"value": 1
}, {
"Month": "2",
"year": "2010",
"value": 2
}, {
"Month": "3",
"year": "2010",
"value": 3
}, {
"Month": "4",
"year": "2010",
"value": 4
}, {
"Month": "5",
"year": "2010",
"value": 5
},
{
"Month": "6",
"year": "2010",
"value": 6
}, {
"Month": "7",
"year": "2010",
"value": 7
}, {
"Month": "8",
"year": "2010",
"value": 8
},
{
"Month": "9",
"year": "2010",
"value": 9
}, {
"Month": "10",
"year": "2010",
"value": 10
}, {
"Month": "11",
"year": "2010",
"value": 11
},
{
"Month": "12",
"year": "2010",
"value": 17117.00
},
{
"Month": "1",
"year": "2011",
"value": 12
}, {
"Month": "2",
"year": "2011",
"value": 13
}, {
"Month": "3",
"year": "2011",
"value": 4
}, {
"Month": "4",
"year": "2011",
"value": 6
}, {
"Month": "5",
"year": "2011",
"value": 24
},
{
"Month": "6",
"year": "2011",
"value": 3
}, {
"Month": "7",
"year": "2011",
"value": 35
}, {
"Month": "8",
"year": "2011",
"value": 34
},
{
"Month": "9",
"year": "2011",
"value": 22
}, {
"Month": "10",
"year": "2011",
"value": 21
}, {
"Month": "11",
"year": "2011",
"value": 215
},
{
"Month": "12",
"year": "2011",
"value": 12
}];
function createChart() {
$("#chart").kendoChart({
theme: $(document).data("kendoSkin") || "default",
dataSource: {
data: internetUsers,
group: {
field: "year"
},
sort: {
field: "year",
dir: "asc"
}
},
title: {
text: "Sales"
},
legend: {
position: "bottom"
},
seriesDefaults: {
type: "column"
},
series: [{
field: "value"
}],
valueAxis: {
labels: {
format: "{0}$"
},
line: {
visible: false
},
axisCrossingValue: 0
},
categoryAxis: {
field: "Month"
},
tooltip: {
visible: true,
format: "{0}%",
template: "#= series.name #: #= value #"
}
});
}
$(document).ready(function() {
setTimeout(function() {
// Initialize the chart with a delay to make sure
// the initial animation is visible
createChart();
$("#example").bind("kendo:skinChange", function(e) {
createChart();
});
}, 400);
});
</script>
</div>
http://jsbin.com/oxakup/17/edit
You need to sort your dataSource by month instead of year like the following:
sort: { field: "Month", dir: "asc" }
Now your months are sorting correctly based off your values, although the month data types are string instead of number, hence the reason this will now sort by 1, 10, 11, 12, 2, 3 etc..
You can work around this by fixing it in your JSON data source, but if you're unable to change that, you can use the following to format the data in the dataSource before processing:
schema: {
data: function(response) {
for (var i = 0; i < response.length; i++) {
response[i].Month = new Number(response[i].Month);
}
return response;
}
}

How Do You Get Tooltips in Open Flash Charts When Writing JSON?

I am trying to display a chart with tool tips but I cannot seem to figure out how you put in tool tips when you write your own JSON for the chart.
Is this possible?
Here is the JSON I have written so far:
var days_of_week_chart = {
"elements": [
{
"type": "bar",
"values": [33,0,0,0,0,0,0,],
}
],
"title": {
"text": "Visitors By Day of Week"
},
"x_axis":{
"stroke":1,
"tick_height":10,
"colour":"#d000d0",
"grid_colour":"#00ff00",
"labels": {
"labels": ["Saturday","Sunday","Monday","Tuesday","Wednesday","Thursday","Friday",]
}
},
"y_axis": {
"stroke": 4,
"steps": 5,
"tick_length": 5,
"colour": "#d000d0",
"grid_colour": "#00ff00",
"offset": 0,
"max": 33 }
};
You need to have the tooltip element, and tip element in the data series:
{ "elements": [ { "type": "hbar", "values": [ { "right": 4 }, { "right": 8 }, { "right": 3 }, { "right": 4 }, { "right": 7 }, { "right": 8 } ], "colour": "#86BBEF", "tip": "Months: #val#" } ], "title": { "text": "Total hours on project mayhem" }, "x_axis": { "offset": false, "min": 0, "max": 10 }, "y_axis": { "offset": 1, "labels": [ "Jeff", "Geoff", "Bob", "Terry", "Duncan", "monk.e.boy" ] }, "tooltip": { "mouse": 2, "stroke": 1, "colour": "#000000", "background": "#ffffff" } }

Resources