using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
using ZedGraph;
using ZedGraph.Web;
namespace HINDI.Web.Report
{
public partial class LineChart : System.Web.UI.Page
{
private string zPath = System.Configuration.ConfigurationManager.AppSettings["ZedPath"];
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
this.ZedGraphDemo();
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
this.ZedGraphWeb1.RenderGraph += new ZedGraphWebControlEventHandler(this.OnRenderGraph);
}
#endregion
#region ZedGraph生成折线图
private void ZedGraphDemo()
{
//设置图表保存文件夹
this.zgwLine.RenderedImagePath = zPath;
}
///
/// ZedGraph折线图演示
///
/// 封装的一个GDI+绘图图面
/// ZedGraph.MasterPane:绘图面板
private void OnRenderGraph(ZedGraphWeb zgw, Graphics g, MasterPane masterPane)
{
ZedGraph.GraphPane myPane = masterPane[0];
//主题
myPane.Title.Text = "指标数据报表";
//主题字体颜色
myPane.Title.FontSpec.FontColor = Color.Red;
//主题字体大小
myPane.Title.FontSpec.Size = 20;
//横纵坐标的标题
string [] subject = new string[]{"月份","数据值"};
//月份数组
string [] months = new string[] { "一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二" };
//月份对应值
double[] datas = new double[] { 1.5,2.1,1.5,1.8,1.7,1.9,5.9,4.3,1.7,1.8,1.1,1.9};
//数据点集合(包含横纵坐标点)
PointPairList list = new PointPairList();
for (int i = 0; i < months.Length; i++)
{
//横坐标点
double x = Convert.ToDouble(i);
//纵坐标点
double y = datas[i];
//添加到集合中
list.Add(x,y);
}
//设置横坐标的标题
myPane.XAxis.Title.Text = subject[0];
//设置纵坐标的标题
myPane.YAxis.Title.Text = subject[1];
//设置横坐标的类型为文本
myPane.XAxis.Type = AxisType.Text;
//设置横坐标的开始的最小值
myPane.XAxis.Scale.Min = 0;
//设置横坐标的结束的最大值
myPane.XAxis.Scale.Max = 13;
//设置横坐标要显示的文本
myPane.XAxis.Scale.TextLabels = months;
//设置横坐标的字体大小
myPane.XAxis.Scale.FontSpec.Size = 8;
//设置纵坐标的字体大小
myPane.YAxis.Scale.FontSpec.Size = 10;
//设置横坐标的文本为可见的(默认可见)
//myPane.XAxis.Scale.IsVisible = true;
//将横纵坐标点添加到面板中,并设置名称,值,颜色,点的形状
LineItem curve = myPane.AddCurve("实际值", list, Color.Red, SymbolType.Circle);
//设置各点的连线宽度
curve.Line.Width = 1.0F;
//设置点的填充颜色
curve.Symbol.Fill = new Fill(Color.White);
//设置点的大小
curve.Symbol.Size = 5;
//设置连接线的抗锯齿效果
curve.Line.IsAntiAlias = true;
//设置图形的填充颜色(渐变效果,及渐变的角度)
myPane.Chart.Fill = new Fill(Color.White,Color.SteelBlue,45.0F);
myPane.AxisChange(g);
//绘制图片
myPane.Draw(g);
}
#endregion
}
}
ZedGraph来源:http://sourceforge.net/project/showfiles.php?group_id=114675
ZedGraph相关例子资源:http://zedgraph.org/wiki/index.php?title=Sample_Graphs
newv.graph.GraphPane myPane = new GraphPane();
//定义绘制图表的大小
// 设置图表的说明文字
myPane.Title = "直方图";
myPane.XAxis.Title = "答题";
myPane.YAxis.Title = "人数";
//设置基于X轴排列柱状图
myPane.BarBase = BarBase.X;
myPane.XAxis.Type = AxisType.Text;
string[] machine ={ "赌东道大幅度的赌东道", "赌东道大幅度的赌东道-40", "赌东道大幅度的赌东道0-60", "赌东道大幅度的赌东道-70", "赌东道大幅度的赌东道0-80", "赌东道大幅度的赌东道0-90" };
double[] efficiency ={ 22, 13, 89, 19, 56, 7 };
double maxNum = 0;
PointPairList lineList2 = new PointPairList();
double x = 0;
double y = 0;
int a = 2;
int b = 89;
for (int i = 0; i < machine.Length; i++)
{
if (maxNum < efficiency[i])
maxNum = efficiency[i];
if (i == 0) minNum = efficiency[i];
else
{
if (minNum > efficiency[i])
minNum = efficiency[i];
}
x = i;
y = efficiency[i];
lineList.Add(x, y);
lineList2.Add(a, b);
else
lineList2.Add(0, 0);
}
maxNum = maxNum + 10;
if (minNum / 10 > 1) minNum = (Math.Ceiling(minNum / 10) - 1) * 10;
else minNum = 0;
//设置X轴显示“柱子”的起始和终止位置
myPane.XAxis.Max = 7;
myPane.XAxis.Min = 0;
myPane.YAxis.Max = maxNum;
myPane.XAxis.TextLabels = machine;
myPane.XAxis.ScaleFontSpec.Angle=-70;
//BarItem myCurve = myPane.AddBar("", null, efficiency, Color.Green);
myCurve.Line.IsSmooth = true;
myCurve2.Line.IsVisible=false;
myPane.FontSpec.Angle = 90;
//BarItem myCurve3 = myPane.AddCurve((.AddBar("", Convert.ToDouble(3),Convert.ToDouble(89), Color.Red);
// 在数据变化时绘制图形
//myPane.AxisChange(g);
//zgc.AxisChange();
string graphPath = "C:/Documents and Settings/Administrator/My Documents/Visual Studio 2005/Projects/WindowsApplication1/WindowsApplication1/filePath/" + "AnalysisGraph.bmp";
myPane.Image.Save(graphPath,System.Drawing.Imaging.ImageFormat.Png);