<%@ Page Language="C#" Description="dotnetCHARTING Component"%>
<%@ Register TagPrefix="dotnet" Namespace="dotnetCHARTING" Assembly="dotnetCHARTING"%>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.IO" %>
<script runat="server">
SeriesCollection getRandomData()
{
// 设置TempDirectory=“temp”属性时,一定要保证有该文件夹,否则会在当前线程文件夹下生成No Data图片
SeriesCollection SC = new SeriesCollection();
int[] myDay = new int []{1,2,3,4,5,6,7,8,9,10,11,12};
int[] myLine1 = new int[] { 2, 3, 11, 4, 5, 6, 7, 8, 9, 8, 9, 8 };
int[] myLine2 = new int[] { 10, 1, 21, 1, 2, 2, 1, 1, 1, 1, 1, 13 };
int[] myLine3 = new int[] { 5, 12, 11, 14, 21, 18, 31, 41, 51, 51, 21, 43 };
int[] myLine4 = new int[] { 15, 2, 5, 4, 2, 8, 3, 4, 5, 5, 2, 4 };
ArrayList cc = new ArrayList();
cc.Add(myLine1);
cc.Add(myLine2);
cc.Add(myLine3);
cc.Add(myLine4);
for(int a = 0; a <4; a++)
{
Series s = new Series();
s.Name = "Line " + (a+1);
for(int b = 0; b < myDay.Length; b++)
{
Element e = new Element();
e.Name = "Element: " + b;
e.YValue = ((int[])cc[a])[b];
e.XValue = myDay[b];
// e.SmartLabel.Text = ;//自定义数据点的显示样式
s.Elements.Add(e);
}
SC.Add(s);
}
// Set Different Colors for our Series
SC[0].DefaultElement.Color = Color.FromArgb(49,255,49);
SC[1].DefaultElement.Color = Color.FromArgb(255,255,0);
SC[2].DefaultElement.Color = Color.FromArgb(255,99,49);
SC[3].DefaultElement.Color = Color.FromArgb(0, 156, 255);
return SC;
}
void Page_Load(Object sender,EventArgs e)
{
string dirPath;
if (!Page.IsPostBack)
{
dirPath = Server.MapPath(".") + @"temp\";
if (Directory.Exists(dirPath))
{
DirectoryInfo dir = new DirectoryInfo(dirPath);
if (dir.GetFiles().Length > 50)
{
foreach (FileInfo f in dir.GetFiles())
{
f.Delete();
}
}
}
dirPath = Server.MapPath(".") ;
DirectoryInfo adminDir = new DirectoryInfo(dirPath);
foreach (FileInfo fi in adminDir.GetFiles())
{
if (fi.Extension.ToLower() == ".png")
{
fi.Delete();
}
}
}
/*标题框设置*/
Chart.Title="访问量统计图";
Chart.TitleBox.Position = TitleBoxPosition.Center;
Chart.TitleBox.Background.Color = Color.LightBlue;
Chart.TitleBox.CornerTopLeft = BoxCorner.Cut;
Chart.TitleBox.CornerTopRight = BoxCorner.Cut;
Chart.Type = ChartType.Scatter;//数据图形显示方式
Chart.Debug = true;
Chart.ImageFormat = ImageFormat.Png;//生成的图表文件类型
Chart.DefaultElement.ShowValue = true;//显示坐标点的值
Chart.Use3D = false;
Chart.DefaultSeries.Type = SeriesType.Line;//数据图形类型
//Chart.DefaultElement.SmartLabel.DynamicDisplay = false;
//坐标轴设置
Chart.DefaultAxis.Line.StartCap = System.Drawing.Drawing2D.LineCap.RoundAnchor;//坐标轴线条开始端点
Chart.DefaultAxis.Line.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor; //坐标轴线条结束端点
Chart.DefaultAxis.Line.Width = 4;//坐标轴线条大小
Chart.XAxis.Interval = 1;//x轴的最小刻度
Chart.YAxis.Interval = 5;//y轴的最小刻度
//Chart.XAxis.Maximum = 12;//X轴的最大值,默认为坐标点最大值
//Chart.YAxis.Maximum = 100;//Y轴的最大值,默认为坐标点最大值
// Chart.DefaultSeries.DefaultElement.Marker.Type = ElementMarkerType.FivePointStar;
Chart.DefaultSeries.Element.Marker.Type = ElementMarkerType.Circle; //坐标点的图形
// Set a default transparency
Chart.DefaultSeries.DefaultElement.Transparency = 40;//线条透明度
Chart.XAxis.Label.Text = "月份";//x坐标名称
Chart.YAxis.Label.Text = "人数";//y坐标命名
Chart.TempDirectory = "temp";//图片存放路径
Chart.Width = 600;//报表图宽度
Chart.Height = 650;//报表图高度
// Add the random data.
SeriesCollection sc = new SeriesCollection();
sc = getRandomData();
double sum = sc.Calculate("", Calculation.Sum).Calculate("", Calculation.Sum).YValue;//sum of YAxis
Chart.LegendBox.HeaderLabel.Text = "Total:" + sum.ToString();//注释提示框
Chart.SeriesCollection.Add(sc);//为图表添加数据源
string filePicture = Chart.FileManager.SaveImage();//返回带文件名的路径,如 temp\dnc-2vt63wfc.png
// Response.Write(filePicture.ToString());
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Gallery Sample </title></head>
<body>
<div style="text-align:center">
<dotnet:Chart id="Chart" runat="server"></dotnet:Chart>
</div>
</body>
</html>
如需了解更多的应用,可以发邮件给我。