如何从sql数据中获得多系列highstock图表

时间:2013-05-16 22:05:56

标签: c# asp.net-mvc highstock

目前我有这段代码:

<script type="text/javascript" src="/Scripts/highstock.js"></script>
<script type="text/javascript">
$(document).ready(function() {
    var yAxisOptions = [],
    seriesOptions = []; 
    @{
        var measureType = Model.sensorMeasurements.Values.First();
        int i = 0;
        foreach (System.Reflection.PropertyInfo propertyInfo in measureType.GetType().GetProperties())
        {
            if (propertyInfo.Name == "ID" || propertyInfo.Name == "sensorID" || propertyInfo.Name == "timemark")
            {
                continue;
            }

            @: seriesOptions[@i] = { marker: { states: { hover: { enabled: false},},}, data: [

            bool firstData = true;

            foreach (ManualSensors.Models.ManualMeasurement x in Model.sensorMeasurements.Values)
            {
                System.Reflection.PropertyInfo pData = x.GetType().GetProperty(propertyInfo.Name);
                System.Reflection.PropertyInfo pDate = x.GetType().GetProperty("timemark");

                var m_data = pData.GetValue(x, null);
                DateTime m_date = (DateTime)pDate.GetValue(x, null);

                if (m_data.ToString() == "")
                {
                    continue;
                }

                if (firstData)
                {
                    firstData = false;

                    @:[Date.parse('@m_date.ToString("MM/dd/yyyy HH:mm:ss")'), @m_data.ToString()]
                }
                else
                {
                    @:,[Date.parse('@m_date.ToString("MM/dd/yyyy HH:mm:ss")'), @m_data.ToString()]
                } 
            }
            @:  ], name: '@propertyInfo.Name',  type: 'line', };
            i++;
        }

    }   
    createChart();
    // create the chart when all data is loaded
    function createChart() {
    chart = new Highcharts.StockChart({
    chart: {
    renderTo: 'container',
    borderWidth: 0.5,
    marginTop: 0,
    marginBottom: 30,
    zoomType: 'x',
    },
    scrollbar : {
        enabled : false
    },
    rangeSelector: {
        enabled : false
    },
    navigator: {
        enabled: false
    },
    tooltip: {
        enabled: false
    },
    series: seriesOptions
    });
    }
});
        </script>
        <div id="container">
        </div>

这是一个mvc视图,我将这个系列作为数组中的元素逐个构建, 我很确定这个系列很好,但它正在崩溃

chart = new Highcharts.StockChart({

在createChart()函数中,说图表没有被反抗...有人可以帮我实现我想要的,创建简单的stockChart并使用这里显示的数据吗? 感谢

0 个答案:

没有答案