现在的情况是这样的,下图的数据图是柱状图,是已经能够连接上SQL server了,柱状数据也是来自于SQL server的table5表,
现在我上司又突然想加一个功能,就是当鼠标悬停在它们各自的柱状图或悬停在它们各自的X轴标签时(两种都可以),能够显示出它们各自的elaborate字段的文字内容,
table5的elaborate字段数据如下
之前有人建议我用tooltips控件来实现,但是不知道是不是撞邪了,我的VS工具箱内没有tooltips控件!!是的,没有!!!,不知道什么情况,想请求,跪求各路大神或专家过来帮我解决下好吗~~本人目前实习生,主要偏向SQL server,但是由于项目要求,不得不使用VS软件来制作数据分析图,在学校也没有接触过这个软件,恳请恳求大神帮忙啊~!!顺便留下我的扣扣联系方式:584958184
顺便附上我的后台代码~
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Drawing;
using System.Web.UI.DataVisualization.Charting;
namespace zhu
{
public partial class WebForm3 : System.Web.UI.Page
{
public SqlConnection SqlConnString2;
string[] Count3 = new string[9];
double[] Count4 = new double[9];
protected void Page_Load(object sender, EventArgs e)
{
DataSet ds2 = new DataSet();
string vOutParam = "";
//载入SQL server的查询存储过程
ds2 = ExeProcDT4("Searchtable6", "", ref vOutParam);
if (ds2.Tables.Count > 0)
{
DataTable dt2 = new DataTable();
dt2 = ds2.Tables[0];
if (dt2.Rows.Count > 0)
{
for (int i = 0; i < 9; i++)
{
Count4[i] = Convert.ToDouble(dt2.Rows[i]["PM"]);
Count3[i] = dt2.Rows[i]["d"].ToString() + dt2.Rows[i]["e"].ToString();
}
}
}
zhuzhaugntu2(Count3, Count4);
}
//柱状图设置
protected void zhuzhaugntu2(string[] a, double[] b)
{
Chart1.ChartAreas[0].BackColor = Color.Black;//设置背景为黑色
Chart1.ChartAreas[0].Area3DStyle.PointGapDepth = 10;//x轴行间距
Chart1.ChartAreas[0].AxisY.MajorGrid.LineDashStyle = ChartDashStyle.Dash;//需线
Chart1.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.Yellow;//需线颜色
Chart1.ChartAreas[0].AxisX.MajorGrid.Enabled = false;//关掉竖线1
//根据水尺最高值设置Y轴间距
Chart1.ChartAreas[0].AxisY.Maximum = 10000;
Chart1.Series[0].Label = "#VAL";//设置标签文本 (在设计期通过属性窗口编辑更直观)
Chart1.Series[0].IsValueShownAsLabel = true;//显示标签
Chart1.ChartAreas[0].AxisX.LabelStyle.ForeColor = Color.Blue;
Chart1.ChartAreas[0].AxisX.LabelAutoFitMaxFontSize = 12;
Chart1.ChartAreas[0].AxisY.LabelAutoFitMaxFontSize = 15;
Chart1.ChartAreas[0].AxisY.LabelStyle.ForeColor = Color.Red;
Chart1.Series[0].Points.DataBindXY(a, b);//初始化数据
}
//连接数据库
private SqlConnection GetConnect()
{
string strSqlSqlConn2 = "Data Source=.;Initial Catalog=plc;" +
"Persist Security Info=True;User ID=Jerome;Password=123456";
SqlConnection sqlConnString2 = new SqlConnection(strSqlSqlConn2);
sqlConnString2.Open();
return sqlConnString2;
}
public DataSet ExeProcDT4(string procName, string vInParam, ref string vOutParam)
{
SqlConnString2 = GetConnect();
SqlCommand SqlCmd = new SqlCommand(procName, SqlConnString2);
SqlCmd.CommandType = CommandType.StoredProcedure;
SqlCmd.Parameters.Add("@inparam", SqlDbType.VarChar, 1000).Value = vInParam;
SqlCmd.Parameters.Add("@outparam", SqlDbType.VarChar, 1024).Direction = ParameterDirection.Output;
SqlDataAdapter SqlDa = new SqlDataAdapter(SqlCmd);
DataSet DS = new DataSet();
SqlDa.Fill(DS);
vOutParam = SqlCmd.Parameters["@outparam"].Value.ToString();
return DS;
}
}
}
你和 https://ask.csdn.net/questions/689601 这个帖子的发布者是什么关系?
echarts本身不是已经可以实现tooltips了么
例子网站:http://echarts.baidu.com/echarts2/doc/example/bar1.html
现在我在Count3[i] = dt2.Rows[i]["d"].ToString() + dt2.Rows[i]["e"].ToString();下加了一句 Chart1.Series[0].ToolTip = dt.Rows[i]["d"].ToString();,有鼠标悬停提示信息出来了,但提示的信息全部都是elaborate字段的第一行,都是一样的,怎么解决????
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Drawing;
using System.Web.UI.DataVisualization.Charting;
namespace zhu
{
public partial class WebForm3 : System.Web.UI.Page
{
public SqlConnection SqlConnString2;
string[] Count3 = new string[9];
double[] Count4 = new double[9];
protected void Page_Load(object sender, EventArgs e)
{
DataSet ds2 = new DataSet();
string vOutParam = "";
//载入SQL server的查询存储过程
ds2 = ExeProcDT4("Searchtable6", "", ref vOutParam);
if (ds2.Tables.Count > 0)
{
DataTable dt2 = new DataTable();
dt2 = ds2.Tables[0];
if (dt2.Rows.Count > 0)
{
for (int i = 0; i < 9; i++)
{
Count4[i] = Convert.ToDouble(dt2.Rows[i]["PM"]);
Count3[i] = dt2.Rows[i]["d"].ToString() + dt2.Rows[i]["e"].ToString();
Chart1.Series[0].ToolTip = dt.Rows[i]["d"].ToString();
}
}
}
zhuzhaugntu2(Count3, Count4);
}
//柱状图设置
protected void zhuzhaugntu2(string[] a, double[] b)
{
Chart1.ChartAreas[0].BackColor = Color.Black;//设置背景为黑色
Chart1.ChartAreas[0].Area3DStyle.PointGapDepth = 10;//x轴行间距
Chart1.ChartAreas[0].AxisY.MajorGrid.LineDashStyle = ChartDashStyle.Dash;//需线
Chart1.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.Yellow;//需线颜色
Chart1.ChartAreas[0].AxisX.MajorGrid.Enabled = false;//关掉竖线1
//根据水尺最高值设置Y轴间距
Chart1.ChartAreas[0].AxisY.Maximum = 10000;
Chart1.Series[0].Label = "#VAL";//设置标签文本 (在设计期通过属性窗口编辑更直观)
Chart1.Series[0].IsValueShownAsLabel = true;//显示标签
Chart1.ChartAreas[0].AxisX.LabelStyle.ForeColor = Color.Blue;
Chart1.ChartAreas[0].AxisX.LabelAutoFitMaxFontSize = 12;
Chart1.ChartAreas[0].AxisY.LabelAutoFitMaxFontSize = 15;
Chart1.ChartAreas[0].AxisY.LabelStyle.ForeColor = Color.Red;
Chart1.Series[0].Points.DataBindXY(a, b);//初始化数据
}
//连接数据库
private SqlConnection GetConnect()
{
string strSqlSqlConn2 = "Data Source=.;Initial Catalog=plc;" +
"Persist Security Info=True;User ID=Jerome;Password=123456";
SqlConnection sqlConnString2 = new SqlConnection(strSqlSqlConn2);
sqlConnString2.Open();
return sqlConnString2;
}
public DataSet ExeProcDT4(string procName, string vInParam, ref string vOutParam)
{
SqlConnString2 = GetConnect();
SqlCommand SqlCmd = new SqlCommand(procName, SqlConnString2);
SqlCmd.CommandType = CommandType.StoredProcedure;
SqlCmd.Parameters.Add("@inparam", SqlDbType.VarChar, 1000).Value = vInParam;
SqlCmd.Parameters.Add("@outparam", SqlDbType.VarChar, 1024).Direction = ParameterDirection.Output;
SqlDataAdapter SqlDa = new SqlDataAdapter(SqlCmd);
DataSet DS = new DataSet();
SqlDa.Fill(DS);
vOutParam = SqlCmd.Parameters["@outparam"].Value.ToString();
return DS;
}
}
}
有没人帮忙来看下,主要是elaborate字段的数据源不知道怎么绑定输出出来啊,输出出来的都是一样的信息!!!