zoukankan      html  css  js  c++  java
  • silverlight 生产图表(动态图表类型,Y轴数量) .xaml.cs文件

     silverlight 页面后台方法 .xaml.cs文件

    public void CreateChart(Grid oGrid, ObservableCollection<ListItem> lBaseOilBar)
            {
                foreach (ListItem li in lBaseOilBar)
                {
                    //图表大小,框线
                    Chart chart = new MyCharts();
                    chart.Width = 800;
                    chart.Height = 600;
                    chart.ScrollingEnabled = false;
                    //图表标题
                    Title title = new Title();
                    string sTitle = li.Title;
                    title.Text = sTitle;
                    chart.Titles.Add(title);
                    //Y轴数据单位
                    Axis axisY = new Axis();
                    string sYUint = li.YUint;
                    axisY.Title = sYUint;
                    chart.AxesY.Add(axisY);

                    title.MouseLeftButtonDown += new MouseButtonEventHandler(title_MouseLeftButtonDown);
                    //X轴数据
                    string[] sXLabel = li.XAXIS.ToArray();
                    string sTableName = "";
                    #region 点击是否触发事件,钻取数据图表赋值一个物理表名
                    bool ifGetSig = false;
                    switch (li.ChartName)
                    {
                        case "Stock":
                            sTableName = "StockSingleOildom";
                            ifGetSig = true;
                            break;
                        case "Drill_JC":
                            sTableName = "Drill_JCSingleOildom";
                            ifGetSig = true;
                            break;
                        case "EXTRACTIONOIL":
                            sTableName = "EXTRACTIONOILSingleOildom";
                            ifGetSig = true;
                            break;
                        case "Drill_MACHINE":
                            sTableName = "Drill_MACHINESingleOildom";
                            ifGetSig = true;
                            break;
                        case "PROVEDRILL":
                            sTableName = "PROVEDRILLSingleOildom";
                            ifGetSig = true;
                            break;

                    }
                    #endregion
                    #region 图表柱状个数,循环加载数据
                    ColorSet cs = new ColorSet();
                    cs.Id = "colorset1";
                    //foreach (YAXIS oYAXIS in li.YAXISs)
                    for (int j = 0; j < li.YAXISs.Count(); j++)
                    {
                        YAXIS oYAXIS = (YAXIS)li.YAXISs[j];
                        string sYTitle = "";
                        sYTitle = oYAXIS.Name;
                        double[] dYValue = null;
                        dYValue = oYAXIS.YValue.ToArray();
                        DataSeries dataSeries = new DataSeries();
                        dataSeries.LegendText = sYTitle;
                        #region 设置柱状图的颜色 待开发
                        //ColorSet cs = new ColorSet();
                        //string strColor = oYAXIS.Color;
                        //////Colors oColors = new Colors();
                        //cs.Id = "colorset1"; // 设置ColorSet 的 Id 为 colorset1
                        //cs.Brushes.Add(new SolidColorBrush(Colors.Green));
                        //cs.Brushes.Add(new SolidColorBrush(Colors.Red));
                        //cs.Brushes.Add(new SolidColorBrush(Colors.Blue));
                        ////cs.Brushes.Add(new SolidColorBrush(Colors.Yellow));
                        ////cs.Brushes.Add(new SolidColorBrush(Colors.Orange));
                        //chart.ColorSets.Add(cs);
                        //chart.ColorSet = "colorset1";  // 设置 Chart 使用自定义的颜色集合 colorset1
                        string strColor = oYAXIS.Color;
                        switch (strColor)
                        {
                            case "Red":
                                cs.Brushes.Add(new SolidColorBrush(Colors.Red));
                                break;
                            case "Yellow":
                                cs.Brushes.Add(new SolidColorBrush(Colors.Yellow));
                                break;
                            case "Orange":
                                cs.Brushes.Add(new SolidColorBrush(Colors.Orange));
                                break;
                            case "Green":
                                cs.Brushes.Add(new SolidColorBrush(Colors.Green));
                                break;
                            case "Blue":
                                cs.Brushes.Add(new SolidColorBrush(Colors.Blue));
                                break;
                            default:
                                break;
                        }
                        #endregion
                        #region 图表类型(柱状,饼状……)
                        string sChartType = li.ChartType;
                        RenderAs oRenderAs = new RenderAs();
                        switch (sChartType)
                        {
                            case "Column":
                                oRenderAs = RenderAs.Column;
                                break;
                            case "Pie":
                                oRenderAs = RenderAs.Pie;
                                break;
                            case "Line":
                                oRenderAs = RenderAs.Line;
                                break;
                        }
                        dataSeries.RenderAs = oRenderAs;
                        #endregion
                        #region 构造数据
                        DataPoint dp;
                        if (sXLabel != null)
                        {
                            for (int i = 0; i < sXLabel.Length; i++)
                            {
                                dp = new DataPoint();
                                dp.AxisXLabel = sXLabel[i];
                                dp.YValue = dYValue[i];
                                if (ifGetSig)
                                {
                                    dp.Tag = sTableName;
                                    dp.MouseLeftButtonUp += new MouseButtonEventHandler(dataPoint_MouseLeftButtonUp);
                                }
                                //饼状图去除值为0的oildom
                                if (dataSeries.RenderAs == RenderAs.Pie & dp.YValue == 0)
                                {
                                  
                                }
                                else
                                {
                                    dataSeries.DataPoints.Add(dp);
                                }
                            }
                        }
                        #endregion
                        chart.Series.Add(dataSeries);
                    }
                    // 设置 Chart 使用自定义的颜色集合 colorset1
                    if (cs.Brushes.Count > 0)
                    {
                        chart.ColorSets.Clear();
                        chart.ColorSets.Add(cs);
                        chart.ColorSet = "colorset1";
                    }
                    #endregion
                    oGrid.Children.Add(chart);
                }
            }

  • 相关阅读:
    BZOJ 3881: [Coci2015]Divljak
    BZOJ 2434: [Noi2011]阿狸的打字机
    BZOJ 2580: [Usaco2012 Jan]Video Game
    BZOJ 3940: [Usaco2015 Feb]Censoring
    BZOJ 3942: [Usaco2015 Feb]Censoring
    PTA L2-002 链表去重 团体程序设计天梯赛-练习集
    PTA L2-001 紧急救援-最短路(Dijkstra)多条最短路找最优解并输出路径 团体程序设计天梯赛-练习集
    PTA L1-020 帅到没朋友 团体程序设计天梯赛-练习集
    Codeforces 429 B. Working out-dp( Codeforces Round #245 (Div. 1))
    HDU 6467.简单数学题-数学题 (“字节跳动-文远知行杯”广东工业大学第十四届程序设计竞赛)
  • 原文地址:https://www.cnblogs.com/xuxin-1989/p/3627524.html
Copyright © 2011-2022 走看看