• 大小: 94KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-20
  • 语言: C#
  • 标签: C#  Chart控件  滚动条  

资源简介

本资源主要为c#中使用chart控件绘制曲线图,当数据量较大时,x轴出现滚动条,实现全局视图和滚动视图的功能

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;

namespace test_chart
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender EventArgs e)
        {
            InitChart();

            for (int i = 0; i < 3; i++)
            {
                AddSeries(r.Next(1100).ToString() Color.Red);
            }
        }
        static int range = 0;
        Random r = new Random(6);

        private void AddSeries(string seriersName Color serierscolor)
        {
            Series series = new Series(seriersName);
            //图表类型  设置为样条图曲线
            series.ChartType = SeriesChartType.Line;
            series.IsXValueIndexed = true;
            series.XValueType = ChartValueType.Time;
            series.Markerstyle = Markerstyle.Circle;
            series.MarkerColor = Color.Black;
            //设置点的大小
            series.MarkerSize = 5;
            //设置曲线的颜色
            series.Color = serierscolor;
            //设置曲线宽度
            series.BorderWidth = 2;
            series.CustomProperties = “PointWidth=2“;
            series.IsValueShownAsLabel = true;
            chart.Series.Add(series);
        }


        private void CreateChart()
        {
            ChartArea chartArea = new ChartArea();
            //chartArea.Name = “FirstArea“;

            chartArea.CursorX.IsUserEnabled = true;
            chartArea.CursorX.IsUserSelectionEnabled = true;
            chartArea.CursorX.SelectionColor = Color.SkyBlue;
            chartArea.CursorY.IsUserEnabled = true;
            chartArea.CursorY.AutoScroll = true;
            chartArea.CursorY.IsUserSelectionEnabled = true;
            chartArea.CursorY.SelectionColor = Color.SkyBlue;

            chartArea.CursorX.IntervalType = DateTimeIntervalType.Auto;
            chartArea.AxisX.ScaleView.Zoomable = false;
            chartArea.AxisX.ScrollBar.Buttonstyle = ScrollBarButtonstyles.All;//启用X轴滚动条按钮

            chartArea.BackColor = Color.BlueViolet;                      //背景色
            chartArea.BackSecondaryColor = Color.White;                 //渐变背景色
            chartArea.BackGradientstyle = Gradientstyle.TopBottom;      //渐变方式
            chartArea.BackHatchstyle = ChartHatchstyle.None;            //背景阴影
            chartArea.BorderDashstyle = ChartDashstyle.NotSet;          //边框线样式
            chartArea.BorderWidth = 1;                                  //边框宽度
            chartArea.BorderColor = Color.Black;

            //chartArea.AxisX.
            chartArea.AxisX.MajorGrid.Enabled = true;
            chartArea.AxisY.MajorGrid.Enabled = true;

            // Axis
            chartArea.AxisY.title = @“Value“;

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      14336  2018-10-24 10:05  test_chart\test_chart\bin\Debug\test_chart.exe

     文件      28160  2018-10-24 10:05  test_chart\test_chart\bin\Debug\test_chart.pdb

     文件      14328  2018-10-24 10:06  test_chart\test_chart\bin\Debug\test_chart.vshost.exe

     文件        490  2009-06-11 05:14  test_chart\test_chart\bin\Debug\test_chart.vshost.exe.manifest

     文件       7748  2018-06-01 09:47  test_chart\test_chart\Form1.cs

     文件       4141  2018-06-01 09:27  test_chart\test_chart\Form1.Designer.cs

     文件       6003  2018-06-01 09:27  test_chart\test_chart\Form1.resx

     文件       6034  2018-05-25 11:12  test_chart\test_chart\obj\Debug\ResolveAssemblyReference.cache

     文件        953  2018-10-24 10:06  test_chart\test_chart\obj\Debug\test_chart.csproj.FileListAbsolute.txt

     文件        847  2018-06-01 09:27  test_chart\test_chart\obj\Debug\test_chart.csproj.GenerateResource.Cache

     文件      14336  2018-10-24 10:05  test_chart\test_chart\obj\Debug\test_chart.exe

     文件        180  2018-10-24 10:05  test_chart\test_chart\obj\Debug\test_chart.Form1.resources

     文件      28160  2018-10-24 10:05  test_chart\test_chart\obj\Debug\test_chart.pdb

     文件        180  2018-10-24 10:05  test_chart\test_chart\obj\Debug\test_chart.Properties.Resources.resources

     文件        491  2018-05-25 11:07  test_chart\test_chart\Program.cs

     文件       1370  2018-05-25 11:07  test_chart\test_chart\Properties\AssemblyInfo.cs

     文件       2870  2018-05-25 11:07  test_chart\test_chart\Properties\Resources.Designer.cs

     文件       5612  2018-05-25 11:07  test_chart\test_chart\Properties\Resources.resx

     文件       1095  2018-05-25 11:07  test_chart\test_chart\Properties\Settings.Designer.cs

     文件        249  2018-05-25 11:07  test_chart\test_chart\Properties\Settings.settings

     文件       3866  2018-05-25 11:12  test_chart\test_chart\test_chart.csproj

     文件        920  2018-05-25 11:08  test_chart\test_chart.sln

    ..A..H.     16384  2018-10-24 10:06  test_chart\test_chart.suo

     文件      15360  2018-10-24 10:07  WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\windowsformsapplication1.exe

     文件      30208  2018-10-24 10:07  WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.pdb

     文件      14328  2018-10-24 10:07  WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.vshost.exe

     文件        490  2009-06-11 05:14  WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.vshost.exe.manifest

     文件       8890  2018-05-25 17:02  WindowsFormsApplication1\WindowsFormsApplication1\Form2.cs

     文件       4376  2018-05-25 16:49  WindowsFormsApplication1\WindowsFormsApplication1\Form2.Designer.cs

     文件       6003  2018-05-25 16:49  WindowsFormsApplication1\WindowsFormsApplication1\Form2.resx

............此处省略37个文件信息

评论

共有 条评论