柱形图控件 关键字 柱形图 asp.net2.0柱形图 柱形图控件 免费柱形图控件
asp.net制作柱形图有很多方法 使用GDI+也可以实现.这里我使用的是asp.net2.0的开源柱形图控件。
ZedGraph
我将 他的绘图事件封装成了一个类 这样就可以方便的调用了
using
System;
using
System.Data;
using
System.Configuration;
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.Collections;
using
System.Drawing;
using
ZedGraph;
using
ZedGraph.Web;
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
public
class
mymap
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
public string userame;
public ArrayList _date;
public mymap()
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
_date = new ArrayList();
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
public
class
mydate
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
public double x1;
public double x2;
public double x3;
public double x4;
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
public
class
mygraph
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
public static void OnRenderGraph(ZedGraphWeb zgw, Graphics g, MasterPane masterPane,mymap m)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
GraphPane myPane = masterPane[0];
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
myPane.Title.Text = "员工业绩图:"+m.userame; //captaion
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
string[] labels2 =
{ "100", "800", "1000", "2000" };
myPane.YAxis.MajorTic.IsBetweenLabels = true;
myPane.YAxis.Title.Text = "款额(万元)";
myPane.YAxis.Scale.Max=30;
myPane.YAxis.Scale.Min = 0;
myPane.YAxis.Type = AxisType.Exponent;
myPane.XAxis.Title.Text = "月业绩";
//myPane.YAxis.Title.Text = "Gross Sales, $Thousands";
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
PointPairList list = new PointPairList();
PointPairList list2 = new PointPairList();
PointPairList list3 = new PointPairList();
PointPairList list4 = new PointPairList();
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
Random rand = new Random();
for (double x = 0; x < 12; x +=1.0)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
double y = ((mydate)m._date[(int)x]).x1;
double y2 = ((mydate)m._date[(int)x]).x2;
double y3 = ((mydate)m._date[(int)x]).x3;
double y4 = ((mydate)m._date[(int)x]).x4;
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
list.Add(x, y);
list2.Add(x, y2);
list3.Add(x, y3);
list4.Add(x, y4);
}
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
BarItem myCurve = myPane.AddBar("计划回款", list, Color.Blue);
myCurve.Bar.Fill = new Fill(Color.Blue, Color.White, Color.Blue);
BarItem myCurve2 = myPane.AddBar("实际回款", list2, Color.Red);
myCurve2.Bar.Fill = new Fill(Color.Red, Color.White, Color.Red);
BarItem myCurve3 = myPane.AddBar("铺货款", list3, Color.Green);
myCurve3.Bar.Fill = new Fill(Color.Green, Color.White, Color.Green);
BarItem myCurve4 = myPane.AddBar("任务额", list4, Color.Aqua);
myCurve4.Bar.Fill = new Fill(Color.Green, Color.White, Color.Aqua);
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
myPane.XAxis.MajorTic.IsBetweenLabels = true;
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
string[] labels =
{ "1月", "2月", "3月", "4月", "5月","6月","7月","8月","9月","10月","11月","12月" };
myPane.XAxis.Scale.TextLabels = labels;
myPane.XAxis.Type = AxisType.Text;
myPane.Fill = new Fill(Color.White, Color.FromArgb(200, 100, 255), 45.0f);
myPane.Chart.Fill = new Fill(Color.White, Color.LightGoldenrodYellow, 45.0f);
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
masterPane.AxisChange(g);
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
}
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)