Example #1
0
        public string ToHtmlString()
        {
            StringBuilder scripts = new StringBuilder();
            _Highstock.ForEach(x => scripts.AppendLine("<div id='{0}'></div>".FormatWith(x.ContainerName)));

            List<Highstock> startupCharts = _Highstock.Where(x => String.IsNullOrEmpty(x.FunctionName)).ToList();
            scripts.AppendLine("<script type='text/javascript'>");
            startupCharts.ForEach(x => scripts.AppendLine("var {0};".FormatWith(x.Name)));
            scripts.AppendLine("$(document).ready(function() {");
            startupCharts.ForEach(scripts.AppendHighstock);
            scripts.AppendLine("});");

            List<Highstock> functionCharts = _Highstock.Where(x => !String.IsNullOrEmpty(x.FunctionName)).ToList();
            foreach (Highstock chart in functionCharts)
            {
                scripts.AppendLine("var {0};".FormatWith(chart.Name));
                scripts.AppendLine(String.Format("function {0}() {{", chart.FunctionName));
                scripts.AppendHighstock(chart);
                scripts.AppendLine("}");
            }
            scripts.AppendLine("</script>");

            return scripts.ToString();
        }
Example #2
0
        /// <summary>
        /// Returns JavaScript code for the chart in an HTML-encoded String.
        /// </summary>
        /// <returns></returns>
        public HtmlString ChartScriptHtmlString()
        {
            StringBuilder scripts = new StringBuilder();

            scripts.AppendLine("<script type='text/javascript'>");
            if (Options != null)
                scripts.AppendLine("Highcharts.setOptions({0});".FormatWith(JsonSerializer.Serialize(Options)));

            scripts.AppendLine("var {0};".FormatWith(Name));
            scripts.AppendLine(!String.IsNullOrEmpty(FunctionName) ? String.Format("function {0}() {{", FunctionName) : "$(document).ready(function() {");
            scripts.AppendHighstock(this);
            scripts.AppendLine(!String.IsNullOrEmpty(FunctionName) ? "}" : "});");

            scripts.AppendLine("</script>");

            return new HtmlString(scripts.ToString());
        }