この記事は機械翻訳のミラー記事です。元の記事にジャンプするにはこちらをクリックしてください。

眺める: 21090|答える: 0

[WPF] WPFやSilverlightのプロジェクトでは棒グラフ、円グラフ、折れ線グラフが使われています

[リンクをコピー]
掲載地 2015/12/09 15:46:45 | | | |
開発過程で、データの表現をより良くするために棒グラフ、円グラフ、折れ線図などが使われることがあります。 この記事は単なる簡単な表示です。複雑な表示効果をご希望の場合は、公式ウェブサイトのコード例を参照してください。 この記事のコード----WPF、Silverlightの類似コードを使用し、サードパーティ製wpf_visifire_v5.1.2-0_trial制御を使用しています。

まずスクリーンショットをいくつか見てみましょう。


公開データ:

  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" };
コードをコピーします

ヒストグラム:

  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.         }
コードをコピーします

円グラフ:

  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.         }
コードをコピーします
線図:

  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.         }
コードをコピーします

コードダウンロード VisifireShow.rar (475.66 KB, ダウンロード数: 2, 售价: 1 粒MB)





先の:ブレイクは何回ループから飛び出せるのでしょうか? どうすればすべてのループから抜け出せますか?
次に:Visual Studio 2013やVS2010用の背景画像を設定すれば、とても便利です!
免責事項:
Code Farmer Networkが発行するすべてのソフトウェア、プログラミング資料、記事は学習および研究目的のみを目的としています。 上記の内容は商業的または違法な目的で使用されてはならず、そうでなければ利用者はすべての結果を負うことになります。 このサイトの情報はインターネットからのものであり、著作権紛争はこのサイトとは関係ありません。 ダウンロード後24時間以内に上記の内容を完全にパソコンから削除してください。 もしこのプログラムを気に入ったら、正規のソフトウェアを支持し、登録を購入し、より良い本物のサービスを受けてください。 もし侵害があれば、メールでご連絡ください。

Mail To:help@itsvse.com