aic007 Skrevet 2. mai 2007 Skrevet 2. mai 2007 Hei. Jeg lasta ned gratis webchart control fra http://www.carlosag.net/Tools/WebChart/Default.aspx Vil hente data fra database og få det ut i form av grafer. Dette er koden jeg bruker <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Statistics.aspx.cs" Inherits="Statistikk" %> <%@ Register TagPrefix="Web" Namespace="WebChart" Assembly="WebChart" %> <%@ Import Namespace="System.Drawing" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.SqlClient" %> <%@ register tagprefix="web" namespace="WebChart" assembly="WebChart"%> <script runat="server"> private void Page_Load(object sender, System.EventArgs e) { if (!Page.IsPostBack) { //STEP 1: Get the data from the database SqlConnection myConnection = new SqlConnection("Connection String"); const string strSQL = @"SELECT TOP 6 Name, ViewCount " + "FROM tblFAQCategory ORDER BY NEWID()"; SqlCommand myCommand = new SqlCommand(strSQL, myConnection); SqlDataReader reader = new SqlDataReader(); reader = myCommand.ExecuteReader(); //STEP 2: Create the chart object PieChart chart = new PieChart(); //STEP 3: Bind the DataTable to the WebChart chart.DataSource = reader; chart.DataXValueField = "Name"; chart.DataYValueField = "ViewCount"; chart.DataBind(); chart.DataLabels.Visible = true; //STEP 4: Attach the chart object to the chart container ChartControl1.Charts.Add(chart); ChartControl1.RedrawChart(); reader.Close(); } } </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> <br /> <Web:ChartControl runat="Server" id="ChartControl1" height="400" Width="350" GridLines="None" Legend-Position="Bottom"/> </div> </form> </body> </html> Men det virker ikke. Er det noen som har erfaring med dette og kan gi meg noen eksempler på åssen jeg kan hente data fra database og vise det i form av grafer ?
aic007 Skrevet 2. mai 2007 Forfatter Skrevet 2. mai 2007 Jeg har kode her som henter data fra Access database. Er det noen som vet hva som må endres for å kunne hente det fra database som jeg har VS05 ? <%@ Page Language="VB" %> <%@ Register tagPrefix="web" Assembly="WebChart" Namespace="WebChart" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.OleDb" %> <script runat=server> Sub Page_Load(o as object, e as EventArgs) Dim reader As IDataReader = GetReader() Dim chart As New SmoothLineChart() chart.DataXValueField = "Product" chart.DataYValueField = "Price" chart.DataSource = reader chart.DataBind() reader.Close() ChartControl1.Charts.Add(chart) ChartControl1.RedrawChart() End Sub Function GetReader() As IDataReader Dim connection As new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Program Files\Microsoft Visual Studio\VB98\NWIND.MDB;Mode=Read") Dim command As new OleDbCommand("SELECT Top 10 [ProductName] As Product,[UnitPrice] As Price FROM Products order by UnitPrice desc", connection) connection.Open() Return command.ExecuteReader(CommandBehavior.CloseConnection) End Function </script> <html> <body> <form runat="server"> <web:ChartControl runat="server" Width="800px" Height="600px" id="ChartControl1" HasChartLegend="false" BottomChartPadding=80 ChartPadding=20> <XAxisFont ForeColor="Black" StringFormat="Center,Center,Character,DirectionVertical" Font="Tahoma, 8pt, style=bold" /> </web:ChartControl> </form> </body> </html> http://www.carlosag.net/Tools/WebChart/sampleAccess.aspx
Anbefalte innlegg
Opprett en konto eller logg inn for å kommentere
Du må være et medlem for å kunne skrive en kommentar
Opprett konto
Det er enkelt å melde seg inn for å starte en ny konto!
Start en kontoLogg inn
Har du allerede en konto? Logg inn her.
Logg inn nå