以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 如何使用多图表 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=184480) |
-- 作者:onlinech -- 发布时间:2022/12/9 17:13:00 -- 如何使用多图表 此主题相关图片如下:图表-002.png 想实现功能: 1、前3列用柱形图,最后1列“本月”用线型 2、取消图表背景的网格 3、鼠标移到到某个柱或点时,例:显示出“x=1月 y=1021600" 代码如下: Dim Chart As WinForm.Chart \'定义一个图表变量 Dim Series As WinForm.ChartSeries \'定义一个图系变量 Chart = e.Form.Controls("Chart1") \' 引用窗口中的图表 Chart.VisualEffect = True \'加上这一行,让你的图表更漂亮 Chart.ChartType = ChartTypeEnum.Bar \'图表1类型该为Bar(条形) Chart.ChartType2 = ChartTypeEnum.bar \'图表2类型该为Bar(条形) Chart.ChartType3 = ChartTypeEnum.bar \'图表3类型该为Bar(条形) Chart.ChartType4 = ChartTypeEnum.XYPlot \'图表4类型该为线形 Chart.DataSource = "统计表1" \'设置绑定表 Chart.SeriesList.Clear() \'清除图表原来的图系 Series = Chart.SeriesList.Add() \'给图表1增加一个图系 For Each c As Col In Tables("统计表1").Cols If c.Name = "净重_1" Then Series = Chart.SeriesList.Add() \'增加一个图系 Series.Text = c.Caption \'设置图系的标题 Series.X.DataField = "时" \'X轴绑定到产品列 Series.Y.DataField = c.Name \'设置Y轴的绑定列 End If Next Chart.SeriesList2.Clear() \'清除图表原来的图系 Series = Chart.SeriesList2.Add() \'给图表2增加一个图系 For Each c As Col In Tables("统计表1").Cols If c.Name = "净重_2" Then Series = Chart.SeriesList.Add() \'增加一个图系 Series.Text = c.Caption \'设置图系的标题 Series.X.DataField = "时" \'X轴绑定到产品列 Series.Y.DataField = c.Name \'设置Y轴的绑定列 End If Next Chart.SeriesList3.Clear() \'清除图表原来的图系 Series = Chart.SeriesList3.Add() \'给图表2增加一个图系 For Each c As Col In Tables("统计表1").Cols If c.Name = "净重_3" Then Series = Chart.SeriesList.Add() \'增加一个图系 Series.Text = c.Caption \'设置图系的标题 Series.X.DataField = "时" \'X轴绑定到产品列 Series.Y.DataField = c.Name \'设置Y轴的绑定列 End If Next Chart.SeriesList4.Clear() \'清除图表原来的图系 Series = Chart.SeriesList4.Add() \'给图表2增加一个图系 For Each c As Col In Tables("统计表1").Cols If c.Name = "净重_4" Then Series = Chart.SeriesList.Add() \'增加一个图系 Series.Text = c.Caption \'设置图系的标题 Series.X.DataField = "时" \'X轴绑定到产品列 Series.Y.DataField = c.Name \'设置Y轴的绑定列 End If Next Chart.LegendVisible = True \'显示图列 Chart.LegendCompass = CompassEnum.South \'图列显示在南方(底端) Chart.AxisY.Text = "净重_1" Chart.AxisY2.Text = "净重_2" Chart.AxisY3.Text = "净重_3" Chart.AxisY4.Text = "净重_4" Chart.AxisX.AnnoWithLabels = True \'启用字符标示 Chart.VisualEffect = True \'加上这一行,让你的图表更漂亮 Chart.LegendVisible = True \'显示图列 Chart.LegendCompass = CompassEnum.South \'图列显示在南方(底端) Series.DataLabelText = "{#YVAL}" Series.Length = 12 \'新增图系包括10个数据点 Series.TooltipText = "X = {#XVAL}, Y = {#YVAL}" For i As Integer = 0 To 11 \'指定每个数据点的位置 Series.X(i) = i \'指定水平坐标 Series.Y(i) = i + Rand.Next(5) \'垂直坐标用随机数生成 Next |
-- 作者:有点蓝 -- 发布时间:2022/12/9 17:23:00 -- Dim Chart As WinForm.Chart \'定义一个图表变量 Dim Series As WinForm.ChartSeries \'定义一个图系变量 Chart = e.Form.Controls("Chart1") \' 引用窗口中的图表 Chart.VisualEffect = True \'加上这一行,让你的图表更漂亮 Chart.ChartType = ChartTypeEnum.Bar \'图表1类型该为Bar(条形) Chart.ChartType2 = ChartTypeEnum.XYPlot \'图表4类型该为线形 Chart.DataSource = "统计表1" \'设置绑定表 Chart.SeriesList.Clear() \'清除图表原来的图系 For Each c As string in {"净重_1","净重_2","净重_3"} Series = Chart.SeriesList.Add() \'增加一个图系 Series.TooltipText = "X = {#XVAL}, Y = {#YVAL}" Series.Text = c \'设置图系的标题 Series.X.DataField = "时" \'X轴绑定到产品列 Series.Y.DataField = c \'设置Y轴的绑定列 Next Chart.SeriesList2.Clear() \'清除图表原来的图系 Series = Chart.SeriesList2.Add() \'增加一个图系 Series.TooltipText = "X = {#XVAL}, Y = {#YVAL}"
Series.X.DataField = "时" \'X轴绑定到月份列 Series.Y.DataField = "净重_3" \'Y轴绑定到数量列 |
-- 作者:onlinech -- 发布时间:2022/12/12 8:36:00 -- 现在还有几点问题:图表4放在最前面,因为有时会被图表1-3的柱形图遮挡 不显示图后面的刻度 不显示主、副刻度(或仅不显示刻度) 图和图例所在位置的颜色可以修改 代码如下: Dim Chart As WinForm.Chart \'定义一个图表变量 Dim Series As WinForm.ChartSeries \'定义一个图系变量 Dim b, x As String \'定义一个字符串变更,用于暂存统计表1的列标题 Chart = e.Form.Controls("Chart1") \' 引用窗口中的图表 Chart.VisualEffect = True \'加上这一行,让你的图表更漂亮 Chart.ChartType = ChartTypeEnum.Bar \'图表1类型为Bar(条形) Chart.ChartType2 = ChartTypeEnum.XYPlot \'图表4类型为线形 Chart.DataSource = "统计表1" \'设置绑定表 Chart.HeaderText = "小时重量对比图" Dim fnt As New Font("宋体", 22, FontStyle.Bold Or FontStyle.Underline) Chart.HeaderFont = fnt Chart.SeriesList.Clear() \'清除图表原来的图系 Chart.BarClusterWidth = 40 \'设置条形图(Bar)所占水平空间的百分比,默认50 \'Chart.AxisY.Major = 1000000 \'主刻度间隔值为50000 \'Chart.AxisY.MajorTick = False \'不在坐标轴轴上显示主刻度 For Each c As String In {"净重_1", "净重_2", "净重_3"} Series = Chart.SeriesList.Add() \'增加一个图系 \' Series.TooltipText = "X = {#XVAL}, Y = {#YVAL}" Select Case c Case "净重_1" b = Tables("统计表1").Cols("净重_1").Caption Case "净重_2" b = Tables("统计表1").Cols("净重_2").Caption Case "净重_3" b = Tables("统计表1").Cols("净重_3").Caption End Select Series.TooltipText = b & "{#XVAL}点, {#YVAL}" Series.Text = b \'设置图系的标题 Series.X.DataField = "时" \'X轴绑定到产品列 Series.Y.DataField = c \'设置Y轴的绑定列 Next Series.Length = 24 \'设置图系的长度 For i As Integer = 0 To 23 \'指定每个数据点的位置 Series.X(i) = i \'指定水平坐标 Series.Y(i) = Tables("统计表1").Rows(i)("净重_1") \'指定垂直坐标 Chart.AxisX.SetValueLabel(i, Tables("统计表1").Rows(i)("时")) \'指定字符表示 Next Chart.SeriesList2.Clear() \'清除图表原来的图系 Chart.AxisY.MinorTick = False \'不在坐标轴轴上显示副刻度 Series = Chart.SeriesList2.Add() \'增加一个图系 Series.TooltipText = "今日{#XVAL}点, {#YVAL}" Series.Text = "今日" \'设置图系的标题 Series.X.DataField = "时" \'X轴绑定到月份列 Series.Y.DataField = "净重_4" \'Y轴绑定到数量列 Chart.LegendVisible = True \'显示图列 Chart.LegendCompass = CompassEnum.South \'图列显示在南方(底端) Chart.AxisX.AnnoWithLabels = True \'启用字符标示 [此贴子已经被作者于2022/12/12 8:48:07编辑过]
|
-- 作者:有点蓝 -- 发布时间:2022/12/12 8:53:00 -- 1、图表4放在最前面 --- 图表4放到第一个图即可 hart.ChartType = ChartTypeEnum.XYPlot \'图表1类型该为Bar(条形) Chart.ChartType2 = ChartTypeEnum.Bar \'图表4类型该为线形 Chart.DataSource = "统计表1" \'设置绑定表 Chart.SeriesList.Clear() \'清除图表原来的图系 Chart.SeriesList2.Clear() \'清除图表原来的图系For Each c As string in {"净重_1","净重_2","净重_3"} Series = Chart.SeriesList2.Add() \'增加一个图系 Series.TooltipText = "X = {#XVAL}, Y = {#YVAL}" Series.Text = c \'设置图系的标题 Series.X.DataField = "时" \'X轴绑定到产品列 Series.Y.DataField = c \'设置Y轴的绑定列 Next Series = Chart.SeriesList.Add() \'增加一个图系 Series.TooltipText = "X = {#XVAL}, Y = {#YVAL}" Series.X.DataField = "时" \'X轴绑定到月份列 Series.Y.DataField = "净重_3" \'Y轴绑定到数量列 |
-- 作者:onlinech -- 发布时间:2022/12/12 10:35:00 -- 1的问题已解决 2、3的问题,不显示图后面的刻度和网络线,未解决 代码1: Chart.HeaderFont = fnt Chart.BarClusterWidth2 = 60 \'设置条形图(Bar)所占水平空间的百分比,默认50 Chart.AxisY2.MinorTick = False \'不在坐标轴轴上显示副刻度 Chart.AxisY2.GridMinorVisible = False \'不显示副刻度的网格线 For Each c As String In {"净重_1", "净重_2", "净重_3"} Series = Chart.SeriesList2.Add() \'图表1-3条形增加一个图系 \' Series.TooltipText = "X = {#XVAL}, Y = {#YVAL}" Select Case c 代码2: Series = Chart.SeriesList.Add() \'图表4线形增加一个图系 Chart.AxisY.MajorTick = False \'不在坐标轴轴上显示主刻度 Chart.AxisY.GridMajorVisible = False \'不显示主刻度的网格线 Series.TooltipText = "今日{#XVAL}点, {#YVAL}" 4的问题,未解决,不是线或柱的颜色,是背景色,就是那个白色的区域 |
-- 作者:有点蓝 -- 发布时间:2022/12/12 10:48:00 -- http://www.foxtable.com/bbs/dispbbs.asp?BoardID=2&ID=48654 |
-- 作者:onlinech -- 发布时间:2022/12/12 11:06:00 -- 我已经增加了下面标颜色的代码,但是2、3的问题,还是未解决,是哪里还有问题吗?实在看不出来了 代码1: Chart.HeaderFont = fnt Chart.BarClusterWidth2 = 60 \'设置条形图(Bar)所占水平空间的百分比,默认50 Chart.AxisY2.MinorTick = False \'不在坐标轴轴上显示副刻度 Chart.AxisY2.GridMinorVisible = False \'不显示副刻度的网格线 For Each c As String In {"净重_1", "净重_2", "净重_3"} Series = Chart.SeriesList2.Add() \'图表1-3条形增加一个图系 \' Series.TooltipText = "X = {#XVAL}, Y = {#YVAL}" Select Case c 代码2: Series = Chart.SeriesList.Add() \'图表4线形增加一个图系 Chart.AxisY.MajorTick = False \'不在坐标轴轴上显示主刻度 Chart.AxisY.GridMajorVisible = False \'不显示主刻度的网格线 Series.TooltipText = "今日{#XVAL}点, {#YVAL}" |
-- 作者:有点蓝 -- 发布时间:2022/12/12 11:10:00 -- 看6楼 |
-- 作者:onlinech -- 发布时间:2022/12/12 11:24:00 -- 背景问题参考6楼已解决,我说的是我已经在代码中增加了下面的代码,但是主、副刻度与网格线仍然存在,实在看不出问题出在哪儿? Chart.AxisY2.MinorTick = False \'不在坐标轴轴上显示副刻度
Chart.AxisY2.GridMinorVisible = False \'不显示副刻度的网格线 Chart.AxisY.MajorTick = False \'不在坐标轴轴上显示主刻度 Chart.AxisY.GridMajorVisible = False \'不显示主刻度的网格线 |
-- 作者:有点蓝 -- 发布时间:2022/12/12 11:30:00 -- Chart.AxisY.MajorTick = False \'不在坐标轴轴上显示主刻度 Chart.AxisY.MinorTick = False \'不在坐标轴轴上显示主刻度 Chart.AxisY.GridMajorVisible = False \'不显示主刻度的网格线 Chart.AxisY.GridMinorVisible = False \'不显示主刻度的网格线AxisY2同样按上面设置
|