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);
    }

https://www.cnblogs.com/ashou706/archive/2010/06/01/1749257.html

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值