为我的Web应用程序创建了一个aspx页面,该页面应该显示ASP.NET图表。能够生成图表但不在页面上显示。我可以在我的“临时图表”中看到生成的图表。夹。
我正在使用ASP.Net 4和.NET Framework 4并完成以下操作。
代码是:
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="System.Web.UI" %>
<%@ Import Namespace="System.Web.UI.HtmlControls" %>
<%@ Import Namespace="System.Web.UI.WebControls" %>
<%@ Import Namespace="System.Web.UI.WebControls.WebParts" %>
<%@ Import Namespace="System.Xml.Linq" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="System.Collections" %>
<%@ Import Namespace="System.Linq" %>
<%@ Import Namespace="System.Web.UI.DataVisualization" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Web.UI.DataVisualization.Charting" %>
<%@ Page Language="C#" %>
<%@ Register Assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Web.UI.DataVisualization.Charting" TagPrefix="asp" %>
<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
}
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
<asp:Chart ID="Chart1" runat="server" ImageLocation="~/TempCharts/ChartPic_#SEQ(200,2)" Height="200px" Width="535px" >
<BorderSkin />
<Series>
<asp:Series Name="Series1" ChartType="Pie" YValuesPerPoint="2" >
<Points>
<asp:DataPoint AxisLabel="4 letter" YValues="20,0" />
<asp:DataPoint AxisLabel="5 letter" YValues="10,0" />
<asp:DataPoint AxisLabel="6 letter" YValues="5,0" />
<asp:DataPoint AxisLabel="7 letter" YValues="16,0" />
</Points>
</asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea Name="ChartArea1" >
</asp:ChartArea>
</ChartAreas>
</asp:Chart>
</div>
</form>
</body>
</html>
并将以下内容添加到web.config:
<appSettings>
<add key="ChartImageHandler" value="storage=memory;timeout=30;" />
</appSettings>
<system.webServer>
<handlers>
<remove name="ChartImageHandler" />
<add name="ChartImageHandler" preCondition="integratedMode" verb="GET,HEAD,POST"
path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler,
System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</handlers>
</system.webServer>
但我无法在页面上看到图表。我错过了吗?
已解决:已将ImageStorageMode属性添加到<asp:Chart>
并设置值&#34; UseImageLocation&#34;
答案 0 :(得分:0)
这是一个完整的Web.Config图表设置:
<configuration>
<appSettings>
<add key="ChartImageHandler" value="storage=file;timeout=30;dir=~/TempCharts/;"/>
</appSettings>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<handlers>
<remove name="ChartImageHandler"/>
<add name="ChartImageHandler" preCondition="integratedMode" verb="GET,HEAD,POST" path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</handlers>
</system.webServer>
<system.web>
<httpHandlers>
<add path="ChartImg.axd" verb="GET,HEAD,POST" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
</httpHandlers>
<pages>
<controls>
<add tagPrefix="asp" namespace="System.Web.UI.DataVisualization.Charting" assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</controls>
</pages>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/></assemblies</compilation>
</system.web>
</configuration>
将它与您当前的Web.Config文件进行比较,看看缺少了什么,并尝试创建一个新的空项目,添加对System.Web.DataVisualization.dll的引用,它应该自动添加图表设置Web.Config文件。
希望这有帮助。
答案 1 :(得分:0)
尝试从
<appSettings>
<add key="ChartImageHandler" value="storage=memory;timeout=30;" />
</appSettings>
到这个
<appSettings>
<add key="ChartImageHandler" value="storage=memory;timeout=30;privateImages=false" />
</appSettings>
设置为true时,如果强制执行以下某些类型的标识,则只能由其所有者下载生成的图像:
用户已通过身份验证 AnonymousID已启用 SessionID可用。
默认值为true。