例如我的x轴为时间,y轴为成绩,在折线上如何显示出具体的数据,而且还能加上连接更好,就是点一下那个数据,能够连接到一个页面上。请大侠帮帮忙。下面是我找的源代码:
double xx, yy;
PointPairList list = new PointPairList();
for (int i = 0; i < 10; i++)
{
string[] kk = x[i].Split('-');
xx = (double)new XDate(Convert.ToInt32(kk[0]), Convert.ToInt32(kk[1]), Convert.ToInt32(kk[2])+11);
yy =Convert.ToDouble(y[i]);
list.Add(xx,yy);
}
CurveItem myCurve = myPane.AddCurve("My Curve",list, Color.Red, SymbolType.Diamond);
myPane.XAxis.MajorTic.IsBetweenLabels = true;
myPane.XAxis.Scale.TextLabels = x;
myPane.XAxis.Type = AxisType.Text;
//myPane.XAxis.Type = AxisType.Date;
myPane.Fill = new Fill(Color.White, Color.FromArgb(200, 200, 255), 45.0f);
myPane.Chart.Fill = new Fill(Color.White, Color.LightGoldenrodYellow, 45.0f); pane.AxisChange(g);
我想肯定有不少人遇到过这个问题吧。请帮帮忙。
double xx, yy;
PointPairList list = new PointPairList();
for (int i = 0; i < 10; i++)
{
string[] kk = x[i].Split('-');
xx = (double)new XDate(Convert.ToInt32(kk[0]), Convert.ToInt32(kk[1]), Convert.ToInt32(kk[2])+11);
yy =Convert.ToDouble(y[i]);
list.Add(xx,yy);
}
CurveItem myCurve = myPane.AddCurve("My Curve",list, Color.Red, SymbolType.Diamond);
myPane.XAxis.MajorTic.IsBetweenLabels = true;
myPane.XAxis.Scale.TextLabels = x;
myPane.XAxis.Type = AxisType.Text;
//myPane.XAxis.Type = AxisType.Date;
myPane.Fill = new Fill(Color.White, Color.FromArgb(200, 200, 255), 45.0f);
myPane.Chart.Fill = new Fill(Color.White, Color.LightGoldenrodYellow, 45.0f); pane.AxisChange(g);
我想肯定有不少人遇到过这个问题吧。请帮帮忙。
解决方案 »
- 用Reflector反编译后如何重新生成dll?
- 票据无法读取,求教
- 怎么能把textbox的值读取为html?
- 关于按钮事件用 window.open
- .net 如何实现点击form上的非服务器控件按钮实现向SQl里添加数据的功能?
- 本人想买 一本 <<专家门诊asp.net 2003 >>一书 谁不想看,卖给我.联系方式:邮箱:[email protected](mp3che) 是书.
- 关于c#调用javascript的问题????
- 如何Sql Server连接也sleep的进程早点取消掉?
- 除了Page.IsPostBack以外,没有别的办法了吗?
- 如何在浏览器关闭之后保留用户登录状态
- upload问题
- 我想选择DataList的前5项,可以更改前5项的图片的visible属性,该如何做?
下面是我测试好的代码:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using ZedGraph.Web;
using ZedGraph;
using System.Drawing;
using tongguan.Data;
public partial class Graph1 : System.Web.UI.Page
{
baoguanOperate msg = new baoguanOperate();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void ZedGraphWeb1_RenderGraph(ZedGraph.Web.ZedGraphWeb webObject, System.Drawing.Graphics g, ZedGraph.MasterPane pane)
{
string[] w ={ "1:", "2:", "3:", "4:", "5:", "6:", "7:", "8:", "9:", "10:" };
double[] z = { 45, 75, 80, 129, 89, 67, 87, 102, 109, 115 };
string[] x = new string[10];
double[] y = new double[10];
DataSet ds = new DataSet();
ds = msg.Show_top10_papers();
DataTable dt = ds.Tables["tg"];
int k = 0;
//把数据库中papers的score取出
while(k<dt.Rows.Count)
{
string[] tt = dt.Rows[k][5].ToString().Split(' ');
x[k] = tt[0].Substring(2);
y[k] = Convert.ToDouble(dt.Rows[k][3].ToString());
k = k + 1;
}
//
GraphPane myPane = pane[0];
//
myPane.Title.Text = "折线成绩分布图";
myPane.Title.FontSpec.FontColor = Color.DarkBlue; myPane.XAxis.Title.Text = "考试的日期";
myPane.YAxis.Title.Text = "考试所对应的成绩";
myPane.XAxis.Title.FontSpec.FontColor = Color.DeepSkyBlue;
myPane.YAxis.Title.FontSpec.FontColor = Color.DeepSkyBlue; //double xx, yy;
//PointPairList list = new PointPairList();
//for (int i = 0; i < 10; i++)
//{
// string[] kk = x[i].Split('-'); // xx = (double)new XDate(Convert.ToInt32(kk[0]), Convert.ToInt32(kk[1]), Convert.ToInt32(kk[2]) + 11);
// //xx = (double)new XDate(1995, 5, i + 11); // //y = Math.Sin((double)i * Math.PI / 15.0);
// // xx =Convert.ToDouble( x[i]);
// // xx = (double)new XDate(Convert.ToDouble(x[i]));
// yy =Convert.ToDouble( y[i]); // list.Add(xx, yy);
//}
LineItem curve = myPane.AddCurve("My Curve", null, y, Color.Goldenrod, SymbolType.Triangle);
curve.Line.Width = 2.0F;
curve.Line.IsAntiAlias = true;
curve.Symbol.Fill = new Fill(Color.White);
curve.Symbol.Size = 7;
//
//LineItem curve1 = myPane.AddCurve("My Curve11", null, z, Color.Blue, SymbolType.Diamond);
//curve1.Line.Width = 2.0F;
//curve1.Line.IsAntiAlias = true;
//curve1.Symbol.Fill = new Fill(Color.White);
//curve1.Symbol.Size = 7;
//能够在折点上显示数据
// Fill the axis background with a gradient
myPane.Chart.Fill = new Fill(Color.White, Color.FromArgb(255, Color.ForestGreen), 45.0F);
// Offset Y space between point and label
// NOTE: This offset is in Y scale units, so it depends on your actual data
const double offset = 1.0;
// Loop to add text labels to the points
for (int i = 0; i < y.Length; i++)
{
// Get the pointpair
PointPair pt = curve.Points[i];
// Create a text label from the Y data value
TextObj text = new TextObj(pt.Y.ToString("f0"), pt.X, pt.Y + offset, CoordType.AxisXYScale, AlignH.Left, AlignV.Center);
text.ZOrder = ZOrder.A_InFront;
// Hide the border and the fill
text.FontSpec.Border.IsVisible = false;
text.FontSpec.Fill.IsVisible = false;
text.FontSpec.Angle = 1; //字体倾斜度
text.FontSpec.Size = 13;
text.FontSpec.FontColor = Color.Green;
//myPane.GraphObjList.Add(text);
myPane.GraphObjList.Add(text);
}
//for (int i = 0; i < z.Length; i++)
//{
// // Get the pointpair
// PointPair pt = curve1.Points[i];
// // Create a text label from the Y data value
// TextObj text = new TextObj(pt.Y.ToString("f0"), pt.X, pt.Y + offset,
// CoordType.AxisXYScale, AlignH.Left, AlignV.Center);
// text.ZOrder = ZOrder.A_InFront;
// // Hide the border and the fill
// text.FontSpec.Border.IsVisible = false;
// text.FontSpec.Fill.IsVisible = false;
// //text.FontSpec.Fill = new Fill( Color.FromArgb( 100, Color.White ) );
// // Rotate the text to 90 degrees
// text.FontSpec.Angle = 1; //数值字体倾斜度
// text.FontSpec.Size = 12;
// text.FontSpec.FontColor = Color.Green;
// myPane.GraphObjList.Add(text);
//} // Leave some extra space on top for the labels to fit within the chart rect
//myPane.YAxis.Scale.MaxGrace = 0.2;
//以上为显示折点数据信息的代码
myPane.XAxis.MajorTic.IsBetweenLabels = true;
myPane.XAxis.Type = AxisType.Text;
//myPane.XAxis.Type = AxisType.Date;
myPane.XAxis.Scale.TextLabels = x;
myPane.XAxis.Scale.FontSpec.Size = 10; //x线字体
myPane.XAxis.Scale.FontSpec.FontColor = Color.Crimson;
myPane.XAxis.Scale.FontSpec.Angle = 0;//x线字体倾斜度
//
myPane.Fill = new Fill(Color.Chartreuse, Color.FromArgb(200, 200, 255), 45.0f);
myPane.Chart.Fill = new Fill(Color.White, Color.LightGoldenrodYellow, 45.0f); pane.AxisChange(g);
myPane.Border.Color = Color.Green;
}
}