Ciao a tutti, avrei bisogno di un prezioso aiuto.
Mi riferisco al Chart Controls di NET:
http://archive.msdn.microsoft.com/ms...ReleaseId=4418
Con il codice che vi posto di seguito non riesco a:
1) creare spazi tra una `series` e l'altra dell'area del grafico;
2) assegnare dinamicamente ciascun nome alle `series` da un dato preso da una query.
Ad esempio la `series` che ho chiamato "Default" dovrebbe essere chiamata con il nome del campo `AAA` della tabella estratto tramite la query.
Qualcuno ha già avuto queste difficoltà?. Su Google ho trovato pochissimo e complicato...
Grazie
codice:<%@ Import Namespace="System.Data.Odbc" %> <%@ Import Namespace="System.Drawing" %> <%@ Import Namespace="System.IO" %> <%@ Import Namespace="System.Collections.Generic" %> <%@ Import Namespace="System.Linq" %> <%@ Import Namespace="System.Configuration" %> <%@ Import Namespace="System.Security.Principal" %> <%@ Import Namespace="System.Text" %> <%@ Import Namespace="DocumentFormat.OpenXml" %> <%@ Import Namespace="DocumentFormat.OpenXml.Presentation" %> <%@ Import Namespace="DocumentFormat.OpenXml.Packaging" %> <%@ Import Namespace="DocumentFormat.OpenXml.Drawing" %> <%@ Register Assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Web.UI.DataVisualization.Charting" TagPrefix="asp" %> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title>Chart</title> <script runat="server"> private void Page_Load(object sender, System.EventArgs e) { OdbcConnection myConnectionString = new OdbcConnection(ConfigurationManager.ConnectionStrings["ConnMySQL"].ConnectionString); myConnectionString.Open(); String strQuery = " SELECT AAA, BBB, CCC, DDD, EEE, myDates from myTbl; "; OdbcCommand objCmd = new OdbcCommand(strQuery, myConnectionString); objCmd.CommandType = CommandType.Text; objCmd.CommandText = strQuery; Chart1.DataSource = objCmd.ExecuteReader(); Chart1.ChartAreas["ChartArea1"].Area3DStyle.Inclination = 0; Chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = false; Chart1.ChartAreas["ChartArea1"].AxisX.LabelStyle.Angle = -35; Chart1.ChartAreas["ChartArea1"].AxisX.IsLabelAutoFit = false; Chart1.ChartAreas["ChartArea1"].AxisX.LabelStyle.Font = new System.Drawing.Font("Arial", 8); Chart1.ChartAreas["ChartArea1"].AxisX.LabelStyle.IsStaggered = false; Chart1.ChartAreas["ChartArea1"].AxisX.LabelStyle.Enabled = true; Chart1.ChartAreas["ChartArea1"].AxisX.IsMarginVisible = true; Chart1.ChartAreas["ChartArea1"].AxisX.LineColor = Color.Black; Chart1.ChartAreas["ChartArea1"].AxisY.LineColor = Color.Black; Chart1.ChartAreas["ChartArea1"].AxisX.LineDashStyle = ChartDashStyle.Solid; Chart1.ChartAreas["ChartArea1"].AxisX.LineWidth = 3; Chart1.ChartAreas["ChartArea1"].AxisY.LineWidth = 3; Chart1.AntiAliasing = AntiAliasingStyles.All; Chart1.TextAntiAliasingQuality = TextAntiAliasingQuality.High; Chart1.Series["Default"].XValueMember = "AAA"; Chart1.Series["Default"].YValueMembers = "BBB"; Chart1.Series["Default"].ChartType = SeriesChartType.Column; Chart1.Series["Default"]["PointWidth"] = "0.7"; Chart1.Series["Default"].IsValueShownAsLabel = true; Chart1.Series["Default"]["BarLabelStyle"] = "Center"; Chart1.Series["Default"]["PixelPointDepth"] = "99"; Chart1.Series["Default"]["DrawingStyle"] = "Cylinder"; Chart1.Series["Default"].Font = new System.Drawing.Font("Verdana", 10); Chart1.Series["Default"]["LabelStyle"] = "Top"; Chart1.Series["Default2"].YValueMembers = "CCC"; Chart1.Series["Default2"].ChartType = SeriesChartType.Column; Chart1.Series["Default2"]["LabelStyle"] = "Center"; Chart1.Series["Default2"]["PointWidth"] = "0.7"; Chart1.Series["Default2"].IsValueShownAsLabel = true; Chart1.Series["Default2"].Font = new System.Drawing.Font("Verdana", 10); Chart1.Series["Default2"]["LabelStyle"] = "TopLeft"; Chart1.Series["Default2"]["BarLabelStyle"] = "Center"; Chart1.Series["Default2"]["PixelPointDepth"] = "99"; Chart1.Series["Default2"]["DrawingStyle"] = "Cylinder"; Chart1.Series["Default3"].YValueMembers = "DDD"; Chart1.Series["Default3"].ChartType = SeriesChartType.Line; Chart1.Series["Default3"].Font = new System.Drawing.Font("Verdana", 12); Chart1.Series["Default3"]["LabelStyle"] = "TopLeft"; Chart1.Series["Default4"].YValueMembers = "EEE"; Chart1.Series["Default4"].ChartType = SeriesChartType.Column; Chart1.Series["Default4"]["PointWidth"] = "0.7"; Chart1.Series["Default4"].IsValueShownAsLabel = true; Chart1.Series["Default4"]["BarLabelStyle"] = "Center"; Chart1.Series["Default4"]["PixelPointDepth"] = "99"; Chart1.Series["Default4"]["DrawingStyle"] = "Cylinder"; Chart1.Series["Default4"].Font = new System.Drawing.Font("Verdana", 10); Chart1.Series["Default4"]["LabelStyle"] = "Top"; Chart1.Legends.Add(new Legend("Default")); Chart1.Series["Default"].Legend = "Default"; Chart1.Legends["Default"].BackColor = Color.MediumSeaGreen; Chart1.Legends["Default"].BackSecondaryColor = Color.Green; Chart1.Legends["Default"].BackGradientStyle = GradientStyle.DiagonalLeft; Chart1.Legends["Default"].BorderColor = Color.Black; Chart1.Legends["Default"].BorderWidth = 2; Chart1.Legends["Default"].BorderDashStyle = ChartDashStyle.Solid; Chart1.Legends["Default"].ShadowOffset = 2; myConnectionString.Close(); myConnectionString.Dispose(); } </script> </head> <body> <form id="form1" runat="server"> <div> <asp:Chart ID="Chart1" runat="server" Width="1058" Height="680"> <Series> <asp:Series Name="Default" ChartArea="ChartArea1" Color="MediumOrchid" BorderWidth="2"> </asp:Series> </Series> <Series> <asp:Series Name="Default2" ChartArea="ChartArea1" Color="Maroon" BorderWidth="2"> </asp:Series> </Series> <Series> <asp:Series Name="Default3" ChartArea="ChartArea1" Color="Red" BorderWidth="4"> </asp:Series> </Series> <Series> <asp:Series Name="Default4" ChartArea="ChartArea1" Color="Blue" BorderWidth="2"> </asp:Series> </Series> <ChartAreas> <asp:ChartArea Name="ChartArea1"> <AxisX Interval="1"> </AxisX> </asp:ChartArea> </ChartAreas> </asp:Chart> </div> </form> </body> </html>

Rispondi quotando