zoukankan      html  css  js  c++  java
  • MSChart参考

    MSChart在vs2008中使用遇到一个问题,坐标轴的标题为中文时被图表区域遮挡了一部分.

    解决办法:在说明文字前加 实现换一行显示.

        //this.Chart1.ChartAreas[0].AxisX.LabelStyle.Angle =-90;//x轴倾斜的角度。

    //设置坐标轴交错显示
    //chartFreq.ChartAreas["ChartArea1"].AxisX.LabelStyle.IsStaggered = true;

    //legend文字设置,Series的label文字设置,Series的label的Tooltip文字设置

    LegendText="#VALX" Label="#PERCENT{P1}" LabelToolTip="#VALX"

    //前台设置,交错和文字角度.--IsStaggered="True" Angle="90"

    <AxisX LineColor="64, 64, 64, 64" Interval="1.0" IsLabelAutoFit="False">
    <LabelStyle Font="宋体, 13px" IsStaggered="True" Angle="90" />
    <MajorGrid LineColor="64, 64, 64, 64" />
    </AxisX>

    X轴坐标如果超过9位的话,就不能完全显示了,就会一个隔一个的显示,这样让人很不爽,其实只要进行如下设置:

        Chart1.ChartAreas[0].AxisX.Interval = 1;   //设置X轴坐标的间隔为1
        Chart1.ChartAreas[0].AxisX.IntervalOffset = 1;  //设置X轴坐标偏移为1
        Chart1.ChartAreas[0].AxisX.LabelStyle.IsStaggered = true;   //设置是否交错显示,比如数据多的时间分成两行来显示 

    官方文档:

    http://msdn.microsoft.com/zh-cn/library/dd489237(v=vs.100).aspx

    园友博客:

    http://www.cnblogs.com/shuncy/archive/2008/11/07/1328738.html

    http://www.cnblogs.com/shuncy/archive/2008/11/10/1330827.html

    官方示例:

    http://archive.msdn.microsoft.com/mschart

    转:简介

    http://blog.csdn.net/gzy11/article/details/5190228

    参考一:

    mschart总结:

    1. mschart的坐标轴默认类型为decimal,所以不能太大。

    2. 可以为每个点添加提示信息;
        /// <summary>
        /// 设置点提示信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void chartCWPBestMode_PreRender(object sender, EventArgs e)
        {
            for (int i = 0; i < chartCWPBestMode.Series["Series1"].Points.Count; i++)
            {
                chartCWPBestMode.Series["Series1"].Points[i].ToolTip = i.ToString();
            }
        }

    3.再每次加载数据时先清空曲线,防止页面刷新后曲线重叠。
       
            chartCWPBestMode.Series["Series1"].Points.Clear();
            chartCWPBestMode.Series["Series2"].Points.Clear();
            chartCWPBestMode.Series["Series3"].Points.Clear();
            chartCWPBestMode.Series["Series4"].Points.Clear();

    4.以下是我在做的时候控制样式时用到的方法
         /// <summary>
        /// 设置mschart样式
        /// </summary>
        private void SetMSChartStyle()
        {
            //绘图前期处理
            chartCWPBestMode.Titles.Clear();

            //标题设置
            Title title = new Title();
            title.Text = "循环水泵最佳运行方式";
            title.Font = new Font("宋体", 16f, FontStyle.Bold);
            //标题
            chartCWPBestMode.Titles.Add(title);

            // 坐标轴设置
            chartCWPBestMode.ChartAreas["ChartAreaCWP"].AxisY.IsMarginVisible = false;

            //X 轴坐标最大最小值
            chartCWPBestMode.ChartAreas["ChartAreaCWP"].AxisX.Minimum = 5;
            chartCWPBestMode.ChartAreas["ChartAreaCWP"].AxisX.Maximum = 35;

            // 坐标轴刻度线不延长出来设置
            chartCWPBestMode.ChartAreas["ChartAreaCWP"].AxisX.MajorTickMark.Enabled = false;
            chartCWPBestMode.ChartAreas["ChartAreaCWP"].AxisY.MajorTickMark.Enabled = false;

            //X 次要辅助线设置
            chartCWPBestMode.ChartAreas["ChartAreaCWP"].AxisX.MinorGrid.Enabled = true;
            //X 次要辅助线间距
            chartCWPBestMode.ChartAreas["ChartAreaCWP"].AxisX.MinorGrid.Interval = 1;
            //X 次要辅助线颜色
            chartCWPBestMode.ChartAreas["ChartAreaCWP"].AxisX.MinorGrid.LineColor = Color.LightGray;

            //Y 次要辅助线设置
            chartCWPBestMode.ChartAreas["ChartAreaCWP"].AxisY.MinorGrid.Enabled = true;
            //Y 次要辅助线间距
            chartCWPBestMode.ChartAreas["ChartAreaCWP"].AxisY.MinorGrid.Interval = 10;
            //Y 次要辅助线颜色
            chartCWPBestMode.ChartAreas["ChartAreaCWP"].AxisY.MinorGrid.LineColor = Color.LightGray;

            //X 主要辅助线设置
            chartCWPBestMode.ChartAreas["ChartAreaCWP"].AxisX.MajorGrid.Enabled = true;
            //X 主要辅助线间距
            chartCWPBestMode.ChartAreas["ChartAreaCWP"].AxisX.MajorGrid.Interval = 5;
            //X 主要辅助线颜色
            chartCWPBestMode.ChartAreas["ChartAreaCWP"].AxisX.MajorGrid.LineColor = Color.Black;

            //Y 主要辅助线设置
            chartCWPBestMode.ChartAreas["ChartAreaCWP"].AxisY.MajorGrid.Enabled = true;
            //Y 主要辅助线间距
            chartCWPBestMode.ChartAreas["ChartAreaCWP"].AxisY.MajorGrid.Interval = 30;
            //Y 主要辅助线颜色
            chartCWPBestMode.ChartAreas["ChartAreaCWP"].AxisY.MajorGrid.LineColor = Color.Black;

            //坐标主要辅助线刻度间距
            chartCWPBestMode.ChartAreas["ChartAreaCWP"].AxisX.Interval = 5;
            chartCWPBestMode.ChartAreas["ChartAreaCWP"].AxisY.Interval = 30;

            //坐标轴说明
            chartCWPBestMode.ChartAreas["ChartAreaCWP"].AxisX.Title = "凝汽器冷却水进口温度(℃)";
            chartCWPBestMode.ChartAreas["ChartAreaCWP"].AxisY.Title = "机组负荷(MW)";
            chartCWPBestMode.ChartAreas["ChartAreaCWP"].AxisX.TitleFont = new Font("宋体", 10f, FontStyle.Bold);
            chartCWPBestMode.ChartAreas["ChartAreaCWP"].AxisY.TitleFont = new Font("宋体", 10f, FontStyle.Bold);
            chartCWPBestMode.ChartAreas["ChartAreaCWP"].AxisX.TitleAlignment = StringAlignment.Far;
            chartCWPBestMode.ChartAreas["ChartAreaCWP"].AxisY.TitleAlignment = StringAlignment.Far;

            //边框样式设置
            chartCWPBestMode.ChartAreas["ChartAreaCWP"].BorderColor = Color.Black;
            chartCWPBestMode.ChartAreas["ChartAreaCWP"].BorderDashStyle = ChartDashStyle.Solid;
            chartCWPBestMode.ChartAreas["ChartAreaCWP"].BorderWidth = 2;

            //图例文字
            chartCWPBestMode.Series["SeriesCurrentMode"].LegendText = "当前运行方式";
            chartCWPBestMode.Series["SeriesTRAN1"].LegendText = "单泵高速切换曲线";
            chartCWPBestMode.Series["SeriesTRAN2"].LegendText = "两机三泵切换曲线";
            chartCWPBestMode.Series["SeriesTRAN3"].LegendText = "一高一低切换曲线";
            chartCWPBestMode.Series["SeriesTRAN4"].LegendText = "两泵高速切换曲线";

            //图例位置、字体设置;坐标轴位置设定
            chartCWPBestMode.Legends[0].Position = new ElementPosition(10, 10, 88, 7);
            chartCWPBestMode.Legends[0].Font = new Font("宋体", 9);
            chartCWPBestMode.ChartAreas[0].InnerPlotPosition = new ElementPosition(6, 5, 90, 82);
        }

    5.附MSChart属性列表

     

    ChartAreas:增加多个绘图区域,每个绘图区域包含独立的图表组、数据源,用于多个图表类型在一个绘图区不兼容时。

     

    AlignmentOrientation:图表区对齐方向,定义两个绘图区域间的对齐方式。

    AlignmentStyle:图表区对齐类型,定义图表间用以对其的元素。

    AlignWithChartArea:参照对齐的绘图区名称。

    InnerPlotPosition:图表在绘图区内的位置属性。

    Auto:是否自动对齐。

    Height:图表在绘图区内的高度(百分比,取值在0-100

    Width:图表在绘图区内的宽度(百分比,取值在0-100

    X,Y:图表在绘图区内左上角坐标

    Position:绘图区位置属性,同InnerPlotPosition

    Name:绘图区名称。

    Axis:坐标轴集合

    Title:坐标轴标题

    TitleAlignment:坐标轴标题对齐方式

    Interval:轴刻度间隔大小

    IntervalOffset:轴刻度偏移量大小

    MinorGrid:次要辅助线

     

    MinorTickMark:次要刻度线

    MajorGrid:主要辅助线

    MajorTickMark:主要刻度线

     

    DataSourceIDMSChart的数据源。

    Legends:图例说明。

    Palette:图表外观定义。

    Series:最重要的属性,图表集合,就是最终看到的饼图、柱状图、线图、点图等构成的合;可以将多种相互兼容的类型放在一个绘图区域内,形成复合图。

     

    IsValueShownAsLabel:是否显示数据点标签,如果为true,在图表中显示每一个数据值

    Label:数据点标签文本

    LabelFormat:数据点标签文本格式

    LabelAngle:标签字体角度

    Name:图表名称

    Points:数据点集合

    XValueType:横坐标轴类型

    YValueType:纵坐标轴类型

    XValueMember:横坐标绑定的数据源(如果数据源为Table,则填写横坐标要显示的字段名称)

    YValueMembers:纵坐标绑定的数据源(如果数据源为Table,则填写纵坐标要显示的字段名称,纵坐标可以有两个)

    ChartArea:图表所属的绘图区域名称

    ChartType:图表类型(柱形、饼形、线形、点形等)

    Legend:图表使用的图例名称

    Titles:标题集合。

    widthMSChart的宽度。

    heightMSChart的高度。

     注意:清空MSchart方法.

            如果在同一个页面中显示不同的曲线。在曲线切换时会出现MSchart设置不能正确初始化。

          方法是:在HTML中不能写死<ChartAreas>等,必须在程序中动态添加。

        如:mschart.Series.Add("1");
            mschart.Series.Add("2");

           mschart.ChartAreas.Add("11");

        使用前必须

           mschart.Series.Clear();
           mschart.ChartAreas.Clear();

     

    参考二:

    //1.设置Chart1的相关属性

                //给X,Y轴赋标题(注释)
                Chart1.ChartAreas["ChartArea1"].AxisX.Title = "时间";
                Chart1.ChartAreas["ChartArea1"].AxisY.Title = "数值";

                //设置表数据对象属于哪个绘图区--默认series都属于第一个绘图区
                Chart1.Series["Series3"].ChartArea = "ChartArea2";


                //指点图标元素的渐变样式--中心向外,从左到右,从上到下
                Chart1.BackGradientStyle = System.Web.UI.DataVisualization.Charting.GradientStyle.TopBottom;

                //设置图表的背景颜色
                Chart1.BackColor = System.Drawing.Color.Gray;

                //设置背景的辅助颜色
                Chart1.BackSecondaryColor = Color.White;

                //设置图像边框颜色
                Chart1.BorderlineColor = Color.Green; ;

                //设置图像边框线的样式--实线,虚线,点线
                Chart1.BorderlineDashStyle = System.Web.UI.DataVisualization.Charting.ChartDashStyle.Solid;

                //设置边框线的宽度
                Chart1.BorderlineWidth = 2;

                //设置图片的边框的外观样式
                Chart1.BorderSkin.SkinStyle = System.Web.UI.DataVisualization.Charting.BorderSkinStyle.Emboss;

                //2.数据样式
                //设置颜色
                Chart1.Series["Series1"].Color = System.Drawing.Color.Red;

                //设置图表的类型
                Chart1.Series["Series1"].ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Line;

                //设置是否在chart中显示坐标点值
                Chart1.Series["Series1"].IsValueShownAsLabel = true;

                //设置数据边框颜色
                Chart1.Series["Series1"].BorderColor = System.Drawing.Color.Yellow;

                //设置数据的颜色
                Chart1.Series["Series1"].Color = System.Drawing.Color.Blue;

                //设置数据的名称
                Chart1.Series["Series1"].Name = "数据1";

                //设置阴影偏移量
                Chart1.Series["Series1"].ShadowOffset = 1;

                //设置阴影颜色
                Chart1.Series["Series1"].ShadowColor = System.Drawing.Color.PaleGreen;

                //3.设置图表区域样式--Position/InnerPlotPosition
                //图表区域名字
                Chart1.ChartAreas["ChartArea1"].Name = "图表区域";

                //设置是否自动设置合适的图表元素
                Chart1.ChartAreas["ChartArea1"].Position.Auto = true;

                //设置图表的阴影颜色
                Chart1.ChartAreas["ChartArea1"].ShadowColor = System.Drawing.Color.YellowGreen;

                //设置图表元素左上角对应的X、Y坐标
                Chart1.ChartAreas["ChartArea1"].Position.X = 5.089137f;
                Chart1.ChartAreas["ChartArea1"].Position.Y = 5.89765f;

                //设置图表远的高、宽
                Chart1.ChartAreas["ChartArea1"].Position.Height = 86.760f;
                Chart1.ChartAreas["ChartArea1"].Position.Width = 88f;

                //设置是否在内部绘图区域中自动设置合适的图表元素
                Chart1.ChartAreas["ChartArea1"].InnerPlotPosition.Auto = false;

                //设置图表元素内部绘图区域的高、宽
                Chart1.ChartAreas["ChartArea1"].InnerPlotPosition.Height = 85f;
                Chart1.ChartAreas["ChartArea1"].InnerPlotPosition.Width = 96f;

                //设置图表元素内部绘图区域左上角对应的X,Y坐标
                Chart1.ChartAreas["ChartArea1"].InnerPlotPosition.X = 8.693f;
                Chart1.ChartAreas["ChartArea1"].InnerPlotPosition.Y = 5.6257f;

                //3.设置图表区域样式--3D效果
                //设置是否显示3D效果
                Chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;

                //设置三维图表的旋转角度
                Chart1.ChartAreas["ChartArea1"].Area3DStyle.Inclination = 10;

                //设置条形图或柱状图的数据系列是否为簇状
                Chart1.ChartAreas["ChartArea1"].Area3DStyle.IsClustered = true;

                //设置图表区域是否使用等角投影显示
                Chart1.ChartAreas["ChartArea1"].Area3DStyle.IsRightAngleAxes = true;

                //设置图表的照明类型--(色调随旋转角度改变而改变,不应用照明,色调补改变)
                Chart1.ChartAreas["ChartArea1"].Area3DStyle.LightStyle =
                    System.Web.UI.DataVisualization.Charting.LightStyle.Realistic;

                //设置三维图区的透视百分比
                Chart1.ChartAreas["ChartArea1"].Area3DStyle.Perspective = 60;

                //设置三维图表区域绕垂直轴旋转的角度
                Chart1.ChartAreas["ChartArea1"].Area3DStyle.Rotation = 60;

                //设置三位图区显示的墙的宽度
                Chart1.ChartAreas["ChartArea1"].Area3DStyle.WallWidth = 2;

                //3.设置图表区域样式--坐标
                //设置X轴是否自动调整轴标签
                Chart1.ChartAreas["ChartArea1"].AxisX.IsLabelAutoFit = false;

                //设置X轴下方提示信息的字体属性
                Chart1.ChartAreas["ChartArea1"].AxisX.LabelStyle.Font =
                    new System.Drawing.Font("微软雅黑", 8.25f, System.Drawing.FontStyle.Bold);

                //设置标签文本中格式字符串
                Chart1.ChartAreas["ChartArea1"].AxisX.LabelStyle.Format="";

                //设置标签间隔大小
                Chart1.ChartAreas["ChartArea1"].AxisX.LabelStyle.Interval=5d;

                //设置间隔大小的衡量单位(有:自动,年,月,日,天,星期,时,分,秒,数字)
                Chart1.ChartAreas["ChartArea1"].AxisX.LabelStyle.IntervalType=
                    System.Web.UI.DataVisualization.Charting.DateTimeIntervalType.Number;

                //设置X轴的线条颜色
                        Chart1.ChartAreas["ChartArea1"].AxisX.LineColor=System.Drawing.Color.Violet;

                //设置主网格和次网格的间隔
                Chart1.ChartAreas["ChartArea1"].AxisX.MajorGrid.Interval=50d;

                //设置主网格和次网格间隔的衡量单位
                Chart1.ChartAreas["ChartArea1"].AxisX.MajorGrid.IntervalType=
                    System.Web.UI.DataVisualization.Charting.DateTimeIntervalType.Number;

                //设置主网格的颜色
                Chart1.ChartAreas["ChartArea1"].AxisX.MajorGrid.LineColor=Color.Salmon;

                //设置刻度线的间隔
                Chart1.ChartAreas["ChartArea1"].AxisX.MajorTickMark.Interval=7d;

                //设置刻度线间隔的衡量单位
                Chart1.ChartAreas["ChartArea1"].AxisX.MajorTickMark.IntervalType=
                    System.Web.UI.DataVisualization.Charting.DateTimeIntervalType.Number;

                //设置X轴是否自动调整轴标签
                Chart1.ChartAreas["ChartArea1"].AxisX.IsLabelAutoFit = false;

                //设置是否自动将数据值均为正轴的最小值设置为0,存在负数值时,将使用数据轴最小值
                Chart1.ChartAreas["ChartArea1"].AxisX.IsStartedFromZero=false;

               //Y轴同X轴,同上

                //设置Y轴最大、最小值
                Chart1.ChartAreas["ChartArea1"].AxisY.Maximum = 100;
                Chart1.ChartAreas["ChartArea1"].AxisY.Minimum = 0;

                //4.图例样式
                //图例对齐方式--中间对齐,靠近边缘对齐,远离远点对齐
                Chart1.Legends["Legend1"].Alignment = System.Drawing.StringAlignment.Near;

                //图例背景颜色
                Chart1.Legends["Legend1"].BackColor=Color.Silver;

                //设置图例要停靠在哪个区域上
                Chart1.Legends["Legend1"].DockedToChartArea="ChartArea1";

                //设置图例停靠在图表区域的位置(顶部,底部,左侧,右侧)
                Chart1.Legends["Legend1"].Docking=System.Web.UI.DataVisualization.Charting.Docking.Bottom;

                //设置图例字体属性
                Chart1.Legends["Legend1"].Font=new System.Drawing.Font("换文行楷",6.6f);

                //设置图例文本是否可以自动调整大小
                Chart1.Legends["Legend1"].IsTextAutoFit = false;

                //设置显示图例项方式--列,行,表格
                Chart1.Legends["Legend1"].LegendStyle = System.Web.UI.DataVisualization.Charting.LegendStyle.Column;

  • 相关阅读:
    微服务架构中的熔断 VS 股票市场中的熔断
    通过异常处理错误
    Java之GC 如何工作
    HBase学习笔记
    日志打印的正确姿势
    告别if/else连环写法
    下载resource下的excel文件
    get请求和post请求参数中文乱码的解决办法
    jquery基础
    45度炸队Alpha冲刺博客集
  • 原文地址:https://www.cnblogs.com/fumj/p/3227367.html
Copyright © 2011-2022 走看看