MsChart 柱状图前台代码整理

<asp:Chart ID="ctUtilizationBySM" runat="server" BackImageAlignment="TopRight"
                               PaletteCustomColors="IndianRed; DarkSeaGreen; 0, 192, 192; 128, 128, 255; CornflowerBlue; Gold"
                                Width="700px" BackColor="PapayaWhip"    //the width of chart,the backcolor of chart
                                BackGradientStyle="TopBottom" BackImageTransparentColor="White" 
                                BorderlineColor="Black">
                                <Legends>
                                
                                    <asp:Legend BackColor="Transparent" Name="Legend2"  //legend means a tag,this tag is used notfiy column chart
                                        DockedToChartArea="ChartArea1" Alignment="Far" Docking="Top" 
                                        IsDockedInsideChartArea="False"  >
                                         <Position Height="8.026756" Width="15.4154158" X="83.5" Y="3" /> //legend's position
                                        
                                    </asp:Legend>
                                    <asp:Legend BackColor="Transparent" Name="Legend1" 
                                        DockedToChartArea="ChartArea1" Alignment="Far" Docking="Top" 
                                        IsDockedInsideChartArea="False">
                                     
                                        <Position Height="8.026756" Width="15.4154158" X="72.5" Y="3" />
                                     
                                    </asp:Legend>
                                </Legends>
                                <BorderSkin SkinStyle="Emboss" />  //add emboss effect,backgroud effect
                                <Series>// histogram  series                           
		<asp:Series Name="Series1" Color="49,130,239" Legend="Legend1" LegendText="Pre Utl%"
                                        IsValueShownAsLabel="True" Font="Microsoft Sans Serif, 6.5pt" 
                                        ChartArea="ChartArea1"
                                        CustomProperties="DrawingStyle=Cylinder"> //histogrtam's style
                                    </asp:Series>
                                    <asp:Series Name="Series2" Color="255,174,49" Legend="Legend2" LegendText="Utl%" 
                                        IsValueShownAsLabel="True" ChartArea="ChartArea1" 
                                        Font="Microsoft Sans Serif, 6.5pt"
                                        CustomProperties="DrawingStyle=Cylinder">
                                      
                                    </asp:Series>
                                </Series>
                                   
                                <ChartAreas> //inner chart
                                     <asp:ChartArea Name="ChartArea1" BackColor="OldLace"  //inner chart's color
                                        BorderColor="64, 64, 64, 64" ShadowColor="Transparent" 
                                        BackGradientStyle="TopBottom" BackSecondaryColor="White">
                                        <AxisY IsLabelAutoFit="True" LineColor="64, 64, 64, 64">
                                            <MajorGrid LineColor="64, 64, 64, 64" />
                                            <LabelStyle Font="Verdana, 10pt" />
                                            <ScaleBreakStyle LineColor="Transparent" />
                                        </AxisY>// axis y
                                        <AxisX IsLabelAutoFit="False" LabelAutoFitMaxFontSize="8" 
                                            LabelAutoFitMinFontSize="5" LineColor="64, 64, 64, 64">
                                            
                                            <MajorGrid LineColor="64, 64, 64, 64" />
                                            <LabelStyle Font="Verdana, 8pt"  Interval="1" 
                                                IntervalOffset="Auto" IntervalOffsetType="Auto" IntervalType="Number" 
                                                IsStaggered="True"/>
                                            <ScaleBreakStyle LineColor="Transparent" />
                                        </AxisX> // axis x
                                        <AxisX2 IsLabelAutoFit="False">
                                            <MajorGrid Enabled="False" />
                                            <MajorTickMark Enabled="False" /> // cursor
                                            <LabelStyle Font="Microsoft Sans Serif, 5pt" />
                                        </AxisX2>
                                        <Position Height="77.16558" Width="89.43796" X="4.82481766" Y="16.0208549" /> //chart position
                                        <InnerPlotPosition Height="86.9832" Width="90.5838" X="7.0000" Y="1.40178" /> //chart inner position
                                        <Area3DStyle LightStyle="Realistic" WallWidth="2" />
                                    </asp:ChartArea>
                                </ChartAreas>
                            </asp:Chart>  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: MFC是Microsoft Foundation Class的缩写,是一种使用C++语言开发Windows程序的框架。在MFC中,可以使用MSChart控件来绘制柱状图。 首先,需要在MFC的视图类中添加一个MSChart控件。在视图类的头文件中,添加控件变量的声明,如:CChartCtrl m_chartCtrl; 在OnInitDialog()函数中,初始化控件并设置相关属性,例如: m_chartCtrl.Create(WS_CHILD | WS_VISIBLE | WS_TABSTOP, CRect(10, 10, 300, 200), this, IDC_CHART); m_chartCtrl.SetTitle(_T("柱状图")); m_chartCtrl.SetHasTitle(TRUE); m_chartCtrl.SetHasXAxis(TRUE); m_chartCtrl.SetHasYAxis(TRUE); 接下来,可以使用AddData系列函数向图表控件中添加数据。例如,使用AddData系列函数向X轴添加数据: m_chartCtrl.GetChartData().SetXAxisIsCategory(TRUE); m_chartCtrl.GetChartData().SetDimension2D(CChartChartData::X, 0, 7); m_chartCtrl.GetXAxis().SetCount(8); m_chartCtrl.GetXAxis().SetData(0, _T("1月")); m_chartCtrl.GetXAxis().SetData(1, _T("2月")); //... 然后,使用AddSeries()函数来添加要绘制的柱状图系列。例如: m_chartCtrl.GetChartData().AddSeries(CChartChartData::Column, _T("系列1"), _T("数值范围"), 0, 0); m_chartCtrl.GetChartData().AddData(CChartChartData::X, 0, 1, 100); m_chartCtrl.GetChartData().AddData(CChartChartData::X, 1, 1, 200); //... 最后,调用Invalidate()函数来刷新图表控件,使其显示出绘制的柱状图: m_chartCtrl.Invalidate(); 通过以上步骤,可以在MFC中使用MSChart控件绘制柱状图。注意,对于更复杂的图表需求,还可以设置图表的样式、颜色、坐标轴刻度等属性,以满足实际需要。 ### 回答2: MFC是Microsoft Foundation Classes的缩写,是微软公司为开发Windows操作系统的应用程序而提供的一个类库。而MSChart是MFC中的一个图表控件类,可以用于绘制各种类型的图表,包括柱状图。 使用MFC的MSChart来绘制柱状图可以按照以下步骤进行: 1. 首先,需要创建一个MFC应用程序,并包含MSChart控件的头文件,例如"#include <mschart.h>"。 2. 在MFC窗口类的成员变量中添加MSChart控件对象,例如"CChartCtrl m_chartCtrl"。 3. 在资源编辑器中插入一个图表控件,并在类向导中将该图表控件与前面创建的成员变量关联起来。 4. 在窗口类的OnInitDialog()函数中对图表控件进行初始化,例如设置图表的类型为柱状图,通过调用m_chartCtrl.GetChart()获取图表对象,并对图表对象进行相应的设置。 5. 在需要绘制柱状图的位置,通过调用图表对象的AddData()函数添加数据,并可以设置数据的颜色、名称等属性。 6. 最后,通过调用图表对象的Invalidate()函数刷新图表控件,使得柱状图显示在窗口中。 在绘制柱状图的过程中,还可以根据需求对图表进行一些其他的设置,例如设置坐标轴的显示范围、添加图例、设置柱状图的间隔等。 总之,通过MFC的MSChart控件,我们可以方便地实现柱状图的绘制和定制,为数据的可视化分析提供了很好的支持。 ### 回答3: MFC (Microsoft Foundation Class) 是一种用于开发 Windows 程序的C++框架。而MSChart是MFC的一个重要组件,用于绘制各种图表,包括柱状图。 在MFC中使用MSChart绘制柱状图,需要以下步骤: 1. 创建一个MFC项目,并包含MSChart组件库。 2. 在对话框资源中添加一个控件,选择MSChart控件。 3. 在代码中,通过该控件的类指针,调用相关函数来设置柱状图的数据和样式。 4. 通过调用控件的刷新函数,将柱状图显示在对话框上。 例如,以下是一个使用MFC和MSChart绘制柱状图的简单示例: 首先,在对话框资源中添加一个控件,命名为m_chart。 然后,在对话框的头文件中添加一个成员变量,用于访问MSChart控件: CChartCtrl m_chart; 接下来,重写OnInitDialog()函数,并在该函数中初始化m_chart成员变量,并设置柱状图的数据和样式: BOOL CYourDialog::OnInitDialog() { CDialogEx::OnInitDialog(); // 初始化m_chart成员变量 m_chart.Create(WS_CHILD | WS_VISIBLE, CRect(10, 10, 300, 200), this, IDC_CHART); // 设置柱状图标题 m_chart.SetTitle(_T("柱状图")); // 设置X轴标题 m_chart.GetXAxis().SetTitle(_T("X轴")); // 设置Y轴标题 m_chart.GetYAxis().SetTitle(_T("Y轴")); // 添加柱状图数据 m_chart.GetChartData().SetColumnCount(1); m_chart.GetChartData().GetColumn(0).SetData(10, 20, 30, 40, 50); m_chart.GetChartData().SetColumnLabel(0, _T("数据列1")); // 刷新图表 m_chart.Refresh(); return TRUE; } 最后,在资源文件中,为该对话框的OnInitDialog()函数添加响应,并运行程序,就可以在窗口上看到绘制的柱状图了。 以上就是使用MFC和MSChart绘制柱状图的简要步骤和示例。当然,根据实际需求,你还可以进一步自定义和调整柱状图的样式和功能。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值