前台代码
<div style="position:absolute; top:100px; left:10px; width:865px; height:370px;OVERFLOW-y:auto;OVERFLOW-x:auto;">
<asp:Chart ID="Chart1" runat="server" ImageLocation="~/TempImages/ChartPic_#SEQ(300,3)"
Palette="BrightPastel" ImageType="Png" BackSecondaryColor="White" BackGradientStyle="TopBottom"
BorderWidth="2" BackColor="#D3DFF0" BorderColor="26, 59, 105" AntiAliasing="None"
BorderlineDashStyle="Solid">
<Legends>
<asp:Legend IsTextAutoFit="False" Name="Default" BackColor="Transparent" Font="Trebuchet MS, 8.25pt, style=Bold">
</asp:Legend>
</Legends> <%-- 控制小图标的显示格式 --%>
<BorderSkin SkinStyle="Emboss" ></BorderSkin> <%--<!--控制整个图片边缘的格式 -->--%>
<Series>
<%-- 数据(一个数据集为<asp:Series></asp:Series>) --%>
</Series>
<ChartAreas > <%-- 作图区的修饰 --%>
<asp:ChartArea Name="ChartArea1" BorderColor="64, 64, 64, 64" BorderDashStyle="Solid"
BackSecondaryColor="White" BackColor="64, 165, 191, 228" ShadowColor="Transparent"
BackGradientStyle="TopBottom">
<Area3DStyle Rotation="10" Perspective="10" Inclination="15" IsRightAngleAxes="False"
WallWidth="0" IsClustered="False"></Area3DStyle>
</asp:ChartArea>
</ChartAreas>
</asp:Chart>
</div>
后台代码:
int[] test = { 100, 70, 40, 30, 20, 65, 56, 30, 50, 90, 80, 70, 90, 10, 80, 60, 50, 40, 30, 20, 10, 30, 100, 70, 40, 30, 20, 60, 50, 30, 50, 90, 80, 70, 30, 20, 10, 30, 100, 70, 40, 30, 20, 60, 50, 30, 50, 90, 80, 70 }; //内销
int[] test1 = { 80, 70, 90, 10, 80, 60, 50, 40, 30, 20, 10, 0, 50, 90, 100, 70, 40, 30, 20, 60, 50, 30, 100, 70, 40, 30, 20, 60, 50, 30, 50, 90, 80, 70, 30, 20, 10, 30, 100, 70, 40, 30, 20, 60, 50, 30, 50, 90, 80, 70 }; //出口
//图片属性设置
Chart1.Width = (test.Count() * 25 + 200) >= 600 ? test.Count() * 25 + 200 : 600; //图片宽度
Chart1.Height = 400; //图片高度
//chart2.BackColor = Color.Azure; //图片背景色
Title t2 = new Title("试验2"); //图片标题
Chart1.Titles.Add(t2);
//数据集显示属性设置
//数据集"出口"显示属性设置
Series series1 = new Series("出口"); //数据集声明
series1.ChartType = SeriesChartType.Line; //数据显示方式 Line:为折线 Spline:曲线
series1.Color = Color.Green; //线条颜色
series1.BorderWidth = 2; //线条宽度
series1.ShadowOffset = 1; //阴影宽度
series1.IsVisibleInLegend = true; //是否显示数据说明
series1.IsValueShownAsLabel = false; //线条上是否给吃数据的显示
series1.MarkerStyle = MarkerStyle.Circle; //线条上的数据点标志类型
series1.MarkerSize = 8; // 标志的大小
DateTime date1 = DateTime.Now.Date;
for (int i = 0; i < test1.Count(); i++) //向数据集绑定数据
{
series1.Points.AddXY(date1, test1[i]);
//分别往X,Y轴添加数据(可以为多种类型) (有多中添加方式)
date1 = date1.AddDays(1);
}
Chart1.Series.Add(series1); //把数据集添加到chart中
//数据集"内销"显示属性设置
Series series2 = new Series("内销");
series2.ChartType = SeriesChartType.Line; //数据显示方式 Line:为折线 Spline:曲线
series2.Color = Color.Red; //线条颜色
series2.BorderWidth = 2; //线条宽度
series2.ShadowOffset = 1; //阴影宽度
series2.IsVisibleInLegend = true; //是否显示数据说明
series2.IsValueShownAsLabel = false; //线条上是否给吃数据的显示
series2.MarkerStyle = MarkerStyle.Circle; //线条上的数据点标志类型
series2.MarkerSize = 8; //标志的大小
DateTime date = DateTime.Now.Date;
for (int i = 0; i < test.Count(); i++)
{
series2.Points.AddXY(date, test[i]);
date = date.AddDays(1);
}
Chart1.Series.Add(series2);
//作图区的显示属性设置
Chart1.ChartAreas["ChartArea1"].AxisX.IsMarginVisible = false;
Chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = false;
//背景色设置
Chart1.ChartAreas["ChartArea1"].ShadowColor = Color.Transparent;
Chart1.ChartAreas["ChartArea1"].BackColor = Color.Azure; //该处设置为了由天蓝到白色的逐渐变化
Chart1.ChartAreas["ChartArea1"].BackGradientStyle = GradientStyle.TopBottom;
Chart1.ChartAreas["ChartArea1"].BackSecondaryColor = Color.White;
//X,Y坐标线颜色和大小
Chart1.ChartAreas["ChartArea1"].AxisX.LineColor = Color.Blue;
Chart1.ChartAreas["ChartArea1"].AxisY.LineColor = Color.Blue;
Chart1.ChartAreas["ChartArea1"].AxisX.LineWidth = 2;
Chart1.ChartAreas["ChartArea1"].AxisY.LineWidth = 2;
Chart1.ChartAreas["ChartArea1"].AxisY.Title = "百分比";
Chart1.ChartAreas["ChartArea1"].AxisX.Title = "时间";
//中间X,Y线条的颜色设置
Chart1.ChartAreas["ChartArea1"].AxisX.MajorGrid.LineColor = Color.Blue;
Chart1.ChartAreas["ChartArea1"].AxisY.MajorGrid.LineColor = Color.Blue;
//X.Y轴数据显示间隔
Chart1.ChartAreas["ChartArea1"].AxisX.Interval = 1; //X轴数据显示间隔
Chart1.ChartAreas["ChartArea1"].AxisY.Interval = 10;
//X轴线条显示间隔
Chart1.ChartAreas["ChartArea1"].AxisX.MajorGrid.Interval = 1;