Šis raksts ir mašīntulkošanas spoguļraksts, lūdzu, noklikšķiniet šeit, lai pārietu uz oriģinālo rakstu.

Skats: 21090|Atbildi: 0

[WPF] WPF un Silverlight projektos tiek izmantotas joslu diagrammas, sektoru diagrammas un līniju diagrammas

[Kopēt saiti]
Publicēts 09.12.2015 15:46:45 | | | |
Izstrādes procesā jūs varat sastapties ar joslu diagrammām, sektoru diagrammām un līniju diagrammām, lai labāk parādītu datus. Šis raksts ir tikai vienkāršs displejs, ja vēlaties sarežģītus displeja efektus, lūdzu, skatiet oficiālās vietnes koda piemēru. ---- šajā rakstā aprakstītais kods izmanto WPF, Silverlight līdzīgu kodu un izmanto trešo pušu wpf_visifire_v5.1.2-0_trial vadīklas.

Vispirms ievietosim ekrānuzņēmumu kopu:


Publiskie dati:

  1. private List<string> strListx = new List<string>() { "苹果", "樱桃", "菠萝", "香蕉", "榴莲", "葡萄", "桃子", "猕猴桃" };
  2.         private List<string> strListy = new List<string>() { "13", "75", "60", "38", "97", "22", "39", "80" };

  3.         private List<DateTime> LsTime = new List<DateTime>()
  4.             {
  5.                new DateTime(2012,1,1),
  6.                new DateTime(2012,2,1),
  7.                new DateTime(2012,3,1),
  8.                new DateTime(2012,4,1),
  9.                new DateTime(2012,5,1),
  10.                new DateTime(2012,6,1),
  11.                new DateTime(2012,7,1),
  12.                new DateTime(2012,8,1),
  13.                new DateTime(2012,9,1),
  14.                new DateTime(2012,10,1),
  15.                new DateTime(2012,11,1),
  16.                new DateTime(2012,12,1),
  17.             };
  18.         private List<string> cherry = new List<string>() { "33", "75", "60", "98", "67", "88", "39", "45", "13", "22", "45", "80" };
  19.         private List<string> pineapple = new List<string>() { "13", "34", "38", "12", "45", "76", "36", "80", "97", "22", "76", "39" };
Kopēt kodu

Histogramma:

  1. public void CreateChartColumn(string name, List<string> valuex, List<string> valuey)
  2.         {
  3.             //创建一个图标
  4.             Chart chart = new Chart();

  5.             //设置图标的宽度和高度
  6.             chart.Width = 580;
  7.             chart.Height = 380;
  8.             chart.Margin = new Thickness(100, 5, 10, 5);
  9.             //是否启用打印和保持图片
  10.             chart.ToolBarEnabled = false;

  11.             //设置图标的属性
  12.             chart.ScrollingEnabled = false;//是否启用或禁用滚动
  13.             chart.View3D = true;//3D效果显示

  14.             //创建一个标题的对象
  15.             Title title = new Title();

  16.             //设置标题的名称
  17.             title.Text = Name;
  18.             title.Padding = new Thickness(0, 10, 5, 0);

  19.             //向图标添加标题
  20.             chart.Titles.Add(title);

  21.             Axis yAxis = new Axis();
  22.             //设置图标中Y轴的最小值永远为0           
  23.             yAxis.AxisMinimum = 0;
  24.             //设置图表中Y轴的后缀         
  25.             yAxis.Suffix = "斤";
  26.             chart.AxesY.Add(yAxis);

  27.             // 创建一个新的数据线。               
  28.             DataSeries dataSeries = new DataSeries();

  29.             // 设置数据线的格式
  30.             dataSeries.RenderAs = RenderAs.StackedColumn;//柱状Stacked


  31.             // 设置数据点              
  32.             DataPoint dataPoint;
  33.             for (int i = 0; i < valuex.Count; i++)
  34.             {
  35.                 // 创建一个数据点的实例。                  
  36.                 dataPoint = new DataPoint();
  37.                 // 设置X轴点                    
  38.                 dataPoint.AxisXLabel = valuex[i];
  39.                 //设置Y轴点                  
  40.                 dataPoint.YValue = double.Parse(valuey[i]);
  41.                 //添加一个点击事件        
  42.                 dataPoint.MouseLeftButtonDown += new MouseButtonEventHandler(dataPoint_MouseLeftButtonDown);
  43.                 //添加数据点                  
  44.                 dataSeries.DataPoints.Add(dataPoint);
  45.             }

  46.             // 添加数据线到数据序列。               
  47.             chart.Series.Add(dataSeries);

  48.             //将生产的图表增加到Grid,然后通过Grid添加到上层Grid.           
  49.             Grid gr = new Grid();
  50.             gr.Children.Add(chart);
  51.             Simon.Children.Add(gr);
  52.         }
Kopēt kodu

Sektoru diagramma:

  1. public void CreateChartPie(string name, List<string> valuex, List<string> valuey)
  2.         {
  3.             //创建一个图标
  4.             Chart chart = new Chart();

  5.             //设置图标的宽度和高度
  6.             chart.Width = 580;
  7.             chart.Height = 380;
  8.             chart.Margin = new Thickness(100, 5, 10, 5);
  9.             //是否启用打印和保持图片
  10.             chart.ToolBarEnabled = false;

  11.             //设置图标的属性
  12.             chart.ScrollingEnabled = false;//是否启用或禁用滚动
  13.             chart.View3D = true;//3D效果显示

  14.             //创建一个标题的对象
  15.             Title title = new Title();

  16.             //设置标题的名称
  17.             title.Text = name;
  18.             title.Padding = new Thickness(0, 10, 5, 0);

  19.             //向图标添加标题
  20.             chart.Titles.Add(title);

  21.             //Axis yAxis = new Axis();
  22.             ////设置图标中Y轴的最小值永远为0           
  23.             //yAxis.AxisMinimum = 0;
  24.             ////设置图表中Y轴的后缀         
  25.             //yAxis.Suffix = "斤";
  26.             //chart.AxesY.Add(yAxis);

  27.             // 创建一个新的数据线。               
  28.             DataSeries dataSeries = new DataSeries();

  29.             // 设置数据线的格式
  30.             dataSeries.RenderAs = RenderAs.Pie;//柱状Stacked


  31.             // 设置数据点              
  32.             DataPoint dataPoint;
  33.             for (int i = 0; i < valuex.Count; i++)
  34.             {
  35.                 // 创建一个数据点的实例。                  
  36.                 dataPoint = new DataPoint();
  37.                 // 设置X轴点                    
  38.                 dataPoint.AxisXLabel = valuex[i];

  39.                 dataPoint.LegendText = "##" + valuex[i];
  40.                 //设置Y轴点                  
  41.                 dataPoint.YValue = double.Parse(valuey[i]);
  42.                 //添加一个点击事件        
  43.                 dataPoint.MouseLeftButtonDown += new MouseButtonEventHandler(dataPoint_MouseLeftButtonDown);
  44.                 //添加数据点                  
  45.                 dataSeries.DataPoints.Add(dataPoint);
  46.             }

  47.             // 添加数据线到数据序列。               
  48.             chart.Series.Add(dataSeries);

  49.             //将生产的图表增加到Grid,然后通过Grid添加到上层Grid.           
  50.             Grid gr = new Grid();
  51.             gr.Children.Add(chart);
  52.             Simon.Children.Add(gr);
  53.         }
Kopēt kodu
Līniju diagramma:

  1. public void CreateChartSpline(string name, List<DateTime> lsTime, List<string> cherry, List<string> pineapple)
  2.         {
  3.             //创建一个图标
  4.             Chart chart = new Chart();

  5.             //设置图标的宽度和高度
  6.             chart.Width = 580;
  7.             chart.Height = 380;
  8.             chart.Margin = new Thickness(100, 5, 10, 5);
  9.             //是否启用打印和保持图片
  10.             chart.ToolBarEnabled = false;

  11.             //设置图标的属性
  12.             chart.ScrollingEnabled = false;//是否启用或禁用滚动
  13.             chart.View3D = true;//3D效果显示

  14.             //创建一个标题的对象
  15.             Title title = new Title();

  16.             //设置标题的名称
  17.             title.Text = name;
  18.             title.Padding = new Thickness(0, 10, 5, 0);

  19.             //向图标添加标题
  20.             chart.Titles.Add(title);

  21.             //初始化一个新的Axis
  22.             Axis xaxis = new Axis();
  23.             //设置Axis的属性
  24.             //图表的X轴坐标按什么来分类,如时分秒
  25.             xaxis.IntervalType = IntervalTypes.Months;
  26.             //图表的X轴坐标间隔如2,3,20等,单位为xAxis.IntervalType设置的时分秒。
  27.             xaxis.Interval = 1;
  28.             //设置X轴的时间显示格式为7-10 11:20           
  29.             xaxis.ValueFormatString = "MM月";
  30.             //给图标添加Axis            
  31.             chart.AxesX.Add(xaxis);

  32.             Axis yAxis = new Axis();
  33.             //设置图标中Y轴的最小值永远为0           
  34.             yAxis.AxisMinimum = 0;
  35.             //设置图表中Y轴的后缀         
  36.             yAxis.Suffix = "斤";
  37.             chart.AxesY.Add(yAxis);


  38.             // 创建一个新的数据线。               
  39.             DataSeries dataSeries = new DataSeries();
  40.             // 设置数据线的格式。               
  41.             dataSeries.LegendText = "樱桃";

  42.             dataSeries.RenderAs = RenderAs.Spline;//折线图

  43.             dataSeries.XValueType = ChartValueTypes.DateTime;
  44.             // 设置数据点              
  45.             DataPoint dataPoint;
  46.             for (int i = 0; i < lsTime.Count; i++)
  47.             {
  48.                 // 创建一个数据点的实例。                  
  49.                 dataPoint = new DataPoint();
  50.                 // 设置X轴点                    
  51.                 dataPoint.XValue = lsTime[i];
  52.                 //设置Y轴点                  
  53.                 dataPoint.YValue = double.Parse(cherry[i]);
  54.                 dataPoint.MarkerSize = 8;
  55.                 //dataPoint.Tag = tableName.Split('(')[0];
  56.                 //设置数据点颜色                  
  57.                 // dataPoint.Color = new SolidColorBrush(Colors.LightGray);                  
  58.                 dataPoint.MouseLeftButtonDown += new MouseButtonEventHandler(dataPoint_MouseLeftButtonDown);
  59.                 //添加数据点                  
  60.                 dataSeries.DataPoints.Add(dataPoint);
  61.             }

  62.             // 添加数据线到数据序列。               
  63.             chart.Series.Add(dataSeries);


  64.             // 创建一个新的数据线。               
  65.             DataSeries dataSeriesPineapple = new DataSeries();
  66.             // 设置数据线的格式。         

  67.             dataSeriesPineapple.LegendText = "菠萝";

  68.             dataSeriesPineapple.RenderAs = RenderAs.Spline;//折线图

  69.             dataSeriesPineapple.XValueType = ChartValueTypes.DateTime;
  70.             // 设置数据点              

  71.             DataPoint dataPoint2;
  72.             for (int i = 0; i < lsTime.Count; i++)
  73.             {
  74.                 // 创建一个数据点的实例。                  
  75.                 dataPoint2 = new DataPoint();
  76.                 // 设置X轴点                    
  77.                 dataPoint2.XValue = lsTime[i];
  78.                 //设置Y轴点                  
  79.                 dataPoint2.YValue = double.Parse(pineapple[i]);
  80.                 dataPoint2.MarkerSize = 8;
  81.                 //dataPoint2.Tag = tableName.Split('(')[0];
  82.                 //设置数据点颜色                  
  83.                 // dataPoint.Color = new SolidColorBrush(Colors.LightGray);                  
  84.                 dataPoint2.MouseLeftButtonDown += new MouseButtonEventHandler(dataPoint_MouseLeftButtonDown);
  85.                 //添加数据点                  
  86.                 dataSeriesPineapple.DataPoints.Add(dataPoint2);
  87.             }
  88.             // 添加数据线到数据序列。               
  89.             chart.Series.Add(dataSeriesPineapple);

  90.             //将生产的图表增加到Grid,然后通过Grid添加到上层Grid.           
  91.             Grid gr = new Grid();
  92.             gr.Children.Add(chart);
  93.             
  94.             Simon.Children.Add(gr);
  95.         }
Kopēt kodu

Koda lejupielāde VisifireShow.rar (475.66 KB, Lejupielādes skaits: 2, 售价: 1 粒MB)





Iepriekšējo:Cik cilpu var izlēkt? Kā es varu izlēkt no visām cilpām?
Nākamo:Iestatiet fona attēlu Visual Studio 2013 vai VS2010, tas ir forši!
Atruna:
Visa programmatūra, programmēšanas materiāli vai raksti, ko publicē Code Farmer Network, ir paredzēti tikai mācību un pētniecības mērķiem; Iepriekš minēto saturu nedrīkst izmantot komerciāliem vai nelikumīgiem mērķiem, pretējā gadījumā lietotājiem ir jāuzņemas visas sekas. Informācija šajā vietnē nāk no interneta, un autortiesību strīdiem nav nekāda sakara ar šo vietni. Iepriekš minētais saturs ir pilnībā jāizdzēš no datora 24 stundu laikā pēc lejupielādes. Ja jums patīk programma, lūdzu, atbalstiet oriģinālu programmatūru, iegādājieties reģistrāciju un iegūstiet labākus oriģinālus pakalpojumus. Ja ir kādi pārkāpumi, lūdzu, sazinieties ar mums pa e-pastu.

Mail To:help@itsvse.com