[VB.NET & ASP.NET] Graphique : courbe
Code:
1 2 3 4
|
- ASP.NET
- VB.NET
- Visual Basic 2003 |
Bonjour au forum et aux amis,
après des recherches sur le forum, je n'ai pas réussi à trouver ma réponse.
Voila je dois réaliser des courbes, plus précisément, il faudra retrouver 3-4 courbes (soit plusieurs points réunis par une ligne ) de couleurs différentes sur un meme graphique. Il sera construit avec une abscisse et ordonné définit, puis les courbes devront être tracé.
Qu'elle serait la solution pour réaliser cette tâche ? Utiliser les méthodes graphics me parait fastidieux, non ? J'ai vu des outils pouvant réaliser ceci mais payant, malheuresement mon entreprise ne peut se permettre d'acheter un logiciel.
Faudrait-il que j'utilise MSCHART ? ou alors un composant CrystalReportViewer ?
Merci de votre éclaircissement !
Cordialement.
Salut, une piste et tu pourras l'améliorer après
Bonjour à tous,
Voici mon code source de mon premier graphique et je l'ai amélioré après.
Ce code crée 2 graphiques différents, les données sont stockées dans une table de sql server 2000, le code est en vb.net
Le voici:
Private Sub CreerGraphComparaison(ByVal strTitre As String, ByVal strSerie1 As String, ByVal strSerie2 As String)
Dim objCSpace As New ChartSpaceClass
Dim objChart, objChart2 As ChChart
Dim objSeries, objSeries2 As OWC10.ChSeries
Dim strCategory, strCategory2 As String
Dim strValue, strValue2 As String
Dim strFileName As String
Dim intI, intJ As Integer
Dim file_gif As FileInfo
'S'il n'y a pas d'enregistrements dans le DataGrid, inutile de créer le graph (on aurait un graph tout blanc : aucun intérêt)
If True Then
PictureBox1.Visible = True
objChart = objCSpace.Charts.Add(0)
'objChart2 = objCSpace.Charts.Add(0)
'Type du graph (ici camembert 3D)
'objChart.Type = ChartChartTypeEnum.chChartTypeColumn3D
objChart.Type = ChartChartTypeEnum.chChartTypeLine
'Titre et légendes
objChart.HasTitle = True
objChart.Title.Caption = strTitre
objChart.Title.Font.Bold = False
objChart.Title.Font.Name = "Arial, XX-Small"
objChart.Title.Font.Size = 4
objChart.HasLegend = True
'objSeries.Caption = strSerie1
'objSeries2.Caption = strSerie2
'objChart.Legend.Border.DashStyle = OWC10.ChartLineDashStyleEnum.chLineSolid
'objChart.Legend.Position = OWC10.ChartLegendPositionEnum.chLegendPositionRight
'Les données du graph correspondent au contenu de la Datatable qui est affiché dans un DataGrid
'For Each dRow As DataRow In dTable.Rows
' strCategory &= dglist.Item(intI, 0) & ","
' strValue &= dglist.Item(intI, 1).ToString.Replace(",", ".") & ","
' intI += 1
'Next
'courbe n°1
strCategory = ""
strValue = ""
get_data_graph(strCategory, strValue)
'courbe n°1
strCategory2 = ""
strValue2 = ""
get_data_graph2(strCategory2, strValue2)
objSeries = objChart.SeriesCollection.Add(0)
objSeries2 = objChart.SeriesCollection.Add(2)
objSeries.Caption = strSerie1
objSeries2.Caption = strSerie2
'Mise en forme des datas dans le graph
objSeries.SetData(ChartDimensionsEnum.chDimCategories, ChartSpecialDataSourcesEnum.chDataLiteral, strCategory)
objSeries.SetData(ChartDimensionsEnum.chDimValues, ChartSpecialDataSourcesEnum.chDataLiteral, strValue)
objSeries2.SetData(ChartDimensionsEnum.chDimCategories, ChartSpecialDataSourcesEnum.chDataLiteral, strCategory2)
objSeries2.SetData(ChartDimensionsEnum.chDimValues, ChartSpecialDataSourcesEnum.chDataLiteral, strValue2)
strFileName = "C:\graph2.gif"
file_gif = New FileInfo(strFileName)
'Si le fichier existe déjà, ça signifie qu'on a déjà associé le graph à la PictureBox
'Cette partie permet d'actualiser le graph avec les datas (si elles ont changé)
If file_gif.Exists Then
'On libère les ressources liées au fichier
PictureBox1.Image.Dispose()
file_gif.Delete()
End If
'Else
'Export du graph au format gif pour l'assigner à la propriété Image de la PictureBox
objCSpace.ExportPicture(strFileName, , 450, 300)
PictureBox1.Visible = True
PictureBox1.Image = Image.FromFile(strFileName)
'End If
Else
PictureBox1.Visible = False
End If
End Sub
Voici les procédures Get_Data_Graph :
Private Sub get_data_graph(ByRef strCategory, ByRef strValue)
Try
Dim strConnection As String = sConnexionPoint
Dim myConnection As New SqlClient.SqlConnection(strConnection)
myConnection.Open()
Dim strSql, sqlStr As String
strSql = "SELECT nombre,jour FROM ABS_GRAPHIQUES_COMPARE"
If Me.cbmois.Text.Length > 0 Then
strSql = strSql & " where mois = '" & Me.cbmois.SelectedItem & "' "
End If
strSql = strSql & " order by jour"
Dim cSource As New SqlCommand(strSql, myConnection)
Dim daSource As New SqlDataAdapter(cSource)
Dim dsSource As New DataSet
daSource.Fill(dsSource)
'If dsSource.Tables(0).Rows.Count > 0 Then
Dim Cmd As SqlCommand
Cmd = New SqlCommand(strSql, myConnection)
Cmd.CommandType = CommandType.Text
Dim dr As SqlDataReader
dr = Cmd.ExecuteReader
While dr.Read()
strCategory = strCategory & Trim(CType(dr("JOUR"), String)) & ","
strValue = strValue & Trim(CType((dr("nombre") / 432) * 100, String)).ToString.Replace(",", ".") & ","
End While
dr.Close()
'Else
'MsgBox("Pas de correspondance")
'pictBox1.Visible = False
'End If
myConnection.Close()
Catch ex As Exception
MsgBox("Get_data_graph", ex.Message)
End Try
End Sub
Enleves juste les notions inutiles, comme les commentaires.
Bonne chance!
Arlys.