private void CreateChart(Generator generator)
        {
            MyChart.Series.Clear();

            //Adding Legends for the chart
            var legend = new ChartLegend();

            MyChart.Legend = legend;

            //Initializing column series
            var series = new ColumnSeries
            {
                ItemsSource  = generator.GetResult(),
                XBindingPath = "Range",
                YBindingPath = "InnerNumbers",
                ShowTooltip  = true,
                Label        = "InnerNumbers"
            };

            series.Label = "Range";

            //Setting adornment to the chart series
            series.AdornmentsInfo = new ChartAdornmentInfo()
            {
                ShowLabel = true
            };

            //Adding Series to the Chart Series Collection
            MyChart.Series.Add(series);
        }
        public void ChartLegend()
        {
            //ExStart
            //ExFor:Charts.Chart.Legend
            //ExFor:Charts.ChartLegend
            //ExFor:Charts.ChartLegend.Overlay
            //ExFor:Charts.ChartLegend.Position
            //ExFor:Charts.LegendPosition
            //ExSummary:Shows how to edit the appearance of a chart's legend.
            Document        doc     = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

            // Insert a line graph
            Shape chartShape = builder.InsertChart(ChartType.Line, 450, 300);
            Chart chart      = chartShape.Chart;

            // Get its legend
            ChartLegend legend = chart.Legend;

            // By default, other elements of a chart will not overlap with its legend
            Assert.False(legend.Overlay);

            // We can move its position by setting this attribute
            legend.Position = LegendPosition.TopRight;

            doc.Save(ArtifactsDir + "Charts.ChartLegend.docx");
            //ExEnd
        }
        public static void ApplyChartStyles(ChartControl chart)
        {
            #region ApplyCustomPalette
            chart.Skins = Skins.Metro;
            #endregion

            #region chart appearance customization
            chart.ShowLegend = false;
            chart.BorderAppearance.SkinStyle      = Syncfusion.Windows.Forms.Chart.ChartBorderSkinStyle.None;
            chart.BorderAppearance.FrameThickness = new ChartThickness(-2, -2, 2, 2);
            chart.PrimaryXAxis.DrawGrid           = false;
            #endregion

            #region Chart axes customization
            chart.PrimaryXAxis.TickSize = new System.Drawing.Size(1, 5);
            chart.PrimaryYAxis.TickSize = new System.Drawing.Size(5, 1);
            chart.LegendsPlacement      = ChartPlacement.Outside;
            #endregion

            #region Legend Customization
            //Adds Custom legend to chart control
            ChartLegend legend1 = new ChartLegend(chart);
            legend1.Name = "legend1";
            legend1.RepresentationType = ChartLegendRepresentationType.None;
            legend1.Position           = ChartDock.Bottom;
            legend1.Alignment          = ChartAlignment.Center;
            ChartLegendItem[]          customItems = new ChartLegendItem[0];
            ChartLegendItemsCollection clic        = new ChartLegendItemsCollection();
            ChartLegendItem            cli1        = new ChartLegendItem("Press Esc to Cancel Zooming");
            clic.Add(cli1);
            legend1.CustomItems = clic.ToArray();
            chart.Legends.Add(legend1);
            #endregion
        }
Beispiel #4
0
        /// <summary>
        /// 初始化报表
        /// </summary>
        void InitChart()
        {
            // 数据源下拉列表初始化
            ((CList)_fv["tbl"]).Data = _item.Root.Data.DataSet;

            _chart.BeginUpdate();
            Enum.TryParse <ChartType>(_item.Data.Str("type"), out var tp);
            Enum.TryParse <Orientation>(_item.Data.Str("legorientation"), out var ori);
            Enum.TryParse <LegendPosition>(_item.Data.Str("legpos"), out var pos);
            _chart.ChartType = tp;
            ChgFldByType(tp);
            _chart.Data = GetData(tp);

            _chart.Header = _item.Data.Str("title");
            for (int i = 0; i < _chart.Children.Count; i++)
            {
                if (_chart.Children[i] is ChartLegend)
                {
                    // 加载初始数据值,改变legend表现样式。
                    ChartLegend legend = _chart.Children[i] as ChartLegend;
                    legend.Visibility  = _item.Data.Bool("showlegend") ? Visibility.Visible : Visibility.Collapsed;
                    legend.Title       = _item.Data.Str("legtitle");
                    legend.Position    = pos;
                    legend.Orientation = ori;
                }
            }
            _chart.View.AxisX.Title = _item.Data.Str("titlex");
            _chart.View.AxisY.Title = _item.Data.Str("titley");
            _chart.EndUpdate();
        }
        public MainWindow()
        {
            InitializeComponent();

            series1.ItemsSource = viewModel.Data;
            series2.ItemsSource = viewModel.Data;
            series1.ColorModel  = new ChartColorModel();
            ChartLegend legend = new ChartLegend();

            toggleIndexes = new List <int>();

            var data = viewModel.Data;

            for (int i = 0; i < data.Count; i++)
            {
                legend.Items.Add(new LegendItem()
                {
                    Item               = data[i],
                    Series             = series1,
                    IconHeight         = 10,
                    IconWidth          = 10,
                    IconVisibility     = Visibility.Visible,
                    Interior           = series1.ColorModel.GetBrush(i),
                    CheckBoxVisibility = Visibility.Visible
                });
            }

            legend.ItemTemplate = grid.Resources["itemTemplate"] as DataTemplate;
            chart.Legend        = legend;
        }
Beispiel #6
0
        //生成文章来源饼图
        public string CreateSumPie(string key, DataTable dt)
        {
            ChartTitle title = new ChartTitle()
            {
                text = key, subtext = "平台对比"
            };
            ChartOption option = new PieChartOption(title, "");
            ChartLegend legend = new ChartLegend();

            legend.data = "新闻,微博,微信".Split(',');
            ChartData[] data_mod = new ChartData[legend.data.Length];
            for (int i = 0; i < legend.data.Length; i++)
            {
                data_mod[i] = new ChartData()
                {
                    name = legend.data[i], value = dt.Select("Source='" + legend.data[i] + "'").Length
                };
            }
            List <ChartSeries> seriesList = new List <ChartSeries>()
            {
                new ChartSeries()
                {
                    name = "平台对比", data_mod = data_mod
                }
            };

            ((PieChartOption)option).AddData(legend, seriesList, "");
            return(option.ToString());
        }
Beispiel #7
0
        /// <summary>
        /// The GetLegend
        /// </summary>
        /// <param name="chart">The chart<see cref="ChartControl"/></param>
        /// <returns>The <see cref="ChartLegend"/></returns>
        internal ChartLegend GetLegend(ChartControl chart)
        {
            try
            {
                if (Chart.Legends != null)
                {
                    Chart.Legends.Clear();
                }

                ChartLegend legend = new ChartLegend(Chart);
                foreach (string axislabel in Chart.PrimaryXAxis.Labels)
                {
                    ChartLegendItem item = new ChartLegendItem(axislabel);
                }

                legend.VisibleCheckBox = true;
                Chart.Legends.Add(legend);
                return(legend);
            }
            catch (Exception e)
            {
                new Error(e).ShowDialog();
                return(null);
            }
        }
        /// <summary>
        /// Sets up the Legend style.
        /// </summary>
        /// <param name="chartXy"></param>
        private void SetupChartLegend(ChartXy chartXy)
        {
            ChartLegend legend = chartXy.Legend;

            legend.ShowCheckBoxes = true;

            legend.Placement = Placement.Inside;
            legend.Alignment = Alignment.TopRight;
            legend.Direction = Direction.LeftToRight;

            // Align vertical items, and permit the legend to only use
            // up to 50% of the available chart width;

            legend.AlignVerticalItems = true;
            legend.MaxHorizontalPct   = 50;

            ChartLegendVisualStyle lstyle = legend.ChartLegendVisualStyles.Default;

            lstyle.BorderThickness = new Thickness(0);
            lstyle.BorderColor     = new BorderColor(Color.White);

            lstyle.Margin  = new DevComponents.DotNetBar.Charts.Style.Padding(8);
            lstyle.Padding = new DevComponents.DotNetBar.Charts.Style.Padding(4);

            //lstyle.Background = new Background(Color.FromArgb(200, Color.White));
        }
Beispiel #9
0
        /// <summary>
        /// Initializes the ChartControl's data and sets the Chart type
        /// </summary>
        protected void InitializeChartData()
        {
            ChartSeries series1 = new ChartSeries();

            series1.Name = "Year 2004";
            series1.Text = series1.Name;
            series1.Points.Add(0, 10);
            series1.Points.Add(1, 8);
            series1.Points.Add(2, 24);
            series1.Points.Add(3, 24);
            series1.Points.Add(4, 10);
            series1.Points.Add(5, 24);
            SeriesSettings(series1);
            this.chartControl1.Series.Add(series1);
            series1.ConfigItems.PieItem.ShowSeriesTitle = true;
            series1.ConfigItems.PieItem.LabelStyle      = ChartAccumulationLabelStyle.Inside;

            ChartSeries series2 = new ChartSeries();

            series2.Name = "Year 2005";
            series2.Text = series2.Name;
            series2.Points.Add(0, 12);
            series2.Points.Add(1, 10);
            series2.Points.Add(2, 18);
            series2.Points.Add(3, 25);
            series2.Points.Add(5, 15);
            series2.Points.Add(6, 20);
            SeriesSettings(series2);
            this.chartControl1.Series.Add(series2);
            series2.ConfigItems.PieItem.ShowSeriesTitle = true;
            series2.ConfigItems.PieItem.LabelStyle      = ChartAccumulationLabelStyle.Inside;

            this.chartControl1.ChartArea.DivideArea = true;
            ChartLegend chartLegend = new ChartLegend();

            chartLegend.Name = "Legend 1";
            string[] label = new string[] { "Engineering", "Medical Sciences", "BioTechnology", "Information Services", "Art and Humanities", "Geography" };
            List <ChartLegendItem> items = new List <ChartLegendItem>();

            for (int i = 0; i < 6; i++)
            {
                ChartLegendItem legendItem = new ChartLegendItem(label[i]);
                legendItem.Font = new Font("Segoe UI", 10F);
                legendItem.RepresentationSize = new Size(15, 15);
                legendItem.TextColor          = Color.Black;
                legendItem.Border.Color       = Color.Transparent;
                items.Add(legendItem);
            }
            chartControl1.Legend.RepresentationType = ChartLegendRepresentationType.SeriesType;

            chartControl1.Legend.CustomItems    = items.ToArray();
            chartControl1.Legend.RowsCount      = 2;
            this.chartControl1.LegendAlignment  = ChartAlignment.Center;
            this.chartControl1.LegendPosition   = ChartDock.Bottom;
            this.chartControl1.LegendsPlacement = ChartPlacement.Outside;
            this.chartControl1.LegendsPlacement = ChartPlacement.Outside;
            this.chartControl1.ShowLegend       = true;
            this.chartControl1.SmoothingMode    = SmoothingMode.AntiAlias;
        }
        /// <summary>
        /// 柱状图数据处理
        /// </summary>
        /// <param name="charttitle">标题</param>
        /// <param name="chartAxisData">坐标轴数据</param>
        /// <param name="seriesData">图表数据</param>
        /// <param name="lengendData">图例数据</param>
        /// <param name="chartGrid">直角坐标系内绘图网格</param>
        /// <param name="isShowlengend">是否开启图例</param>
        /// <param name="chatsubtitle">副标题文本,默认值:'','\n'指定换行</param>
        /// <param name="isCalculable">是否启用拖拽重计算特性,默认关闭</param>
        /// <param name="chartYAxisName">Y轴名称</param>
        /// <returns>图表所有数据</returns>
        public static string ChartBarDataProcess(string charttitle, List <object> chartAxisData, IEnumerable <ChartRightangleSeries> seriesData, List <string> lengendData, ChartGrid chartGrid, bool isShowlengend = false, string chatsubtitle = null, bool isCalculable = false, string chartYAxisName = null)
        {
            //标题
            var chartTitle = new ChartTitle()
            {
                text    = charttitle,
                subtext = chatsubtitle
            };
            //提示框
            var chartTooltip = new ChartTooltip()
            {
                trigger = "axis"
            };
            //图例
            var chartLegend = new ChartLegend()
            {
                show = isShowlengend, data = lengendData
            };

            //X坐标轴
            var chartXAxis = new List <ChartAxis>()
            {
                new ChartAxis
                {
                    type = "category",
                    data = chartAxisData
                }
            };

            //Y坐标轴
            var chartYAxis = new List <ChartAxis>()
            {
                new ChartAxis()
                {
                    type = "value",
                    name = chartYAxisName
                }
            };

            //数据
            var chartRightangleSeries = new List <ChartRightangleSeries>();

            chartRightangleSeries.AddRange(seriesData);
            var seriesDatas = chartRightangleSeries.Count > 0 ? chartRightangleSeries : (object)"-";

            var jsondata = new
            {
                title      = chartTitle,
                tooltip    = chartTooltip,
                calculable = isCalculable,
                legend     = chartLegend,
                grid       = chartGrid,
                xAxis      = chartXAxis,
                yAxis      = chartYAxis,
                series     = seriesDatas
            };

            return(jsondata.ToJson());
        }
        private void DisplayOrphanStats()
        {
            SfChart chart = new SfChart()
            {
                Header = "Orphan Statistics", FontSize = 18, Height = 300, Width = 500
            };

            OrphanStatistics OrphanStats = new OrphanStatistics();

            //GuardianStatistics GuardianStats = new GuardianStatistics();
            //NarrationStatistics NarrationStats = new NarrationStatistics();

            OrphanStats = OrphanDataService.GetOrphanStatistics();

            TotalOrphanCount = OrphanStats.TotalCount;

            ActiveSeries = new List <ActivePieModel>()
            {
                new ActivePieModel {
                    Category = "Active", Value = OrphanStats.ActiveCount
                },
                new ActivePieModel {
                    Category = "Inactive", Value = OrphanStats.InactiveCount
                },
                new ActivePieModel {
                    Category = "Unspecified", Value = OrphanStats.UnknownCount
                },
                //new ActivePieModel { Category = "Total", Value = OrphanStats.TotalCount}
            };

            //Adding Legends for the chart
            ChartLegend legend = new ChartLegend();

            chart.Legend = legend;

            PieSeries series = new PieSeries()
            {
                ItemsSource    = ActiveSeries,
                XBindingPath   = "Category",
                YBindingPath   = "Value",
                ShowTooltip    = true,
                Label          = "Values",
                AdornmentsInfo = new ChartAdornmentInfo()
                {
                    ShowLabel = true
                },
            };

            chart.Series.Add(series);

            stackOrphanStats.Children.Add(chart);

            TextBlock txtTotal = new TextBlock();

            txtTotal.FontSize            = 14;
            txtTotal.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Center;
            txtTotal.Text = "Total Orphan Count: " + TotalOrphanCount.ToString();
            stackOrphanStats.Children.Add(txtTotal);
        }
        /// <summary>
        /// 时间轴线性图数据处理
        /// </summary>
        /// <param name="charttitle">标题</param>
        /// <param name="fm">y轴数据自定义单位,如“元”,“年”</param>
        /// <param name="chartAxisData">坐标轴数据</param>
        /// <param name="seriesData">图表数据</param>
        /// <param name="lengendData">图例数据</param>
        /// <param name="isShowlengend">是否开启图例</param>
        /// <param name="chatsubtitle">副标题文本,默认值:"","\n"指定换行</param>
        /// <param name="isCalculable">是否启用拖拽重计算特性,默认关闭</param>
        /// <param name="chartYAxisName">Y轴名称</param>
        /// <param name="chartTimeline">时间轴</param>
        /// <returns>图表所有数据</returns>
        public static string TimeLineChartLineDataProcess(string charttitle, string fm, List <object> chartAxisData, IEnumerable <ChartRightangleSeries> seriesData, List <string> lengendData, bool isShowlengend = false, string chatsubtitle = null, bool isCalculable = false, string chartYAxisName = null, ChartTimeline chartTimeline = null)
        {
            //标题
            var chartTitle = new ChartTitle()
            {
                text    = charttitle,
                subtext = chatsubtitle
            };
            //提示框
            var chartTooltip = new ChartTooltip()
            {
                trigger = "axis"
            };
            //图例
            var chartLegend = new ChartLegend()
            {
                show = isShowlengend, data = lengendData
            };

            //X坐标轴
            var chartXAxis = new List <ChartAxis>()
            {
                new ChartAxis
                {
                    type        = "category",
                    boundaryGap = false,
                    data        = chartAxisData
                }
            };

            //Y坐标轴
            var chartYAxis = new List <ChartAxis>()
            {
                new ChartAxis()
                {
                    type = "value",
                    name = chartYAxisName
                }
            };

            //数据
            var chartRightangleSeries = new List <ChartRightangleSeries>();

            chartRightangleSeries.AddRange(seriesData);
            var seriesDatas = chartRightangleSeries.Count > 0 ? chartRightangleSeries : (object)"-";

            //时间点
            var chartOptions = new List <object> {
                new { chartTitle, chartTooltip, chartXAxis, chartYAxis, series = seriesDatas }
            };

            var jsondata = new
            {
                timeline = chartTimeline,//时间轴设置
                options  = chartOptions
            };

            return(jsondata.ToJson());
        }
Beispiel #13
0
 public void AddChartLegend(PPT.Chart chart, ChartLegend chartLegend)
 {
     chart.HasLegend             = true;
     chart.Legend.Font.Italic    = chartLegend.italic;
     chart.Legend.Font.Bold      = chartLegend.bold;
     chart.Legend.Font.Underline = chartLegend.underline;
     chart.Legend.Font.Size      = chartLegend.fontSize;
     chart.Refresh();
 }
Beispiel #14
0
        protected override void When()
        {
            ChartLegend chartLegend = new ChartLegend()
            {
                bold      = true,
                italic    = true,
                fontSize  = 14,
                underline = true
            };

            this.SUT.AddChartLegend(returnedChart, chartLegend);
        }
Beispiel #15
0
        public string BarChartBind(DataTable dt, string type)
        {
            //初始化图表
            BarChartOption option = new BarChartOption(new ChartTitle()
            {
                text = "推广统计", subtext = "按月统计"
            }, "", type);
            ChartLegend        legend   = new ChartLegend();
            List <ChartSeries> dataList = new List <ChartSeries>();
            //默认按用户统计
            List <string> years = new List <string>();//不存数据,只存年

            foreach (DataRow dr in dt.DefaultView.ToTable(true, "Year").Rows)
            {
                years.Add(dr["Year"].ToString());
            }
            foreach (string year in years)
            {
                List <int> months = new List <int>();//存12个月的数据,不足以0补齐
                for (int i = 1; i <= 12; i++)
                {
                    DataRow[] drs = dt.Select("Year=" + year + " AND Month=" + i);
                    if (drs.Length > 0)
                    {
                        months.Add(Convert.ToInt32(drs[0]["PCount"]));
                    }
                    else
                    {
                        months.Add(0);
                    }
                }
                dataList.Add(new ChartSeries()
                {
                    type     = type,
                    name     = year,
                    data_int = months.ToArray()
                });
            }
            /*数据完成,填充图表*/
            legend.data  = years.ToArray();
            option.yAxis = new YAxis()
            {
                data = years.ToArray()
            };
            //与数据无须name对应,y轴需要name对应
            ((BarChartOption)option).AddData("1月,2月,3月,4月,5月,6月,7月,8月,9月,10月,11月,12月".Split(','), dataList, type);
            option.legend = legend;
            return(option.ToString());
        }
Beispiel #16
0
        private void InitializeControlSettings()
        {
            ChartLegend legend1 = new ChartLegend(chartControl1);

            legend1.Name               = "legend1";
            legend1.ColumnsCount       = 1;
            legend1.RowsCount          = 1;
            legend1.RepresentationType = ChartLegendRepresentationType.None;
            legend1.ShowSymbol         = false;
            legend1.Position           = ChartDock.Bottom;
            legend1.Alignment          = ChartAlignment.Center;

            ChartLegendItem[]          customItems = new ChartLegendItem[0];
            ChartLegendItemsCollection clic        = new ChartLegendItemsCollection();
            ChartLegendItem            cli1        = new ChartLegendItem("That follows a series point");

            cli1.Type               = ChartLegendItemType.Circle;
            cli1.Border.Color       = Color.Transparent;
            cli1.RepresentationSize = new Size(8, 8);
            cli1.Interior           = new BrushInfo(Color.FromArgb(0Xc1, 0X39, 0x2b));
            clic.Add(cli1);

            ChartLegendItem cli2 = new ChartLegendItem("That uses chart coordinates");

            cli2.Type = ChartLegendItemType.InvertedTriangle;
            cli2.RepresentationSize = new Size(8, 8);
            cli2.Interior           = new BrushInfo(Color.FromArgb(0Xfc, 0Xec, 0X29));
            clic.Add(cli2);

            ChartLegendItem cli3 = new ChartLegendItem("That follows a percent type");

            cli3.Type = ChartLegendItemType.Pentagon;
            cli3.RepresentationSize = new Size(8, 8);
            cli3.Interior           = new BrushInfo(Color.FromArgb(0X00, 0X66, 0Xcc));
            clic.Add(cli3);

            ChartLegendItem cli4 = new ChartLegendItem("That follows a pixel type");

            cli4.Type = ChartLegendItemType.Triangle;
            cli4.RepresentationSize = new Size(8, 8);
            cli4.Interior           = new BrushInfo(Color.FromArgb(0X00, 0Xce, 0X45));
            clic.Add(cli4);

            legend1.CustomItems = clic.ToArray();
            chartControl1.Legends.Add(legend1);
            chartControl1.ShowToolTips = true;
        }
Beispiel #17
0
        public MainPage()
        {
            this.InitializeComponent();

            SfChart chart = new SfChart()
            {
                Header = "Chart", Height = 300, Width = 500
            };

            //Adding horizontal axis to the chart
            CategoryAxis primaryAxis = new CategoryAxis();

            primaryAxis.Header   = "Name";
            primaryAxis.FontSize = 14;
            chart.PrimaryAxis    = primaryAxis;

            //Adding vertical axis to the chart
            NumericalAxis secondaryAxis = new NumericalAxis();

            secondaryAxis.Header   = "Height(in cm)";
            secondaryAxis.FontSize = 14;
            chart.SecondaryAxis    = secondaryAxis;

            //Adding Legends for the chart
            ChartLegend legend = new ChartLegend();

            chart.Legend = legend;

            //Initializing column series
            ColumnSeries series = new ColumnSeries();

            series.ItemsSource  = (new ViewModel()).Data;
            series.XBindingPath = "Name";
            series.YBindingPath = "Height";
            series.ShowTooltip  = true;
            series.Label        = "Heights";

            //Setting adornment to the chart series
            series.AdornmentsInfo = new ChartAdornmentInfo()
            {
                ShowLabel = true
            };

            //Adding Series to the Chart Series Collection
            chart.Series.Add(series);
            this.Content = chart;
        }
Beispiel #18
0
        //根据文章发布时间产生扩散速度图
        public string CreatePie(string key, DataTable dt)
        {
            ChartTitle title = new ChartTitle()
            {
                text = key, subtext = "扩散速度"
            };
            ChartOption option = new PieChartOption(title, "");
            ChartLegend legend = new ChartLegend();

            legend.data = "24小时内,72小时内,一周内,30天内,30天外".Split(',');
            ChartData[] data_mod = new ChartData[5];
            DateTime    time_24 = DateTime.Now.AddHours(-24), time_72 = DateTime.Now.AddHours(-72), time_d7 = DateTime.Now.AddDays(-7), time_d30 = DateTime.Now.AddMonths(-1);
            string      sql = "CDate>=#{0}# AND CDate<=#{1}#";

            data_mod[0] = (new ChartData()
            {
                name = legend.data[0], value = dt.Select("CDate>=#" + time_24 + "#").Length
            });
            data_mod[1] = (new ChartData()
            {
                name = legend.data[1], value = dt.Select(string.Format(sql, time_72, time_24)).Length
            });
            data_mod[2] = (new ChartData()
            {
                name = legend.data[2], value = dt.Select(string.Format(sql, time_d7, time_72)).Length
            });
            data_mod[3] = (new ChartData()
            {
                name = legend.data[3], value = dt.Select(string.Format(sql, time_d30, time_d7)).Length
            });
            data_mod[4] = (new ChartData()
            {
                name = legend.data[4], value = dt.Select("CDate<=#" + time_d30 + "#").Length
            });
            List <ChartSeries> seriesList = new List <ChartSeries>()
            {
                new ChartSeries()
                {
                    name     = "扩散速度",
                    data_mod = data_mod
                }
            };

            ((PieChartOption)option).AddData(legend, seriesList, "empy");
            return(option.ToString());
        }
Beispiel #19
0
        public CoreSize LoadLegend()
        {
            if (ChartLegend == null || LegendLocation == LegendLocation.None)
            {
                return(new CoreSize());
            }

            if (ChartLegend.Parent == null)
            {
                Canvas.Children.Add(ChartLegend);
            }

            var l = new List <SeriesViewModel>();

            for (var i = 0; i < Series.Count; i++)
            {
                var item = new SeriesViewModel();

                var series = (Series.Series)Series[i];

                item.Title           = series.Title;
                item.StrokeThickness = series.StrokeThickness;
                item.Stroke          = series.Stroke ?? new SolidColorBrush(GetDefaultColor(i));
                item.Fill            = series.Fill ?? new SolidColorBrush(GetDefaultColor(i))
                {
                    Opacity = series.DefaultFillOpacity
                };

                l.Add(item);
            }

            ChartLegend.Series = l;

            ChartLegend.InternalOrientation = LegendLocation == LegendLocation.Bottom ||
                                              LegendLocation == LegendLocation.Top
                ? Orientation.Horizontal
                : Orientation.Vertical;

            ChartLegend.UpdateLayout();
            ChartLegend.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));

            return(new CoreSize(ChartLegend.DesiredSize.Width,
                                ChartLegend.DesiredSize.Height));
        }
Beispiel #20
0
        /// <summary>
        /// Sets up the Legend style.
        /// </summary>
        /// <param name="chartXy"></param>
        private void SetupChartLegend(ChartXy chartXy)
        {
            ChartLegend legend = chartXy.Legend;

            legend.Placement          = Placement.Outside;
            legend.Alignment          = Alignment.TopCenter;
            legend.AlignVerticalItems = true;
            legend.Direction          = Direction.LeftToRight;

            ChartLegendVisualStyle lstyle = legend.ChartLegendVisualStyles.Default;

            lstyle.BorderThickness = new Thickness(1);
            lstyle.BorderColor     = new BorderColor(Color.Crimson);

            lstyle.Margin  = new DevComponents.DotNetBar.Charts.Style.Padding(8);
            lstyle.Padding = new DevComponents.DotNetBar.Charts.Style.Padding(4);

            lstyle.Background = new Background(Color.FromArgb(200, Color.White));
        }
Beispiel #21
0
        public CoreSize LoadLegend()
        {
            if (ChartLegend == null || LegendLocation == LegendLocation.None)
            {
                return(new CoreSize());
            }

            if (ChartLegend.Parent == null)
            {
                Canvas.Children.Add(ChartLegend);
            }

            var l = new List <SeriesViewModel>();

            foreach (var t in Series)
            {
                var item = new SeriesViewModel();

                var series = (Series.Series)t;

                item.Title           = series.Title;
                item.StrokeThickness = series.StrokeThickness;
                item.Stroke          = series.Stroke;
                item.Fill            = series.Fill;
                item.Geometry        = series.PointGeometry ?? Geometry.Parse("M 0,0.5 h 1,0.5 Z");

                l.Add(item);
            }

            ChartLegend.Series = l;

            ChartLegend.InternalOrientation = LegendLocation == LegendLocation.Bottom ||
                                              LegendLocation == LegendLocation.Top
                ? Orientation.Horizontal
                : Orientation.Vertical;

            ChartLegend.UpdateLayout();
            ChartLegend.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));

            return(new CoreSize(ChartLegend.DesiredSize.Width,
                                ChartLegend.DesiredSize.Height));
        }
        /// <summary>
        /// 饼状图数据处理
        /// </summary>
        /// <param name="lengendData">图例数据</param>
        /// <param name="seriesData">图表数据</param>
        /// <param name="isShowlengend">是否开启图例</param>
        /// <param name="charttitle">主标题文本,默认值:'','\n'指定换行</param>
        /// <param name="chatsubtitle"> 副标题文本,默认值:'','\n'指定换行</param>
        /// <param name="isCalculable"> 是否启用拖拽重计算特性,默认关闭</param>
        /// <returns></returns>
        public static string ChartPieDataProcess(IEnumerable <ChartPieSeries> seriesData, List <string> lengendData, bool isShowlengend = false, string charttitle = null, string chatsubtitle = null, bool isCalculable = false)
        {
            //标题
            var chartTitle = new ChartTitle()
            {
                text      = charttitle,
                subtext   = chatsubtitle,
                textStyle = new ChartTextStyle()
                {
                    fontSize = 20, fontWeight = "bolder", color = "#333"
                },
                x = "center",
                y = "center"
            };
            //提示框
            var chartTooltip = new ChartTooltip()
            {
                trigger = "item", formatter = "{a} <br/>{b} : {d}%"
            };
            //图例
            var chartLegend = new ChartLegend()
            {
                show = isShowlengend, data = lengendData
            };

            //数据
            var chartPieSeries = new List <ChartPieSeries>();

            chartPieSeries.AddRange(seriesData);
            var seriesDatas = chartPieSeries.Count > 0 ? chartPieSeries : (object)"-";

            var jsondata = new
            {
                title      = chartTitle,
                tooltip    = chartTooltip,
                calculable = isCalculable,
                legend     = chartLegend,
                series     = seriesDatas
            };

            return(jsondata.ToJson());
        }
Beispiel #23
0
        /// <summary>
        /// 设置属性
        /// </summary>
        protected override void SetAttributes()
        {
            ChartLegend control = this.ControlHost.Content as ChartLegend;

            if (control.LegendType == EChartLegendType.Legend)
            {
                this.HtmlWriter.AddAttribute("dojoType", "Controls/Charting/Legend");
            }
            else if (control.LegendType == EChartLegendType.SelectableLegend)
            {
                this.HtmlWriter.AddAttribute("dojoType", "Controls/Charting/SelectableLegend");
            }
            if (this.ProjectDocument != null && !string.IsNullOrEmpty(control.ChartRef))
            {
                this.HtmlWriter.AddAttribute("chartRef", this.ProjectDocument.Name + "_" + control.ChartRef);
                this.HtmlWriter.AddAttribute("id", this.ProjectDocument.Name + "_" + control.ChartRef + "_" + control.LegendType.ToString().ToLower());
            }

            base.SetAttributes();
        }
Beispiel #24
0
        private void SfChart_MouseMove(object sender, MouseEventArgs e)
        {
            var chart = sender as SfChart;

            if (isDragable)
            {
                var         position = e.GetPosition(chart);
                ChartLegend legend   = chart.Legend as ChartLegend;
                legend.OffsetX = position.X - (chart.SeriesClipRect.Left + legend.DesiredSize.Width / 2);
                legend.OffsetY = position.Y - (chart.SeriesClipRect.Top + legend.DesiredSize.Height / 2);

                if ((chart.Legend as ChartLegend).IsMouseOver)
                {
                    if (Mouse.OverrideCursor == null)
                    {
                        Mouse.OverrideCursor = Cursors.Hand;
                    }
                }
            }
        }
Beispiel #25
0
        async void OnAddChart(object sender, RoutedEventArgs e)
        {
            Worksheet sheet = _excel.ActiveSheet;

            if (sheet.Selections.Count == 0)
            {
                return;
            }

            CellRange range = sheet.Selections[0];
            Rect      rc    = sheet.GetRangeLocation(range);

            Chart ct = new Chart();

            ct.Width     = rc.Width;
            ct.Height    = rc.Height;
            ct.ChartType = _chart.ChartType;
            ct.Palette   = _chart.Palette;
            ct.Header    = _chart.Header;
            ChartLegend legend = _chart.Children[0] as ChartLegend;

            if (legend.Visibility == Visibility.Visible)
            {
                ChartLegend lg = new ChartLegend();
                lg.Title        = legend.Title;
                lg.Position     = legend.Position;
                lg.Orientation  = legend.Orientation;
                lg.OverlapChart = legend.OverlapChart;
                ct.Children.Add(lg);
            }
            ct.View.AxisX.Title = _chart.View.AxisX.Title;
            ct.View.AxisY.Title = _chart.View.AxisY.Title;
            ct.View.Inverted    = _chart.View.Inverted;
            ct.Data             = _data.GetData(ct.ChartType);

            RenderTargetBitmap bmp = new RenderTargetBitmap();
            await bmp.RenderAsync(_chart);

            sheet.AddPicture("pic" + sheet.Pictures.Count.ToString(), bmp, rc.Left, rc.Top, rc.Width, rc.Height);
        }
Beispiel #26
0
        public Pool()
        {
            this.InitializeComponent();
            this.Demands = new ObservableCollection <PieChartData>();
            MySqlDataReader reader = DataBaseHandler.GetData("SELECT DISTINCT StockName FROM Pool");

            while (reader.Read())
            {
                Demands.Add(new PieChartData((string)reader["StockName"]));
            }
            foreach (PieChartData pcd in Demands)
            {
                pcd.Value = DataBaseHandler.GetCount("SELECT COUNT(*) FROM Pool WHERE StockName = '" + pcd.Name + "'");
            }
            SfChart chart = new SfChart();

            chart.Header = "Stocks In Pool";
            CategoryAxis primaryCategoryAxis = new CategoryAxis();

            primaryCategoryAxis.Header = "Stocks";
            chart.PrimaryAxis          = primaryCategoryAxis;
            NumericalAxis secondaryNumericalAxis = new NumericalAxis();

            secondaryNumericalAxis.Header = "Percentage in Pool";
            chart.SecondaryAxis           = secondaryNumericalAxis;
            PieSeries series1 = new PieSeries();

            series1.ItemsSource  = this.Demands;
            series1.XBindingPath = "Name";
            series1.YBindingPath = "Value";
            chart.Series.Add(series1);
            ChartLegend legend = new ChartLegend();

            chart.Legend = legend;
            MainThing.Children.Add(chart);
        }
Beispiel #27
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ChartLegendBuilder" /> class.
 /// </summary>
 /// <param name="chartLegend">The chart legend.</param>
 public ChartLegendBuilder(ChartLegend chartLegend)
 {
     legend = chartLegend;
 }
Beispiel #28
0
 protected virtual void LoadLegend(ChartLegend legend)
 {
     legend.Series = Series.Select(x => new SeriesStandin
     {
         Fill = x.Fill,
         Stroke = x.Stroke,
         Title = x.Title
     });
     legend.Orientation = LegendLocation == LegendLocation.Bottom || LegendLocation == LegendLocation.Top
         ? Orientation.Horizontal
         : Orientation.Vertical;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ChartLegendBuilder" /> class.
 /// </summary>
 /// <param name="chartLegend">The chart legend.</param>
 public ChartLegendBuilder(ChartLegend chartLegend)
 {
     legend = chartLegend;
 }
Beispiel #30
0
        public void InitialiseData()
        {
            chartControl1.Series.Clear();

            Random      random  = new Random();
            ChartSeries series1 = new ChartSeries();

            series1.Name = "Year 2006";
            series1.Text = series1.Name;
            series1.Points.Add(0, 20);
            series1.Points.Add(2, 18);
            series1.Points.Add(3, 21);
            series1.Points.Add(4, 23);
            series1.Points.Add(5, 18);
            SeriesSettings(series1);
            this.chartControl1.Series.Add(series1);

            ChartSeries series2 = new ChartSeries();

            series2.Name = "Year 2007";
            series2.Text = series2.Name;
            series2.Points.Add(0, 12);
            series2.Points.Add(2, 21);
            series2.Points.Add(3, 18);
            series2.Points.Add(4, 25);
            series2.Points.Add(5, 24);
            SeriesSettings(series2);
            this.chartControl1.Series.Add(series2);

            ChartSeries series3 = new ChartSeries();

            series3.Name = "Year 2008";
            series3.Text = series3.Name;
            series3.Points.Add(0, 18);
            series3.Points.Add(2, 12);
            series3.Points.Add(3, 18);
            series3.Points.Add(4, 21);
            series3.Points.Add(5, 31);
            SeriesSettings(series3);
            this.chartControl1.Series.Add(series3);

            //Enable MultiplePies property to enable this feature.
            chartControl1.ChartArea.MultiplePies = true;
            this.chartControl1.ShowLegend        = true;

            series1.Type = ChartSeriesType.Pie;
            series2.Type = ChartSeriesType.Pie;
            series3.Type = ChartSeriesType.Pie;

            //Each series must have DoughnutCoEfficient value [except the most inner series example: series1], to get the complete functionality of this feature.
            series2.ConfigItems.PieItem.DoughnutCoeficient = 0.7f;
            series3.ConfigItems.PieItem.DoughnutCoeficient = 0.8f;

            series3.ConfigItems.PieItem.AngleOffset = 130f;
            series2.ConfigItems.PieItem.AngleOffset = 130f;
            series1.ConfigItems.PieItem.AngleOffset = 130f;

            ChartLegend chartLegend = new ChartLegend();

            chartLegend.Name = "Legend 1";
            string[] label = new string[] { "Engineering-13.33%", "Medical Sciences-16.67%", "BioTechnology-30%", "Information Services-23%", "Economics -27%" };
            List <ChartLegendItem> items = new List <ChartLegendItem>();

            for (int i = 0; i < 5; i++)
            {
                ChartLegendItem legendItem = new ChartLegendItem(label[i]);
                legendItem.Font = new Font("Segoe UI", 9, FontStyle.Regular);
                legendItem.RepresentationSize = new Size(16, 16);
                items.Add(legendItem);
            }

            chartControl1.Legend.RepresentationType = ChartLegendRepresentationType.SeriesType;
            chartControl1.Legend.CustomItems        = items.ToArray();
            chartControl1.Legend.RowsCount          = 5;
            this.chartControl1.LegendAlignment      = ChartAlignment.Center;
            this.chartControl1.SmoothingMode        = SmoothingMode.AntiAlias;
            this.chartControl1.Legend.DrawItemText += new LegendDrawItemTextEventHandler(Legend_DrawItemText);

            if (ckBxEnable3D.Checked)
            {
                this.lblPieHeight.Visible     = true;
                this.nUpDownPieHeight.Visible = true;
            }
            else
            {
                this.lblPieHeight.Visible     = false;
                this.nUpDownPieHeight.Visible = false;
            }
        }
Beispiel #31
0
        public CoreSize LoadLegend()
        {
            if (ChartLegend == null || LegendLocation == LegendLocation.None)
            {
                return(new CoreSize());
            }

            if (ChartLegend.Parent == null)
            {
                Canvas.Children.Add(ChartLegend);
            }

            var l = new List <SeriesViewModel>();

            foreach (var t in ActualSeries)
            {
                var item = new SeriesViewModel();

                var series = (Series)t;

                item.Title           = series.Title;
                item.StrokeThickness = series.StrokeThickness;
                item.Stroke          = series.Stroke;
                item.Fill            = ((Series)t) is IFondeable
                    ? ((IFondeable)t).PointForeround
                    : ((Series)t).Fill;
                item.PointGeometry = series.PointGeometry ?? Geometry.Parse("M 0,0.5 h 1,0.5 Z");

                l.Add(item);
            }

            var iChartLegend = ChartLegend as IChartLegend;

            if (iChartLegend == null)
            {
                throw new LiveChartsException("The current legend is not valid, ensure it implements IChartLegend");
            }

            iChartLegend.Series = l;

            var defaultLegend = ChartLegend as DefaultLegend;

            if (defaultLegend != null)
            {
                defaultLegend.InternalOrientation = LegendLocation == LegendLocation.Bottom ||
                                                    LegendLocation == LegendLocation.Top
                    ? Orientation.Horizontal
                    : Orientation.Vertical;

                defaultLegend.MaxWidth = defaultLegend.InternalOrientation == Orientation.Horizontal
                    ? ActualWidth
                    : double.PositiveInfinity;

                defaultLegend.MaxHeight = defaultLegend.InternalOrientation == Orientation.Vertical
                    ? ActualHeight
                    : double.PositiveInfinity;
            }

            ChartLegend.UpdateLayout();
            ChartLegend.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));

            return(new CoreSize(ChartLegend.DesiredSize.Width,
                                ChartLegend.DesiredSize.Height));
        }
Beispiel #32
0
            public GitHubTrendsChart()
            {
                TotalViewsSeries = new TrendsAreaSeries("Views", nameof(DailyViewsModel.LocalDay), nameof(DailyViewsModel.TotalViews), ColorConstants.DarkestBlue);
                TotalViewsSeries.SetBinding(ChartSeries.ItemsSourceProperty, nameof(TrendsViewModel.DailyViewsList));

                TotalUniqueViewsSeries = new TrendsAreaSeries("Unique Views", nameof(DailyViewsModel.LocalDay), nameof(DailyViewsModel.TotalUniqueViews), ColorConstants.MediumBlue);
                TotalUniqueViewsSeries.SetBinding(ChartSeries.ItemsSourceProperty, nameof(TrendsViewModel.DailyViewsList));

                TotalClonesSeries = new TrendsAreaSeries("Clones", nameof(DailyClonesModel.LocalDay), nameof(DailyClonesModel.TotalClones), ColorConstants.DarkNavyBlue);
                TotalClonesSeries.SetBinding(ChartSeries.ItemsSourceProperty, nameof(TrendsViewModel.DailyClonesList));

                TotalUniqueClonesSeries = new TrendsAreaSeries("Unique Clones", nameof(DailyClonesModel.LocalDay), nameof(DailyClonesModel.TotalUniqueClones), ColorConstants.LightNavyBlue);
                TotalUniqueClonesSeries.SetBinding(ChartSeries.ItemsSourceProperty, nameof(TrendsViewModel.DailyClonesList));

                this.SetBinding(IsVisibleProperty, nameof(TrendsViewModel.IsChartVisible));

                ChartBehaviors = new ChartBehaviorCollection
                {
                    new ChartZoomPanBehavior(),
                    new ChartTrackballBehavior()
                };

                Series = new ChartSeriesCollection
                {
                    TotalViewsSeries,
                    TotalUniqueViewsSeries,
                    TotalClonesSeries,
                    TotalUniqueClonesSeries
                };

                Legend = new ChartLegend
                {
                    DockPosition           = LegendPlacement.Bottom,
                    ToggleSeriesVisibility = true,
                    IconWidth  = 20,
                    IconHeight = 20,
                    LabelStyle = new ChartLegendLabelStyle {
                        TextColor = ColorConstants.DarkNavyBlue
                    }
                };

                var axisLabelStyle = new ChartAxisLabelStyle
                {
                    TextColor = ColorConstants.DarkNavyBlue,
                    FontSize  = 14
                };
                var axisLineStyle = new ChartLineStyle {
                    StrokeColor = ColorConstants.LightNavyBlue
                };

                PrimaryAxis = new DateTimeAxis
                {
                    IntervalType   = DateTimeIntervalType.Days,
                    Interval       = 1,
                    RangePadding   = DateTimeRangePadding.Round,
                    LabelStyle     = axisLabelStyle,
                    AxisLineStyle  = axisLineStyle,
                    MajorTickStyle = new ChartAxisTickStyle {
                        StrokeColor = Color.Transparent
                    },
                    ShowMajorGridLines = false
                };
                PrimaryAxis.SetBinding(DateTimeAxis.MinimumProperty, nameof(TrendsViewModel.MinDateValue));
                PrimaryAxis.SetBinding(DateTimeAxis.MaximumProperty, nameof(TrendsViewModel.MaxDateValue));

                SecondaryAxis = new NumericalAxis
                {
                    LabelStyle     = axisLabelStyle,
                    AxisLineStyle  = axisLineStyle,
                    MajorTickStyle = new ChartAxisTickStyle {
                        StrokeColor = ColorConstants.LightNavyBlue
                    },
                    ShowMajorGridLines = false
                };
                SecondaryAxis.SetBinding(NumericalAxis.MinimumProperty, nameof(TrendsViewModel.DailyViewsClonesMinValue));
                SecondaryAxis.SetBinding(NumericalAxis.MaximumProperty, nameof(TrendsViewModel.DailyViewsClonesMaxValue));

                BackgroundColor = Color.Transparent;

                ChartPadding = new Thickness(0, 5, 0, 0);
                Margin       = Device.RuntimePlatform is Device.iOS ? new Thickness(0, 5, 0, 15) : new Thickness(0, 5, 0, 0);
            }
		private void Page_Load(object sender, System.EventArgs e)
		{
		
			_questionId = 
				Information.IsNumeric(Request["QuestionId"]) ? int.Parse(Request["QuestionId"]) : -1;
			_filterId = 
				Information.IsNumeric(Request["FilterId"]) ? int.Parse(Request["FilterId"]) : -1;
			_sortOrder =
				Request["SortOrder"] == null ? "ans" : Request["SortOrder"];

			if (_questionId == -1)
			{
				Response.End();
			}
			else if (!NSurveyUser.Identity.IsAdmin &&
				!NSurveyUser.Identity.HasAllSurveyAccess)
			{
				if (!new Question().CheckQuestionUser(_questionId, NSurveyUser.Identity.UserId))
				{
					Response.End();
				}
			}

			ChartEngine engine = new ChartEngine();
			ChartCollection charts = new ChartCollection(engine);
			engine.Size = new Size(700, 500);
			engine.Charts = charts;
			
			
			PieChart pie = new PieChart();
			//pie.Colors = new Color[]{ Color.Red};

			ChartLegend legend = new ChartLegend();
			legend.Position = LegendPosition.Right;
			legend.Width = 200;
			legend.Background.Color = Color.FromArgb(245,249,251);
			
			pie.DataLabels.NumberFormat ="0.00";
			pie.Explosion = 6; 
			pie.Shadow.Visible = true; 
			pie.Shadow.Color=Color.LightGray; 
			pie.Shadow.OffsetY = 5; 
			engine.HasChartLegend = true;
			engine.Legend = legend;
			engine.GridLines = GridLines.None;


			SetQuestionData(engine, pie);
			SetMoreProperties(engine);

			charts.Add(pie);


			// send chart to browser
			Bitmap bmp;
			System.IO.MemoryStream memStream = new System.IO.MemoryStream();
			bmp = engine.GetBitmap();
			bmp.Save(memStream, System.Drawing.Imaging.ImageFormat.Png);
			memStream.WriteTo(Response.OutputStream);
			Response.End();

		}
 public ChartLegendSerializerTests()
 {
     legend = new ChartLegend();
 }