简体   繁体   English

在高图中显示.Net核心Web API响应

[英]show .Net core web API response in highcharts

I want to show data in highcharts, API returns json, is any conversion needed to highcharts show data? 我想在highcharts中显示数据,API返回json,对highcharts显示数据需要进行任何转换吗?

code: 码:

[HttpGet("{id}")]
public ActionResult<List<Tuple<string, double>>> Get(int id)
{
        using (StockContext stockContext = new StockContext())
        {
            var company = stockContext
                .Companies
                .Where(x => x.Id == id)
                .FirstOrDefault();

            var info = company
                .Informations
                .ToList()
                .Select(x => new Tuple<string, double>(((long)x.Date.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds).ToString(), x.Close)), x.Close))
                .ToList();
            return new ObjectResult(info);
        }
}

sample data: 样本数据:

[{"item1":"1548201600000","item2":2470.0}, [{“ item1”:“ 1548201600000”,“ item2”:2470.0},

{"item1":"1548115200000","item2":2469.0}, {“ item1”:“ 1548115200000”,“ item2”:2469.0},

{"item1":"1548028800000","item2":2440.0}] {“ item1”:“ 1548028800000”,“ item2”:2440.0}]

client-side: 客户端:

fetch(url)
        .then(res => res.json())
        .then(json => {
            this.setState({
                data: json, // data passed to highcharts but doesn't show anything
            });
        });

Depending on what Highcharts series you want to use, you must provide data in one of three allowed formats: 根据要使用的Highcharts系列,必须以三种允许的格式之一提供数据:

Array - only y - values: 数组-仅y值:

data: [0, 5, 3, 5]

Array - x and y values: 数组xy值:

data: [
    [0, 1],
    [1, 2],
    [2, 8]
]

Object: 宾语:

data: [{
    x: 1,
    y: 9,
    name: "Point2",
    color: "#00FF00"
}, {
    x: 1,
    y: 6,
    name: "Point1",
    color: "#FF00FF"
}]

Live demo: http://jsfiddle.net/BlackLabel/hpd6kt2z/ 现场演示: http : //jsfiddle.net/BlackLabel/hpd6kt2z/

API Reference: https://api.highcharts.com/highcharts/series.line.data API参考: https//api.highcharts.com/highcharts/series.line.data

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM