循环遍历数组图表数据值,并将highchart追加到在C#中创建的每个div

时间:2019-02-22 10:41:20

标签: javascript c# highcharts

我有一个数组,用于保存javascript highchart函数的图表数据。当前,它正在将数组中第一个值的图表绘制到要创建的第一个div上。我需要它遍历数组中的每个值并将此值解析为javascript函数,以便为每个数组索引创建一个新图表。我在每个div中都使用了一个.boxplot类来渲染高图。

我要去哪里错了?

    private void ConstructBoxPlot()
{
    int i = 0;

        // We create our new div
        System.Web.UI.HtmlControls.HtmlGenericControl newDiv = new System.Web.UI.HtmlControls.HtmlGenericControl("DIV");
        newDiv.ID = "Chart" + i; //<---Give and ID to the div, very important!
        newDiv.Attributes.Add("class", "pagebr"); //<---Apply a css class if wanted
        newDiv.Attributes.Add("class", "boxplot"); //<---Apply a css class if wanted
        div2.Controls.Add(newDiv); //<---Add the new div to our already existing div

        string measuredesc = measureList[i];
        string chartdatadesc = chartdataList[i];


        string[] strList = chartdatadesc.Split(',');

        // convert it in json
        dataStr = JsonConvert.SerializeObject(strList, Formatting.None);


        hiddenvariable.Value = dataStr;
        hiddenvariablemeasuredesc.Value = measuredesc;
        //hiddenvariabletarget.Value = lblTarget.Text;

        Page.ClientScript.RegisterStartupScript(this.GetType(), "MyFunc", "CreateBoxPlot(" + i + ");", true);

}

JavaScript代码:

function CreateBoxPlot() {

    var hv = $('#hiddenvariable').val();
    console.log(hv);
    var hvmeasure = $('#hiddenvariablemeasuredesc').val();
    console.log(hvmeasure);
    var hvtarget = $('#hiddenvariabletarget').val();

    var chart;
    var titleText = hvmeasure;
    //var subTitleText = 'Test Chart Subtitle';
    var type = 'boxplot';
    var data = [JSON.parse(hv).map(item => parseInt(item))]; //Doesnt work in IE




    $(function () {
        $('.boxplot').highcharts({
            chart: { type: type, inverted: true},
    ....
                    plotLines: [{
                    value: hvtarget,
                    color: 'red',
                    width: 2

                }]

            }
        });

        chart = $('.boxplot').highcharts();
        chart.addSeries({ data: data });


    });
}

0 个答案:

没有答案