gpt4 book ai didi

javascript - Highcharts不同数据同图表

转载 作者:行者123 更新时间:2023-11-30 20:33:19 24 4
gpt4 key购买 nike

我想知道如何将比较数据添加到同一个图表,我有当前连接代码,下面是 HTML,我想在同一个图表上比较降雨和阳光数据,它们都来自同一张表。我需要创建另一个 get set 吗?................................................

public string chartData
{
get;
set;
}
public void renderChart()
{
DataTable dt = GetData();
data as datatable
List<int> _data = new List<int>();
foreach (DataRow row in dt.Rows)
{
_data.Add((int)row["Rainfall"]);

}
JavaScriptSerializer jss = new JavaScriptSerializer();
chartData = jss.Serialize(_data);
}



public DataTable GetData()
{
string connectionString = ConfigurationManager.ConnectionStrings["HighChartsConnectionString"].ConnectionString;
DataTable dt = new DataTable();

using (SqlConnection connection = new SqlConnection("SQLServerConnection"))
{
using (SqlCommand command = new SqlCommand("Select Rainfall,Sunlight from SalesData", connection))
{
connection.Open();
using (SqlDataReader dr = command.ExecuteReader())
{
if (dr.HasRows)
{
dt.Load(dr);
}
}
}
}

return dt;
}

$(function () {  
$('#container').highcharts({
chart: {
type: 'column'
},
title: {
text: 'RainFall'
},
subtitle: {
text: ' '
},
xAxis: {
categories: [
'Amazon',
'Sudan',
'Europe'
]
},
yAxis: {
min: 0,
title: {
text: 'Rainfall in inches'
}
},
tooltip: {
headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
'<td style="padding:0"><b>{point.y:.0f}</b></td></tr>',
footerFormat: '</table>',
shared: true,
useHTML: true
},
plotOptions: {
column: {
pointPadding: 0.2,
borderWidth: 0
}
},
series: [{
name: 'RainFall',
data: <%= chartData%>,
}]





});
});

最佳答案

听起来你需要 add another data set to series

关于javascript - Highcharts不同数据同图表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50108948/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com