MVC应用中的.net highcharts:显示唯一的值,但必须有很多

dotnet highcharts in MVC app: displays the only value, but must many

本文关键字:唯一 应用 net highcharts 显示 MVC      更新时间:2023-09-26

尝试在MVC-app中显示特定时期的汇率,但总是只得到一个汇率值。然而,调试器表示所有值都正确地从数据源获得。想想看,javascript方面有问题。这是我的控制器的动作代码:

IList dataSource = _dataProvider。SelectRatesByDateRange (curCountrycrange。BeginDate crange.EndDate) .ToList ();

            string[] dates = dataSource.Select(c => c.Date.ToShortDateString()).ToArray();
            decimal[] values = dataSource.Select(c => c.Value).ToArray();

            var chart = new Highcharts("Charts");
            chart.InitChart(new Chart {DefaultSeriesType = ChartTypes.Areaspline})
                .SetTitle(new Title {Text = "Currency rates at specified period."})
                .SetSubtitle(new Subtitle {Text = crange.SelectedCurrencySymbol})
                .SetXAxis(new XAxis {Categories = dates, Title = new XAxisTitle {Text = "Dates"}})
                .SetYAxis(new YAxis {Title = new YAxisTitle {Text = "Currencies rates"}})
                .SetPlotOptions(new PlotOptions
                {
                    Line = new PlotOptionsLine
                    {
                        DataLabels = new PlotOptionsLineDataLabels {Enabled = true},
                        EnableMouseTracking = false
                    }
                })
                .SetSeries(new Series {Color = Color.Green, Data = new Data(new object[]{values})});
             crange.Chart  = chart;
             return View("ChartingPage", crange);

生成的js代码:(对于欧元/美元)

<script type='text/javascript'>
var Charts;
$(document).ready(function() {
    Charts = new Highcharts.Chart({
        chart: { renderTo:'Charts_container', defaultSeriesType: 'areaspline' }, 
        plotOptions: { line: { dataLabels: { enabled: true }, enableMouseTracking: false } }, 
        subtitle: { text: 'EUR' }, 
        title: { text: 'Currency rates at specified period.' }, 
        xAxis: { categories: ['12.03.2014', '13.03.2014', '14.03.2014', '15.03.2014', '16.03.2014', '17.03.2014', '18.03.2014', '19.03.2014', '20.03.2014', '21.03.2014', '22.03.2014'], title: { text: 'Dates' } }, 
        yAxis: { title: { text: 'Currencies rates' } }, 
        series: [{ data: [[0.72, 0.72, 0.72, 0.72, 0.72, 0.72, 0.72, 0.72, 0.73, 0.72, 0.72]], color: 'green' }]
    });
});

也chrome控制台说:Uncaught TypeError:不能设置属性'不显眼'的未定义。这是否与图形渲染问题有关?所有的想法都将非常感激。提前谢谢。

关于JS Uncaught TypeError: got rid of it -答案在这里(第一个答案)。

得到答案:需要显式创建对象数组,手动复制values集合中的所有值到它,并将该数组传递给Data of chart