I don,t know why I always have the weirdest problems. I am using Kendo UI Charting. which is in a PartialView. When the PartialView is called by jQuery, it generates div and some jQuery code at runtime. I append the whole div and JQ code below the clicked row of the table row. The problem is this, that it only appends div, it ignores script tag and its code, which is neccessary for rendering chart.
My PartialView is:
@(Html.Kendo().Chart()
.Name("XXXProducts")
.Title("XXX Products")
.Legend(legend => legend
.Visible(false)
)
.ChartArea(chartArea => chartArea
.Background("transparent")
)
.Series(series =>
{
series.Bar(Model.SalesAxis).Name("Total Sales");
})
.CategoryAxis(axis => axis
.Categories(Model.MonthsAxis)
.MajorGridLines(lines => lines.Visible(false))
)
.ValueAxis(axis => axis
.Numeric()
.Max(Model.SalesAxis.Max() + 100)
.Line(line => line.Visible(false))
.MajorGridLines(lines => lines.Visible(true))
)
.Tooltip(tooltip => tooltip
.Visible(true)
.Template("#= series.name #: #= value #")
)
)
My jQuery Code on other page to render the view:
function RenderChart(row) {
var rowIndex = $("#tblDetail").find($(row)).index() + 1;
var chartData = '';
$.get('@Url.Action("MonthlyChart", "Chart")', function (data) {
chartData = "<tr style='height:300px;'><td colspan='5'>" + data + "</td></tr>";
$('#tblDetail tr:nth-child(' + rowIndex + ')').after(chartData);
});
}
When I alert "chartData", it shows the following:
<tr><td colspan='5'><div class="k-chart" id="XXXProducts"></div><script> jQuery(function(){jQuery("#XXXWaterProducts").kendoChart({"chartArea":{"background":"transparent"},"title":{"text":"Site Visitors Stats /thousands/"},"legend":{"visible":false},"series":[{"name":"Total Sales","type":"bar","data":[56000,74500,45000,86000,49850,63482,97600,63250,79860,42100,32010,89200]}],"categoryAxis":[{"majorGridLines":{"visible":false},"categories":["January","February","March","April","May","June","July","August","September","October","November","December"]}],"valueAxis":[{"majorGridLines":{"visible":true},"line":{"visible":false},"max":97700}],"tooltip":{"template":"#= series.name #: #= value #","visible":true}});});</script> </td></tr>
But when I check the source it only shows:
<tr><td colspan='5'> <div class="k-chart" id="XXXProducts"></div></td></tr>
The scripts tag is nowhere to be found.