我的代码有问题,我需要制作一个显示图表的页面,以及一个用于更改图表类型的下拉列表
图表显示正确,但是下拉列表控件什么都不做,有人可以帮忙吗?我还想要选择在3种图表类型上使用3D
<%@ Page Title="" Language="VB" MasterPageFile="~/Site.master" AutoEventWireup="false" CodeFile="test.aspx.vb" Inherits="admin_test" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<script type="text/javascript" language="javascript">
function showContent(i) {
if (document.getElementById('statContent' + i).style.display == 'none') {
document.getElementById('statContent' + i).style.display = 'block';
} else {
document.getElementById('statContent' + i).style.display = 'none';
}
}
</script>
choose chart display type:
<asp:dropdownlist id="ChartTypeList" runat="server" AutoPostBack="True"
CssClass="spaceright" Width="112px">
<asp:ListItem Value="Column" Selected="True">Column 2D</asp:ListItem>
<asp:ListItem Value="Column">Column 3D</asp:ListItem>
<asp:ListItem Value="Line">Line 2D</asp:ListItem>
<asp:ListItem Value="Line">Line 3D</asp:ListItem>
<asp:ListItem Value="Pie">Pie 2D</asp:ListItem>
<asp:ListItem Value="Pie">Pie 3D</asp:ListItem>
</asp:dropdownlist><br />
<asp:Chart ID="Chart1" runat="server" DataSourceID="SqlDataSource1" >
<series>
<asp:Series Name="Series1" ChartType="Pie" XValueMember="suburb"
YValueMembers="username">
</asp:Series>
</series>
<chartareas>
<asp:ChartArea Name="ChartArea1">
</asp:ChartArea>
</chartareas>
</asp:Chart>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT suburb, COUNT(username) AS username FROM member GROUP BY suburb">
</asp:SqlDataSource>
</asp:Content>
答案 0 :(得分:1)
我没有看到OnSelectedIndexChanged
为您下拉列表列出的任何功能。你告诉它回发但不告诉它应该做什么。
你应该有类似的东西:
<asp:dropdownlist id="ChartTypeList" runat="server" AutoPostBack="True"
CssClass="spaceright" Width="112px" onselectedindexchanged="ChartTypeList_SelectedIndexChanged">
和代码隐藏
protected void ChartTypeList_SelectedIndexChanged(object sender, EventArgs e)
{
//change the chart code
}
答案 1 :(得分:0)
我自己解决了这个问题,只是想我会发布它以便任何人搜索 这是正确的代码背后:
Protected Sub DropDownList_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles DropDownList.SelectedIndexChanged
'keep charts hidden when not selected
If (DropDownList.SelectedValue = "hide") Then
Chart1.Visible = False
'Columns
ElseIf (DropDownList.SelectedValue = "Column 3D") Then
Chart1.Series(0).ChartType = DataVisualization.Charting.SeriesChartType.Column
Chart1.ChartAreas(0).Area3DStyle.Enable3D = True
Chart1.Visible = True
ElseIf (DropDownList.SelectedValue = "Column") Then
Chart1.Series(0).ChartType = DataVisualization.Charting.SeriesChartType.Column
Chart1.ChartAreas(0).Area3DStyle.Enable3D = False
Chart1.Visible = True
'Pies
ElseIf (DropDownList.SelectedValue = "Pie 3D") Then
Chart1.Series(0).ChartType = DataVisualization.Charting.SeriesChartType.Pie
Chart1.ChartAreas(0).Area3DStyle.Enable3D = True
Chart1.Visible = True
ElseIf (DropDownList.SelectedValue = "Pie") Then
Chart1.Series(0).ChartType = DataVisualization.Charting.SeriesChartType.Pie
Chart1.ChartAreas(0).Area3DStyle.Enable3D = False
Chart1.Visible = True
'Lines
ElseIf (DropDownList.SelectedValue = "Line 3D") Then
Chart1.Series(0).ChartType = DataVisualization.Charting.SeriesChartType.Line
Chart1.ChartAreas(0).Area3DStyle.Enable3D = True
Chart1.Visible = True
ElseIf (DropDownList.SelectedValue = "Line") Then
Chart1.Series(0).ChartType = DataVisualization.Charting.SeriesChartType.Line
Chart1.ChartAreas(0).Area3DStyle.Enable3D = False
Chart1.Visible = True
End If
End Sub
这是正确的代码:
<asp:dropdownlist id="DropDownList" runat="server" AutoPostBack="True"
OnSelectedIndexChanged="DropDownList_SelectedIndexChanged" >
<asp:ListItem value="hide" Selected="True">Select</asp:ListItem>
<asp:ListItem Value="Pie">Pie Chart</asp:ListItem>
<asp:ListItem Value="Pie 3D">Pie Chart 3D</asp:ListItem>
<asp:ListItem Value="Column" >Column Chart</asp:ListItem>
<asp:ListItem Value="Column 3D">Column Chart 3D</asp:ListItem>
<asp:ListItem Value="Line">Line Chart</asp:ListItem>
<asp:ListItem Value="Line 3D">Line Chart 3D</asp:ListItem>
</asp:dropdownlist><br />
<asp:Chart ID="Chart1" runat="server" Width="450px" Height="450px" DataSourceID="SqlDataSource1" Visible="false" >
<series>
<asp:Series Name="Series1" XValueMember="suburb" YValueMembers="username">
</asp:Series>
</series>
<chartareas>
<asp:ChartArea Name="ChartArea1">
</asp:ChartArea>
</chartareas>
</asp:Chart>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT suburb, COUNT(username) AS username FROM member GROUP BY suburb">
</asp:SqlDataSource>