I've written a custom HTMLHelper that outputs some javascript. The javascript is being added to the page but it's not being run when the page loads. If I copy / paste the generated JS into the console window of Chrome, the script works perfectly. Is what I am wanting to do possible?
public static HtmlString CreatePieChart(this HtmlHelper helper, string divId, int width, Collection<PieChartSeriesItem> series)
{
if (width < 1)
{
throw new System.ArgumentException("Width of pie chart must be greater than zero");
}
StringBuilder htmlString = new StringBuilder();
htmlString.Append("<script type=\"type/javascript\">");
htmlString.Append("$(window).load(\"#");
htmlString.Append(divId);
htmlString.Append("\").kendoChart({");
htmlString.Append("title: { visible: false },");
htmlString.Append("chartArea: { background: \"transparent\", width: ");
htmlString.Append(width.ToString(CultureInfo.InvariantCulture));
htmlString.Append(" },");
htmlString.Append("legend: { visible: false },");
htmlString.Append("seriesDefaults: { labels: { visible: false } },");
htmlString.Append("series: [{");
htmlString.Append("type: \"pie\",");
htmlString.Append("padding: 0,");
htmlString.Append("overlay: { gradient: \"none\"},");
htmlString.Append("data: [");
htmlString.Append(CreatePieChartDataSeriesString(series));
htmlString.Append("]");
htmlString.Append("}],");
htmlString.Append("tooltip: { visible: true, template: \"#= category # (#= value #%)\"}");
htmlString.Append("});");
htmlString.Append("</script>");
return new HtmlString(htmlString.ToString());
}
and here's the call in the page
<div id="piechart">
@Html.Partial("_PieChart", Model.BalancePieChartData)
</div>
console.log("Test #n")and look if thats being executed