如何访问Jquery库中的特定属性?

时间:2014-06-19 09:01:25

标签: javascript jquery ajax

伙计我在Jquery自定义库中编写了以下代码,用于在我的ASP.net MVC应用程序中绘制图表。现在我想使用ajax调用更改其中的特定值。请看一下我的代码:

来自Jquery自定义lib:

 $('#performance-cart').highcharts({
        chart: {
            type: 'area', backgroundColor: '#f5f7f7', style: { fontFamily: 'Roboto, Sans-serif', color: '#aeafb1' },
            animation: {
                duration: 1500,
                easing: 'easeOutBounce'
            }
        },
        xAxis: {
            type: 'datetime',
            labels: { style: { color: '#aeafb1' } }
        },
        yAxis: {
            min: 0, max: 50, tickInterval: 10, gridLineColor: '#ebeded', gridLineWidth: 1,
            title: { text: '' }, lineWidth: 0, labels: { align: 'right', style: { color: '#aeafb1' } }
        },
        title: { text: '' },
        tooltip: {
            useHTML: true, headerFormat: '<h3 style="color:#ffffff;font-weight:300;padding: 3px 12px;">{point.y:,.1f}</br>',
            backgroundColor: '#515757', pointFormat: 'Issues</h3>'//$('#performanceColumnChart').data('tooltip')
        },
        legend: {
            itemStyle: { color: '#838589' }, symbolWidth: 12, symbolHeight: 5, itemWidth: 80, symbolRadius: 0,
            itemMarginBottom: 10, backgroundColor: '#f5f7f7', verticalAlign: 'top', borderWidth: 0, x: -498, y: 10
        },
        plotOptions: {
            area: {
                fillOpacity: 0.2, cursor: 'pointer', marker: {
                    symbol: 'circle', fillColor: '#FFFFFF', lineWidth: 2, lineColor: null,
                    allowPointSelect: true
                }
            },
            line: {
                fillOpacity: 0.2, cursor: 'pointer', marker: {
                    symbol: 'circle', fillColor: '#FFFFFF', lineWidth: 2, lineColor: null,
                    allowPointSelect: true
                }
            },
            column: {
                fillOpacity: 0.2, cursor: 'pointer', marker: {
                    symbol: 'circle', fillColor: '#FFFFFF', lineWidth: 2, lineColor: null,
                    allowPointSelect: true
                }
            },
            series: {
                pointStart: myIssueResolvedStartDate,
                pointInterval: 24 * 3600 * 1000 // one day
            }
        },
        series: [{
            name: 'Issues', color: '#ff3806',
            data: myIssueData,
            marker: { states: { hover: { fillColor: '#ff3806', lineColor: '#ffffff', lineWidth: 2 } } }
        }, {
            name: 'Resolved', color: '#1da9dd',
            data: myResolvedData,
            marker: { states: { hover: { fillColor: '#1da9dd', lineColor: '#ffffff', lineWidth: 2 } } }
        }]
    });

我的Ajax电话:

$.ajax(
    {
        type: "GET",
        url: WebApiURL + "/api/home/GetQueryIssueResolvedData?deptCode=" + departCode,
        dataType: "json",
        crossDomain: true,
        async: true,
        cache: false,
        success: function (myData) {
            var chart = $('#performance-cart').highcharts();
            var ResolvedStartDate = myData.data.IssueResolvedStartDate;
            var issueData = myData.data.IssueData;
            var resolveData = myData.data.ResolvedData;

            //chart.plotOptions.series.setpointStart(ResolvedStartDate, true);
            chart.series[1].setData(issueData, true);
            chart.series[0].setData(resolveData, true);
        },
        error: function (x, e) {
            alert('There seems to be some problem while fetching records!');
        }

    }
);

现在我想通过ajax调用替换jquery库的pointStart元素中的日期值,但我不知道如何访问该属性。

我尝试使用chart.plotOptions.series.setpointStart(ResolvedStartDate, true);但是它说plotOptions未定义。如何从pointStart获取ResolvedStartDate日期值?

2 个答案:

答案 0 :(得分:4)

您可以尝试使用各个系列的新选项更新系列 - 请参阅http://api.highcharts.com/highcharts#Series.update

答案 1 :(得分:0)

我只需要这个简单的一行代码

chart.options.plotOptions.series.pointStart = newDate

其中newDate是UTC格式的新日期的变量。