http://www.bcap.co.jp/hanafusa/VBHLP/mscsono2.htm
グラフのタイプを変更・データポイントラベル・凡例・マーカの表示設定(その2)
これでいかがでしょうか
Yahoo! JAPAN
URLはダミーです。
興味があったのでやってみました。
これで試してみてください。(^^
Dim arrValues(1 To 6)
Dim i As Integer
Me.MSChart1.chartType = 14
Me.MSChart1.Row = 1
Me.MSChart1.Column = 1
Me.MSChart1.RowLabel = ”test”
lowerbound = 30
upperbound = 50
Me.MSChart1.Plot.Backdrop.Fill.Brush.FillColor.Automatic = False
Me.MSChart1.Plot.Backdrop.Fill.Brush.FillColor.Set 255, 255, 255
Me.MSChart1.Plot.Backdrop.Fill.Brush.Style = VtFillStyleBrush
arrValues(1) = ”test” ’ ラベル指定
arrValues(2) = Int((upperbound - lowerbound + 1) * Rnd + lowerbound) ’ 系列 1 の値
arrValues(3) = Int((upperbound - lowerbound + 1) * Rnd + lowerbound) ’ 系列 2 の値
arrValues(4) = Int((upperbound - lowerbound + 1) * Rnd + lowerbound) ’ 系列 3 の値
arrValues(5) = Int((upperbound - lowerbound + 1) * Rnd + lowerbound) ’ 系列 4 の値
arrValues(6) = Int((upperbound - lowerbound + 1) * Rnd + lowerbound) ’ 系列 5 の値
For i = 1 To 5
Me.MSChart1.Plot.SeriesCollection(i).DataPoints(-1).DataPointLabel.LocationType = VtChLabelLocationTypeAbovePoint
Me.MSChart1.Plot.SeriesCollection(i).DataPoints(-1).DataPointLabel.Component = VtChLabelComponentSeriesName
Me.MSChart1.Plot.SeriesCollection(i).DataPoints(-1).DataPointLabel.VtFont.VtColor.Set 1, 1, 1
Next
Me.MSChart1.Plot.SeriesCollection(1).DataPoints(-1).Brush.FillColor.Set 255, 0, 0
Me.MSChart1.Plot.SeriesCollection(2).DataPoints(-1).Brush.FillColor.Set 255, 255, 0
Me.MSChart1.Plot.SeriesCollection(3).DataPoints(-1).Brush.FillColor.Set 0, 255, 64
Me.MSChart1.Plot.SeriesCollection(4).DataPoints(-1).Brush.FillColor.Set 0, 255, 255
Me.MSChart1.Plot.SeriesCollection(5).DataPoints(-1).Brush.FillColor.Set 0, 128, 192
Me.MSChart1.Plot.SeriesCollection(1).LegendText = ”商品1”
Me.MSChart1.Plot.SeriesCollection(2).LegendText = ”商品2”
Me.MSChart1.Plot.SeriesCollection(3).LegendText = ”商品3”
Me.MSChart1.Plot.SeriesCollection(4).LegendText = ”商品4”
Me.MSChart1.Plot.SeriesCollection(5).LegendText = ”商品5”
Me.MSChart1.ShowLegend = True
MSChart1.Plot.Axis(VtChAxisIdX).Labels(1).Auto = False
MSChart1.Plot.Axis(VtChAxisIdX).Labels(1).TextLayout.VertAlignment = VtVerticalAlignmentCenter
MSChart1.Plot.Axis(VtChAxisIdX).Labels(1).TextLayout.HorzAlignment = VtHorizontalAlignmentCenter
MSChart1.ChartData = arrValues
Me.MSChart1.Plot.SeriesCollection(i).DataPoints(-1).DataPointLabel.LocationType = VtChLabelLocationTypeAbovePoint
データ範囲を超えたエラーが出ますが・・
Yahoo!オークション
あ、すみません。
最後の一行消してください。
このままだとCドライブ直下に画像吐き出します…。
あれ質問よく見ると「凡例ではなくて」ですか、もしかしてちょっとずれてますか?
http://www.hondarer-soft.com/cx/pukiwiki/pukiwiki.php?Memo%2F200...
[hondarer-soft] to [cx20.main.jp]
試しにコードを書いてみました。
残念ながら「国語/50点」という書式がうまくいかなかった為、
「国語 50」としています。
ご希望の動作になっていないようでしたら、ポイントは結構です。
Private Sub Command1_Click()
With MSChart1
’ 円グラフを指定
.chartType = VtChChartType2dPie
’ テストデータ
For i = 1 To 4
.Row = 1
.Column = i
.Data = i * 100
Next
With .DataGrid
.RowLabelCount = 1
.ColumnCount = 4
.RowCount = 1
For i = 1 To .ColumnCount
.ColumnLabel(i, 1) = ”Column ” & i
Next i
.RowLabel(1, 1) = ”成績グラフ”
End With
’ 項目の表示内容のカスタマイズ
For i = 1 To .Plot.SeriesCollection.Count
With .Plot.SeriesCollection(i).DataPoints(-1).DataPointLabel
’ ラベルはパイのスライスの内部に表示されます。
.LocationType = VtChLabelLocationTypeInside
’ データ ポイントの値がラベルに表示されます。
.Component = VtChLabelComponentValue
Select Case i
Case 1
.ValueFormat = ”国語 0”
Case 2
.ValueFormat = ”算数 0”
Case 3
.ValueFormat = ”理科 0”
Case 4
.ValueFormat = ”社会 0”
End Select
End With
Next i
End With
End Sub
http://support.microsoft.com/?kbid=230484
How To Label Pie Slices as Percentages in MSChart Pie Chart
参考情報です。
参考情報です。
お世話になりました。ほぼ、網羅されています。
もう少しいろいろやって見ます。
http://www.watch.impress.co.jp/akiba/
AKIBA PC Hotline!
LEDです。
2回書いてしまったので同一IDで回答できないため、こちらで補足させて頂きます。
最初の方に以下を入れてください。
Me.MSChart1.ColumnCount = 5
有り難うございました。OKです。
実は今、このHPを参照して実験しています。
この例では円グラフの円の中に文字は書けないようでした。