c# chart 折线图 datatable 如何生成,我弄了2天,结果都是柱状图,代码如下
string sql = @"SELECT CID,ec01 FROM Iaec WHERE ebID=7";
string con = "server=192.168.1.3;database=HNBD;uid=sa;pwd=lidfss3!@#";
SqlDataAdapter sda = new SqlDataAdapter(sql, con);
DataTable dt = new DataTable();
sda.Fill(dt);
dataGridView1.DataSource = dt;
int iexp =dt.Rows.Count;
int i =2;
string[] xData = { "数值1", "数值2" };
int[] yData = { ieexp, i };
this.chart1.Series[0]["PieLabelStyle"] = "Outside";//将文字移到外侧
this.chart1.Series[0]["PieLineColor"] = "Black";//绘制黑色的连线。
this.chart1.Series["Series1"].Points.DataBindXY(xData, yData);
chart1.Series["Series1"]["PieDrawingStyle"] = "Default";
非常请求大神们帮我改一下代码, 让我有一个折线图出来,非常感谢.
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Highcharts Example</title>
<script type="text/javascript" src="http://cdn.hcharts.cn/jquery/jquery-1.8.2.min.js"></script>
<style type="text/css">
${demo.css}
</style>
<script type="text/javascript">
$(function () {
$('#container').highcharts({
title: {
text: 'Monthly Average Temperature',
x: -20 //center
},
subtitle: {
text: 'Source: WorldClimate.com',
x: -20
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
yAxis: {
title: {
text: 'Temperature (°C)'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
valueSuffix: '°C'
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'middle',
borderWidth: 0
},
series: [{
name: 'Tokyo',
data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]
}, {
name: 'New York',
data: [-0.2, 0.8, 5.7, 11.3, 17.0, 22.0, 24.8, 24.1, 20.1, 14.1, 8.6, 2.5]
}, {
name: 'Berlin',
data: [-0.9, 0.6, 3.5, 8.4, 13.5, 17.0, 18.6, 17.9, 14.3, 9.0, 3.9, 1.0]
}, {
name: 'London',
data: [3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8]
}]
});
});
</script>
</head>
<body>
<script src="../../js/highcharts.js"></script>
<script src="../../js/modules/exporting.js"></script>
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
</body>
</html>
默认的是柱状图
先循环把点加进去
for()
{
Chart1.Series["Series1"].Points.AddXY(横坐标的值,纵坐标的值);
},你已经做了绑定,没必要循环了
设置图表类型
Chart1.Series["Series1"].ChartType=SeriesChartType.****
SeriesChartType是个枚举,包含很多图表类型,有柱状图,饼状图,自己看看就行了
怎么设置X的刻度呢
@zhengyingcan: this.Chart1.ChartAreas["Series1"].AxisX.Interval = *****
@zhengyingcan: 基本流程
this.Chart1.DataSource = dt;//绑定数据
this.Chart1.Series["Series1"].ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Line;//设置图表类型
this.Chart1.Series[0].XValueMember = "RecordTime";//X轴数据成员列
this.Chart1.Series[0].YValueMembers = "AValue";//Y轴数据成员列
this.Chart1.ChartAreas["ChartArea1"].AxisX.Title = "时间";//X轴标题
this.Chart1.ChartAreas["ChartArea1"].AxisY.Title = "数据值:单位(" + (ds2.Tables[0].Rows.Count == 1 ? ds2.Tables[0].Rows[0]["ValueUnit"].ToString().Trim() : "") + ")";//X轴标题
this.Chart1.ChartAreas["ChartArea1"].AxisX.Interval = 1;//X轴数据的间距
this.Chart1.ChartAreas[0].AxisX.IntervalType = DateTimeIntervalType.Hours;
this.Chart1.ChartAreas["ChartArea1"].AxisX.MajorGrid.Enabled = false;//不显示竖着的分割线
this.Chart1.Series[0].IsValueShownAsLabel = true;//显示坐标值
this.Chart1.DataBind();
chart1.Series["Series1"].ChartType = SeriesChartType.Line;