Kendo chart in kendo grid - kendo-ui

I have a problem, I need to set kendo pie chart in Kendo grid with Asp.net mvc.
I have a grid that i want to set a pie chart in one of columns in client template.
Can i do it?If Yes How?
Tnx

Please refer the below forum on telerik in which a jsfiddle sample is provided for what you are looking for
Telerik Forum Link
Sample JS Fiddle

Try with like this
#(Html.Kendo().Grid<Model>()
.Name("grid")
.DataSource(dataSource => dataSource
.Ajax()
.ServerOperation(true)
.Model(model => model.Id(p => p.ID))
.Read(read => read.Action("method", "controller"))
)
.Pageable()
.Sortable()
.Scrollable()
.Events(e => e.DataBound("dataBound"))
.Filterable(ftb => ftb.Mode(GridFilterMode.Row))
.Columns(columns =>
{
columns.Bound(p => p.ID).ClientTemplate("<div class='chart'></div>");
})
)
and script is
function dataBound() {
var grid = this;
grid.tbody.find("tr[role='row']").each(function () {
var model = grid.dataItem(this);
$(this).find(".chart").kendoChart({
title: {
text: "Olympic Medals won by USA"
},
legend: {
visible: false
},
seriesDefaults: {
type: "bar",
stack: {
type: "100%"
}
},
series: [{
name: "Gold Medals",
data: [40, 32, 34, 36, 45, 33, 34, 83, 36, 37, 44, 37, 35, 36, 46],
color: "#f3ac32"
}, {
name: "Silver Medals",
data: [19, 25, 21, 26, 28, 31, 35, 60, 31, 34, 32, 24, 40, 38, 29],
color: "#b8b8b8"
}, {
name: "Bronze Medals",
data: [17, 17, 16, 28, 34, 30, 25, 30, 27, 37, 25, 33, 26, 36, 29],
color: "#bb6e36"
}],
valueAxis: {
line: {
visible: false
},
minorGridLines: {
visible: true
}
},
categoryAxis: {
categories: [1952, 1956, 1960, 1964, 1968, 1972, 1976, 1984, 1988, 1992, 1996, 2000, 2004, 2008, 2012],
majorGridLines: {
visible: false
}
},
tooltip: {
visible: true,
template: "#= series.name #: #= value #"
}
});
});
}

I had a special requirement. To make a single horizontal column inside a table. I thought that having a chart per table would be overkill so I customised the grid component. Basing it on a simple Html table styling it with some CSS and using KendoUI to make it into a grid.
This might be helpful if you want something very specific.
Visual example:
Here's a working example:
http://embed.plnkr.co/Hy2u4d/

Related

KTDatatables want to change page length options

I am using keentheme's Metronic admin template. It has KTDatatables. I can see page length options now as:
5, 10, 30, 50, 100
I want to change it to, to show all records:
5, 10, 30, 50, 100, All
My datatable code:
var datatable = $("#attendance_datatable").KTDatatable({
data: {
type: "remote",
source: baseUrl + "/Hrms/AttendanceManagement/getEmployeesAttendance/",
pageSize: 10,
},
layout: {
scroll: true,
footer: false,
},
sortable: true,
pagination: true,
lengthMenu: [
[10, 25, 50, -1],
[10, 25, 50, "All"],
],
search: {
input: $("#attendance_datatable_search_query"),
key: "generalSearch",
},
columns: [
{
field: "emp_name",
title: "Employee Name",
width: 120,
},
{
field: "attendance_date",
title: "Date",
width: 85,
},
],
});
};
I have tried following:
https://datatables.net/examples/advanced_init/length_menu.html
Change lengthMenu option
lengthMenu: [
[5, 10, 30, 50, 100, -1],
[5, 10, 30, 50, 100, "All"],
],
This should work
I edited as below and it worked code.
You changes "lengthMenu" -> toolbar needs to be added, changes it as follows to chage the pagination.
toolbar: {
// toolbar placement can be at top or bottom or both top and bottom repeated
placement: ['bottom'],
// toolbar items
items: {
// pagination
pagination: {
// page size select
pageSizeSelect: [5, 10, 20, 30, 50, 999], // display dropdown to select pagination size. -1 is used for "ALl" option
},
}
}

How to remove transparency from bar charts?

I wonder if there's any way to remove opacity from bar charts built with Chartkick in combination with ChartJS? They always appear semi-transparent, no matter what I do.
This is what I've got so far:
<%=
column_chart(
[
{:data => #invoices},
{:data => #payments}
],
:id => "chart",
:stacked => true,
:colors => ["#E91E63", "#003366"],
:legend => false,
:dataset => {:borderWidth => 0}
)
%>
Thanks for any help.
For two different color with two data-set for proper data comparison Check code snippet
//START Common for all chart
var legend = {
display: true,
position: 'bottom',
labels: {
fontColor: '#000'
}
};
//END Common for all chart
//Dataset
var data1 = {
label: 'Dataset 1',
data: [4, 6, 3, 5, 2, 3],
backgroundColor: 'rgba(255, 99, 132, 1)', //Set 1 for remove transparency
borderColor: 'rgba(255, 99, 132, 1)',
borderWidth: 1
};
var data2 = {
label: 'Dataset 2',
data: [5, 2, 3, 4, 6, 3],
backgroundColor: 'rgba(54, 162, 235, 1)', //Set 1 for remove transparency
borderColor: 'rgba(54, 162, 235, 1)',
borderWidth: 1
};
var Dataset = [data1, data2]
// Dataset
//START Bar chart
var option = {
scales: {
yAxes: [{
gridLines: {
offsetGridLines: true
},
categorySpacing: 5,
ticks: {
beginAtZero: true
}
}]
},
responsive: true,
//maintainAspectRatio: false,
legend: legend,
//onClick: LoadDataInDetails
}
var ctx = document.getElementById('myChart').getContext('2d');
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
datasets: Dataset
},
options: option
});
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<canvas id="myChart"></canvas>
OK, it seems that only RGB colours can be passed into column_chart() (correct me if I'm wrong). This is what I ended up with:
<%=
column_chart(
[
{:data => #invoices},
{:data => #payments}
],
:id => "chart",
:stacked => true,
:colors => [to_rgba("#E91E63"), to_rgba("#003366")],
:legend => false,
:dataset => {:borderWidth => 0}
)
%>
module ColorHelper
def to_rgba(hex_value)
opacity = 1
hex_value = hex_value.gsub('#', '')
rgb_values = hex_value.scan(/../).map{ |x| x.hex }
rgb_values << opacity
"rgba(#{rgb_values.join(',')})"
end
end
Not perfect, but it gets the job done.

Stacked bar chart bars dimension is not coralated to Y axis

I am trying to build a stacked bar chart using c3.js.
The issue I have is that the bars that get generated are not coralated to the Y axis.
This is what I have so far: https://codepen.io/anon/pen/dZLMoY?editors=1010
And this is the code:
c3.generate({
bindto:'#chart',
data: {
type: 'bar',
columns: [
['Column 1', 2, 10, 22, 34, 9, 60],
['Column 2', 6, 15, 43, 36, 45, 75],
['Column 3', 10, 20, 79, 39, 50, 97],
['Column 4', 12, 27, 87, 76, 55, 150]
],
groups: [
['Column 1', 'Column 2', 'Column 3', 'Column 4']
],
},
bar: {
width: 15,
},
axis: {
x: {
show: true
},
y: {
show: true,
padding: {
top: 0,
bottom: 0
},
tick: {
//count: 6
},
min: 0,
max: 150
}
},
grid: {
x: {
show: true
},
y: {
show: true
}
}
});
As you can see the bar chart is generated but it is not generated correctly. The last 4 bars are all equal even if the values that are provided are not.
Taking into consideration that the Y axis has the maximum value set to 150 then the 2nd, 3rd and 4th bars should not ocupy the same height as the 5th bar
What am I doing wrong?
Your axis.y.max value is less than stacked sum, so chart is clipped at the top.
Try this:
c3.generate({
...
axis: {
...
y: {
...
min: 0,
max: 500
}
}
}
Or see it in action.

kendo chart categoryAxis

I`m beginner using kendo stacked chart.
this is my categoryAxis.
categoryAxis: {
categories: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23],
majorGridLines: {
visible: true
},
visible: true
},
chartArea: {
height : 200
},
tooltip: {
visible: true,
format: "{0}",
template: "#= series.name #: #= value #",
color: "white"
}
but, 0 index tooltip shows 'd'.
what is the problem ?
tooltip image
From your image you are using a shared tooltip, so try defining your tooltip like this:
tooltip: {
visible: true,
sharedTemplate: "<div>#: category #</div> # for (var i = 0; i < points.length; i++) { # <div>#: points[i].series.name# : #: points[i].value #</div> # } #",
color: "white",
shared: true
}

HighCharts graphs are not showing in IE

For me Highcharts graphs are not showing in Internet Explorer. I searched and saw that extra comma might be a problem but I don't find extra comma in my script.
Following fiddle showing highcharts initialization part only.
var chart = new Highcharts.Chart({
chart: {
renderTo: 'container'
},
credits: {
text: 'Reference: WHO Child Growth Standards (Birth-2 years in percentiles).'
},
xAxis: {
categories: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24],
gridLineWidth: 1,
gridLineColor: 'lightgray',
gridLineDashStyle: 'longdash',
title: {
text: 'Age (Completed months and years)'
}
},
yAxis: {
gridLineWidth: 1,
gridLineColor: 'lightgray',
gridLineDashStyle: 'longdash',
title: {
text: 'Length (cm)'
},
tickInterval: 5,
allowDecimals: false,
min: 45,
max: 95
},
plotOptions: {
spline: {
marker: {
radius: 0,
lineColor: '#666666',
lineWidth: 1
}
}
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
borderWidth: 0,
reversed: true,
y: 30,
width: 200,
itemMarginTop: 6,
itemMarginBottom: 6
},
exporting: {`enter code here`
enabled: false
}
});
http://jsfiddle.net/aparnaunny/RzyY8/
The problem I found is the version of jQuery, which for some reason makes errors on INternet Explorer.
Try an older version, e.g. jQuery 1.9.1
For me that worked
http://jsfiddle.net/RzyY8/2/
jQuery 1.9.1
In gerenal you should run jsfiddle.net/aparnaunny/RzyY8/1/show because fiddles are not supported by ie8. Secondly run your console in the ie8, and you will see that the prbolem is in the line 361.
if(age==2.0)
{
$("#median").append('Median height for this age is 87.1161 cm');
ind=malearr24.indexOf(height);
if(ind=='-1')
{

Resources