サンプル投稿用掲示板  VB2005 〜 用トップページ  VB6.0 用 トップページ
- 日時: 2011/04/27 10:35
- 名前: 花ちゃん
  
  - ***********************************************************************************
 * カテゴリー:[チャート][描画・画像][]                                  * * キーワード:Microsoft Chart Controls,散布図,Point,点グラフ,チャート             * *********************************************************************************** 投 稿 日 : 2010/02/28 投 稿 者 : 花ちゃん
  Microsoft Chart Controls for Microsoft .NET(Chartコントロール(VB2008版))を使っての散布図の描画 
  新たに、VB.NET Tips一覧の方に、Microsoft Chart Controls の項を設けて図表付きで詳しく 解説しておりますのでそちらも併せてご覧ください。  http://www.hanatyan.sakura.ne.jp/dotnet/index.html  http://www.hanatyan.sakura.ne.jp/dotnet/chartframe.htm
 
  '=================================================================================================== '動作確認:WindowsVista/WindowsXP VB2008(EE)(VB2005) Framework 3.5  '[Option Compare Text] [Option Explicit On] [Option Infer On] [Option Strict On]で設定 '使用データは、下記よりダウンロードして使って下さい。 'http://www.hanatyan.sakura.ne.jp/bbs_gif/ChartDat2.zip '使用コントロール及び配置は、下図を参照して下さい。 '--------------------------------------------------------------------------------------------------- '========1=========2=========3=========4=========5=========6=========7=========8=========9=========0 Microsoft Chart Controls(VB2008版)を試して見るその1(VB.NET) を試してからこちらをご覧下さい。 (http://www.hanatyan.sakura.ne.jp/patio/read.cgi?no=255) '---------------------------------------------------------------------------------------------------
  Imports System.Data.OleDb
  Public Class Form1
  Private Sub Form1_Load(ByVal sender As System.Object, _                        ByVal e As System.EventArgs) Handles MyBase.Load '-------------------------------------------------------------------------------------- '下記の表示設定は、[http://hanatyan.sakura.ne.jp/patio/read.cgi?no=255]と同じです。    Dim ds As New DataSet    Dim colums As Integer    Using cn As New System.Data.OleDb.OleDbConnection       Dim FolderPath As String = Application.StartupPath()       Dim csvFileName As String = "test1.csv"       cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & FolderPath & _                   ";Extended Properties=""Text;HDR=YES;IMEX=1;FMT=Delimited"""       Using da As System.Data.OleDb.OleDbDataAdapter = _                New System.Data.OleDb.OleDbDataAdapter("SELECT * FROM " & csvFileName, cn)          da.Fill(ds, "Table1")          Chart1.DataSource = ds                       'Chart に表示するデータソースを設定          colums = ds.Tables(0).Columns.Count - 1      'データの系列数を取得       End Using    End Using
  '--------------------------------ここから散布図の表示設定--------------------------------    With Chart1       .Series.Clear()         '系列を初期化       For i As Integer = 0 To colums          'テーブルからデータを取得          Dim x As Integer = CType(ds.Tables(0).Rows(0).Item(i), Integer)          Dim y As Integer = CType(ds.Tables(0).Rows(1).Item(i), Integer)          .Series.Add(CType(i, String))          'グラフの種類をPoint(点グラフ)にして散布図を描画          .Series(CType(i, String)).ChartType = DataVisualization.Charting.SeriesChartType.Point          .Series(CType(i, String)).Points.AddXY(x, y)    'データを設定          .Series(CType(i, String)).MarkerSize = 15       'マーカーを大きくして表示          If i < 5 Then        '正しく表示されているか確認の為ポイントラベルを表示             .Series(CType(i, String)).Label = CStr(i) & ":#VALX" & ",#VALY"          End If       Next       '.Legends(0).Enabled = False     '凡例を非表示にする    End With
     '■------------------- X軸・Y軸のフォント・線等の設定 ----------------Start--■    With Chart1.ChartAreas(0)    'X軸のメモリを自動設定だと中途半端な値になるので別途設定       With .AxisX          .Minimum = 0          .Maximum = 100          .Interval = 20       End With    End With    '■-------------------------------------------------------------------End----■
  End Sub
  End Class
 
  '使用データ ' 50  45  50  60  80  70  40  30  20  90  39  84  77  64  25  90  47  64  74  55 ' 20  80  35  84  25  65  47  88  60  35  70  40  80  15  20  65  50  80  38  20
  上記実行図(体裁部分は一部異なります。)(画像をクリックすると元のサイズで見られます。) 
 
  
  
 |