1.配置问题:今天郁闷到,在宿舍里调试好软件,带到网络中心就没配置好真烦,原因是网络中心下载个东西要半天;
所需:
到微软下载吧,因为最新的图形控件必需要有对应的配置;
2.最好下到一些demo可以学习下怎么用:
3.前台界面
Code
统计图形:</td>
<td class="style5">
<asp:dropdownlist id="ChartType" runat="server" Width="120px" AutoPostBack="True"
CssClass="spaceright" onselectedindexchanged="ChartType_SelectedIndexChanged">
<asp:ListItem Value="Column">垂直柱状</asp:ListItem>
<asp:ListItem Value="Bar">水平柱状</asp:ListItem>
<asp:ListItem Value="Area">面积图</asp:ListItem>
<asp:ListItem Value="Line">线状图</asp:ListItem>
<asp:ListItem Value="Pie">饼形图</asp:ListItem>
<asp:ListItem Value="Point">点状图</asp:ListItem>
</asp:dropdownlist>
<asp:Button ID="Btn_seePic" runat="server" Text="查看统计图"
onclick="Btn_seePic_Click" />
</td>
</tr>
<tr>
<td colspan="2">
<%-- <IMG alt="Sales Data - Pie" src="SalesChart.aspx?type=pie&width=300&height=300&title=Sales+by+Year&subtitle="> --%>
<%-- <asp:Image ID="Image1" runat="server" />--%>
<asp:chart id="Chart1" runat="server" Width="412px" Height="296px" BorderColor="181, 64, 1" Palette="BrightPastel" BorderDashStyle="Solid" BackGradientStyle="TopBottom" BorderWidth="2" backcolor="#F3DFC1" ImageLocation="~/TempImages/ChartPic_#SEQ(300,3)">
<titles>
<asp:Title ShadowColor="32, 0, 0, 0" Font="Trebuchet MS, 14.25pt, style=Bold" ShadowOffset="3" Text="鱼类产量统计" ForeColor="26, 59, 105"></asp:Title>
</titles>
<legends>
<asp:Legend Enabled="False" IsTextAutoFit="False" Name="Default" BackColor="Transparent" Font="Trebuchet MS, 8.25pt, style=Bold"></asp:Legend>
</legends>
<borderskin SkinStyle="Emboss"></borderskin>
<series>
<asp:Series ChartArea="ChartArea1" Name="Default" ChartType="Bar" BorderColor="180, 26, 59, 105" Color="220, 65, 140, 240"></asp:Series>
</series>
<chartareas>
<asp:ChartArea Name="ChartArea1" BorderColor="64, 64, 64, 64" BorderDashStyle="Solid" BackSecondaryColor="White" BackColor="OldLace" ShadowColor="Transparent">
<axisy2 Enabled="False"></axisy2>
<axisx2 Enabled="False"></axisx2>
<area3dstyle Rotation="10" Perspective="10" Inclination="15" IsRightAngleAxes="False" WallWidth="0" IsClustered="False" />
<axisy LineColor="64, 64, 64, 64" IsLabelAutoFit="False">
<LabelStyle Font="Trebuchet MS, 8.25pt, style=Bold" Format="0,k" />
<MajorGrid LineColor="64, 64, 64, 64" />
</axisy>
<axisx LineColor="64, 64, 64, 64" IsLabelAutoFit="False">
<LabelStyle Font="Trebuchet MS, 8.25pt, style=Bold" />
<MajorGrid LineColor="64, 64, 64, 64" />
</axisx>
</asp:ChartArea>
</chartareas>
</asp:chart>
4.代码片段:
Code
/// <summary>
/// 创建图形
/// </summary>
public void CreatChart()
{
//得到省,城市,市区信息;
string proId = Request.Form[this.DropDownList1.UniqueID];
string cityId = Request.Form[this.DropDownList2.UniqueID];
string zoneId = Request.Form[this.DropDownList3.UniqueID];
//判断是否已经存在同一个区域的统计数据;
if (cityId == null && RadKind.SelectedItem.Text == "城市产量")
{
LabWarn.Text = "<font color=red>提示:请选择城市!</font>";
}
else if (zoneId == null && RadKind.SelectedItem.Text == "市区产量")
{
LabWarn.Text = "<font color=red>提示:请选择市区!</font>";
}
else
{
// Set data points label style
Chart1.Series["Default"]["BarLabelStyle"] = "Center";
// Show as 3D
Chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;
// Draw as 3D Cylinder
Chart1.Series["Default"]["DrawingStyle"] = "Cylinder";
// Set chart title
// Set chart title color
Chart1.Titles[0].ForeColor = Color.Blue;
// Set chart title back color
Chart1.Titles[0].BackColor = Color.LightCyan;
// Set chart title border color
Chart1.Titles[0].BorderColor = Color.YellowGreen;
// Set chart title Tooltips color
Chart1.Titles[0].ToolTip ="分析统计图";
Chart1.ChartAreas["ChartArea1"].AxisX.LabelAutoFitStyle = LabelAutoFitStyles.DecreaseFont | LabelAutoFitStyles.StaggeredLabels | LabelAutoFitStyles.LabelsAngleStep90;
Chart1.ChartAreas["ChartArea1"].AxisY.LabelAutoFitStyle = LabelAutoFitStyles.DecreaseFont | LabelAutoFitStyles.StaggeredLabels | LabelAutoFitStyles.LabelsAngleStep90;
// Populate series data
Random random = new Random(7259);
DateTime dateCurrent = DateTime.Now.Date;
for (int pointIndex = 0; pointIndex < 7; pointIndex++)
{
Chart1.Series[0].Points.AddXY(dateCurrent.AddDays(pointIndex), random.Next(1000, 9000) / 100.0);
}
// Set series chart type
if (ChartType.SelectedValue.ToString() == "Bar")
{
Chart1.Series["Default"].ChartType = SeriesChartType.Bar;
}
else if (ChartType.SelectedValue.ToString() == "Column")
{
Chart1.Series["Default"].ChartType = SeriesChartType.Column;
}
else if (ChartType.SelectedValue.ToString() == "Area")
{
Chart1.Series["Default"].ChartType = SeriesChartType.Area;
}
else if (ChartType.SelectedValue.ToString() == "Line")
{
Chart1.Series["Default"].ChartType = SeriesChartType.Line;
}
else if (ChartType.SelectedValue.ToString() == "Pie")
{
Chart1.Series["Default"].ChartType = SeriesChartType.Pie;
}
else if (ChartType.SelectedValue.ToString() == "Point")
{
Chart1.Series["Default"].ChartType = SeriesChartType.Point;
}
DataSet chartDs = Statistic.ShowChart(RadKind.SelectedItem.Text, proId, cityId, zoneId);
DataView firstView = new DataView(chartDs.Tables[0]);
// Since the DataView implements IEnumerable, pass the dataview directly into
// the DataBind method with the name of the Columns selected in the query
Chart1.Series["Default"].Points.DataBindXY(firstView, "Stat_Year", firstView, "Stat_Data");
}
}
以前OWC 要引用 dll,现在这种不用,但是要求配置更高了,最明显的是要装.net 3.5 sp1 ,ms chart.exe,语言包,看来微软下足功夫。
不过做出来的图形还不错。感觉看一下英文文档都能够使用,没办法只能用。要是自己用GDI+恐怕要写半天咯。