C#Chart控件

            DataSet dataSet = new DataSet();
            OleDbConnection conn = new OleDbConnection();
            conn.ConnectionString = @"Provider=Microsoft.Jet.OleDb.4.0;Data Source=" + @"D:\test\data.xls" + ";" +
            "Extended Properties='Excel 8.0;HDR=YES;IMEX=2';";
            conn.Open();
            string ss = "select* from[Student$] ";
            OleDbCommand oleDb = new OleDbCommand(ss, conn);
            OleDbDataReader dbDataReader = oleDb.ExecuteReader();
            this.chart1.Series["Series1"].Points.DataBindXY(dbDataReader, "name", dbDataReader, "age");

            this.chart1.Titles.Add("学生年龄分布");//标题
            this.chart1.ChartAreas[0].Axes[0].MajorGrid.Enabled = true;//X轴上网格
            this.chart1.ChartAreas[0].Axes[1].MajorGrid.Enabled = false;//Y轴上网格
            this.chart1.ChartAreas[0].Axes[0].MajorGrid.LineDashStyle=ChartDashStyle.Dash;   //网格类型 短横线
            this.chart1.ChartAreas[0].Axes[0].MajorGrid.LineColor = Color.Red;
            this.chart1.ChartAreas[0].Axes[0].MajorTickMark.Enabled = false;                //  x轴上突出的小点
            this.chart1.ChartAreas[0].Axes[1].LabelStyle.Format = "#岁";
            this.chart1.ChartAreas[0].Axes[0].LineWidth = 3;

            this.chart1.Series["Series1"].ToolTip = "#VALX年\r#VAL";//鼠标提示
            this.chart1.Series["Series1"].ChartType = SeriesChartType.Line;

            this.chart1.Series["Series1"].Color = Color.Red;               //线条颜色
            this.chart1.Series["Series1"].BorderWidth = 3;                 //线条粗细
            this.chart1.Series["Series1"].MarkerBorderColor = Color.Red;   //标记点边框颜色
            this.chart1.Series["Series1"].MarkerBorderWidth = 3;             //标记点边框大小
            this.chart1.Series["Series1"].MarkerColor = Color.Red;       //标记点中心颜色
            this.chart1.Series["Series1"].MarkerSize = 5;                 //标记点大小
            this.chart1.Series["Series1"].MarkerStyle = MarkerStyle.Circle;  //标记点类型
            conn.Close();

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
C#Chart控件是微软自带的一个图形可视化组件,可以在Web程序和窗体程序中使用。在.NET4.0之后的版本中,Chart控件已经集成在Visual Studio中,不需要手动安装。你可以在工具箱中找到"数据"控件,里面就有一个Chart控件,你可以直接拖动到窗体中使用。默认情况下,会创建一个名为chart1的实例对象。\[1\] 如果你想了解更多关于Winform控件的介绍和示例,你可以参考一些网址,比如: - https://docs.devexpress.com/WindowsForms/17530/controls-and-libraries/spreadsheet/examples/charts/how-to-show-or-hide-the-chart-legend - https://blog.csdn.net/zhouyingge1104/article/details/105504889 - https://blog.csdn.net/quanlver/article/details/83035998 - https://blog.csdn.net/qq_27825451/article/details/81305387 - https://www.cnblogs.com/arxive/p/5861960 - https://blog.csdn.net/xianfajushi/article/details/7493697 在使用Chart控件时,你可以使用一些方法来绑定数据,比如: - DataBind方法可以将数据源绑定到Chart控件的Series上,可以使用不同的参数组合来绑定不同的数据。 - DataBindXY方法可以将一组X和Y的值绑定到一个Series上。 - DataBindY方法可以将一组Y的值绑定到一个Series上。 例如,你可以使用以下代码将一组X和Y的值绑定到名为"Series1"的Series上: chart1.Series\["Series1"\].Points.DataBindXY(x, y)。\[3\] 希望这些信息对你有帮助! #### 引用[.reference_title] - *1* *3* [c# chart图表控件总结](https://blog.csdn.net/a843538946/article/details/103048471)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [C# chart控件使用方法](https://blog.csdn.net/u012719076/article/details/108192562)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值