예제 #1
0
        /// <summary>
        /// Returns a bar chart for a given set of values.
        /// </summary>
        /// <param name="seriesSet"></param>
        /// <param name="xValues"></param>
        /// <param name="title"></param>
        /// <returns></returns>
        public static DotNet.Highcharts.Highcharts GetBarChart(List <DotNet.Highcharts.Options.Series> seriesSet, List <string> xValues, string title)
        {
            DotNet.Highcharts.Highcharts chart = new DotNet.Highcharts.Highcharts(title);
            chart.InitChart(new Chart
            {
                Height            = 320,
                Width             = 320,
                DefaultSeriesType = ChartTypes.Column
            });

            chart.SetXAxis(new XAxis
            {
                Categories = xValues.ToArray()
            });

            chart.SetLegend(new Legend {
                Enabled = false
            });
            chart.SetSeries(seriesSet.ToArray());

            chart.SetTitle(new DotNet.Highcharts.Options.Title {
                Text = title.Replace("_", " ")
            });

            return(chart);
        }
예제 #2
0
        public PartialViewResult GetChart()
        {
            DotNet.Highcharts.Highcharts chart = new DotNet.Highcharts.Highcharts("chart");

            //初始化
            DotNet.Highcharts.Options.Chart chartOption = new DotNet.Highcharts.Options.Chart();
            chartOption.DefaultSeriesType = DotNet.Highcharts.Enums.ChartTypes.Line;
            chartOption.Width             = 400;
            chartOption.Height            = 400;
            chart.InitChart(chartOption);

            //设置标题
            DotNet.Highcharts.Options.Title title = new DotNet.Highcharts.Options.Title();
            title.Align = DotNet.Highcharts.Enums.HorizontalAligns.Center;
            title.Text  = "图表";
            chart.SetTitle(title);

            //提示
            DotNet.Highcharts.Options.Tooltip tooltip = new DotNet.Highcharts.Options.Tooltip();
            tooltip.ValueSuffix = "摄氏度";
            chart.SetTooltip(tooltip);

            DotNet.Highcharts.Options.PlotOptions plotOptions = new DotNet.Highcharts.Options.PlotOptions();
            plotOptions.Bar                    = new DotNet.Highcharts.Options.PlotOptionsBar();
            plotOptions.Bar.DataLabels         = new DotNet.Highcharts.Options.PlotOptionsBarDataLabels();
            plotOptions.Bar.DataLabels.Enabled = true;
            chart.SetPlotOptions(plotOptions);

            //横坐标
            DotNet.Highcharts.Options.XAxis xs = new DotNet.Highcharts.Options.XAxis {
                Categories = new[] { "jan", "feb" }
            };
            List <string> cList = new List <string>();

            cList.Add("jan");
            cList.Add("feb");
            xs.Categories = cList.ToArray();
            xs.Title      = new DotNet.Highcharts.Options.XAxisTitle();
            xs.Title.Text = "月份";
            chart.SetXAxis(xs);

            //纵坐标
            DotNet.Highcharts.Options.YAxis ys = new DotNet.Highcharts.Options.YAxis();
            ys.Title      = new DotNet.Highcharts.Options.YAxisTitle();
            ys.Title.Text = "温度";
            chart.SetYAxis(ys);

            //设置表现值
            DotNet.Highcharts.Options.Series ss = new DotNet.Highcharts.Options.Series();
            List <object> oList = new List <object>();

            oList.Add(29);
            oList.Add(33);
            ss.Data = new DotNet.Highcharts.Helpers.Data(oList.ToArray());
            ss.Name = "温度";
            chart.SetSeries(ss);

            return(PartialView("_PartialChartView", chart));
        }
예제 #3
0
        public DotNet.Highcharts.Highcharts GetChart(SimpleChartModel chartModel)
        {
            DotNet.Highcharts.Highcharts chart = new DotNet.Highcharts.Highcharts(chartModel.ContainerId);

            //初始化
            DotNet.Highcharts.Options.Chart chartOption = new DotNet.Highcharts.Options.Chart();
            chartOption.DefaultSeriesType = chartModel.ChartType;
            chartOption.Width             = chartModel.Width;
            chartOption.Height            = chartModel.Height;
            chart.InitChart(chartOption);

            //设置标题
            DotNet.Highcharts.Options.Title title = new DotNet.Highcharts.Options.Title();
            title.Align = DotNet.Highcharts.Enums.HorizontalAligns.Center;
            title.Text  = chartModel.Title;
            chart.SetTitle(title);

            //提示
            DotNet.Highcharts.Options.Tooltip tooltip = new DotNet.Highcharts.Options.Tooltip();
            tooltip.ValueSuffix = chartModel.ValueSuffix;
            chart.SetTooltip(tooltip);

            DotNet.Highcharts.Options.PlotOptions plotOptions = new DotNet.Highcharts.Options.PlotOptions();
            plotOptions.Bar                    = new DotNet.Highcharts.Options.PlotOptionsBar();
            plotOptions.Bar.DataLabels         = new DotNet.Highcharts.Options.PlotOptionsBarDataLabels();
            plotOptions.Bar.DataLabels.Enabled = true;
            chart.SetPlotOptions(plotOptions);

            //横坐标
            DotNet.Highcharts.Options.XAxis xs = new DotNet.Highcharts.Options.XAxis();
            xs.Categories = chartModel.XList.ToArray();
            xs.Title      = new DotNet.Highcharts.Options.XAxisTitle();
            xs.Title.Text = chartModel.XTitle;
            chart.SetXAxis(xs);

            //纵坐标
            DotNet.Highcharts.Options.YAxis ys = new DotNet.Highcharts.Options.YAxis();
            ys.Title      = new DotNet.Highcharts.Options.YAxisTitle();
            ys.Title.Text = chartModel.YTitle;
            chart.SetYAxis(ys);

            //设置表现值
            List <DotNet.Highcharts.Options.Series> ssList = new List <DotNet.Highcharts.Options.Series>();

            foreach (YSeries yserires in chartModel.SeriesList)
            {
                DotNet.Highcharts.Options.Series ss = new DotNet.Highcharts.Options.Series();
                ss.Data = new DotNet.Highcharts.Helpers.Data(yserires.YSeriesList.ToArray());
                ss.Name = yserires.YName;
                ssList.Add(ss);
            }
            chart.SetSeries(ssList.ToArray());

            return(chart);
        }
 public static DotNet.Highcharts.Highcharts GetPieChart(Series seriesSet, string title)
 {
     DotNet.Highcharts.Highcharts chart = new DotNet.Highcharts.Highcharts(title);
     chart.InitChart(new Chart
     {
         Height            = 250,
         Width             = 250,
         DefaultSeriesType = ChartTypes.Pie
     });
     chart.SetSeries(seriesSet);
     chart.SetTitle(new DotNet.Highcharts.Options.Title {
         Text = title
     });
     return(chart);
 }
예제 #5
0
        public DotNet.Highcharts.Highcharts GetPieChart(SimpleChartModel chartModel)
        {
            DotNet.Highcharts.Highcharts chart = new DotNet.Highcharts.Highcharts(chartModel.ContainerId);

            //初始化
            DotNet.Highcharts.Options.Chart chartOption = new DotNet.Highcharts.Options.Chart();
            chartOption.DefaultSeriesType = chartModel.ChartType;
            chartOption.Width             = chartModel.Width;
            chartOption.Height            = chartModel.Height;
            chart.InitChart(chartOption);

            //设置标题
            DotNet.Highcharts.Options.Title title = new DotNet.Highcharts.Options.Title();
            title.Align = DotNet.Highcharts.Enums.HorizontalAligns.Center;
            title.Text  = chartModel.Title;
            chart.SetTitle(title);

            //提示
            DotNet.Highcharts.Options.Tooltip tooltip = new DotNet.Highcharts.Options.Tooltip();
            tooltip.ValueSuffix = chartModel.ValueSuffix;
            tooltip.PointFormat = "{point.name}: <b>{point.y}</b>";
            chart.SetTooltip(tooltip);

            //饼图
            DotNet.Highcharts.Options.PlotOptions plotOptions = new DotNet.Highcharts.Options.PlotOptions();
            plotOptions.Pie = new DotNet.Highcharts.Options.PlotOptionsPie();
            plotOptions.Pie.AllowPointSelect   = true;
            plotOptions.Pie.Cursor             = DotNet.Highcharts.Enums.Cursors.Pointer;
            plotOptions.Pie.ShowInLegend       = true;
            plotOptions.Pie.DataLabels         = new DotNet.Highcharts.Options.PlotOptionsPieDataLabels();
            plotOptions.Pie.DataLabels.Enabled = true;
            plotOptions.Pie.DataLabels.Format  = "<b>{point.name}</b>: {point.y}个";
            chart.SetPlotOptions(plotOptions);

            //设置表现值
            List <DotNet.Highcharts.Options.Series> ssList = new List <DotNet.Highcharts.Options.Series>();

            DotNet.Highcharts.Options.Series ss = new DotNet.Highcharts.Options.Series();
            ss.Type = DotNet.Highcharts.Enums.ChartTypes.Pie;
            ss.Name = chartModel.Title;
            ss.Data = new DotNet.Highcharts.Helpers.Data(chartModel.pieDataList.ToArray());
            ssList.Add(ss);
            chart.SetSeries(ssList.ToArray());

            return(chart);
        }
        public static DotNet.Highcharts.Highcharts GetLineChart(List<DotNet.Highcharts.Options.Series> seriesSet, List<string> xValues, string title,int dimensions=300)
        {
            DotNet.Highcharts.Highcharts chart = new DotNet.Highcharts.Highcharts(title);
            chart.InitChart(new Chart
            {
                Height = dimensions,
                Width = dimensions
            });

            chart.SetXAxis(new XAxis
            {
                Categories = xValues.ToArray()

            });
            chart.SetSeries(seriesSet.ToArray());
            chart.SetTitle(new DotNet.Highcharts.Options.Title { Text = title });
            return chart;
        }
        public static DotNet.Highcharts.Highcharts GetAreaChart(List<DotNet.Highcharts.Options.Series> seriesSet, List<string> xValues, string title)
        {
            DotNet.Highcharts.Highcharts chart = new DotNet.Highcharts.Highcharts(title);
            chart.InitChart(new Chart
            {
                Height = 300,
                Width = 300,
                DefaultSeriesType = ChartTypes.Area
            });

            chart.SetXAxis(new XAxis
            {
                Categories = xValues.ToArray()

            });
            chart.SetSeries(seriesSet.ToArray());
            chart.SetTitle(new DotNet.Highcharts.Options.Title { Text = title });
            return chart;
        }
        public static DotNet.Highcharts.Highcharts GetLineChart(List <DotNet.Highcharts.Options.Series> seriesSet, List <string> xValues, string title, int dimensions = 300)
        {
            DotNet.Highcharts.Highcharts chart = new DotNet.Highcharts.Highcharts(title);
            chart.InitChart(new Chart
            {
                Height = dimensions,
                Width  = dimensions
            });

            chart.SetXAxis(new XAxis
            {
                Categories = xValues.ToArray()
            });
            chart.SetSeries(seriesSet.ToArray());
            chart.SetTitle(new DotNet.Highcharts.Options.Title {
                Text = title
            });
            return(chart);
        }
        public static DotNet.Highcharts.Highcharts GetAreaChart(List <DotNet.Highcharts.Options.Series> seriesSet, List <string> xValues, string title)
        {
            DotNet.Highcharts.Highcharts chart = new DotNet.Highcharts.Highcharts(title);
            chart.InitChart(new Chart
            {
                Height            = 300,
                Width             = 300,
                DefaultSeriesType = ChartTypes.Area
            });

            chart.SetXAxis(new XAxis
            {
                Categories = xValues.ToArray()
            });
            chart.SetSeries(seriesSet.ToArray());
            chart.SetTitle(new DotNet.Highcharts.Options.Title {
                Text = title
            });
            return(chart);
        }
예제 #10
0
        public static DotNet.Highcharts.Highcharts GetHighChart(ChartOption option)
        {
            DotNet.Highcharts.Highcharts highChart = new DotNet.Highcharts.Highcharts(option.Name);

            var xa = new XAxis()
            {
                Type = AxisTypes.Category
            };

            if (option.XAxisData != null)
            {
                xa.Categories = option.XAxisData;
            }

            var chart = new Chart
            {
                Type = option.ChartType,
                DefaultSeriesType = option.ChartType
            };

            if (option.AjaxLoading)
            {
                chart.Events = new ChartEvents()
                {
                    Load      = "FetchDataFunc",
                    Drilldown = "function(e) { DrillDownFunc(e) }",
                    Drillup   = "function(e) { FetchDataFunc() }"
                };
                chart.Style = "fontWeight: 'normal', fontFamily: 'IRANSans'";

                //
                // Create Ajax loading address by rout params
                var url = $@"""{option.LoadDataUrl}""";
                // add rout params
                if (option.AjaxRoutParams.Any())
                {
                    url += "/?";
                    for (int i = 0; i < option.AjaxRoutParams.Count; i++)
                    {
                        var param = option.AjaxRoutParams[i];
                        url += $"{param.Key}={param.Value}&";
                    }
                }

                var totalAmount = (option.SubTitleFunc ?? "").ToLower().Equals("sum")
                    ? @"+ sum(dataArr, 'y')" // calc sum of data
                    : "";



                highChart.AddJavascripVariable("ChartParentUrl", url)
                .AddJavascripFunction("FetchDataFunc", $@"                            
                             $.get(ChartParentUrl, function (dataArr) {{ 
                            {option.Name}.series[0].setData(dataArr);
                            var subTitleByTotal = '{option.SubTitle}' {totalAmount};
                            {option.Name}.setTitle(null, {{ text: subTitleByTotal }});  
                         }});
                ")
                .AddJavascripFunction("DrillDownFunc",
                                      $@"
                                if (!e.seriesOptions) {{                                                
                                                var tChart = {option.Name};
                                                tChart.showLoading('در حال بار گذاری داده ها');

                                                $.get(e.point.drilldown_url + ""/"" + e.point.id, function (dataArr) {{
                                                    drilldownData = {{
                                                        name: e.point.name,
                                                        id: e.point.id,
                                                        data: dataArr
                                                    }}
                                                    ChartParentUrl = dataArr[0].drillup_url;
                                                    tChart.hideLoading();
                                                    tChart.addSeriesAsDrilldown(e.point, drilldownData);

                                                    var subTitleByTotal = '{option.SubTitle}' {totalAmount};
                                                    tChart.setTitle(null, {{ text: subTitleByTotal }});            
                                                }});

                                            }}
                ", "e");
            }

            highChart.InitChart(chart)
            .SetTitle(new Title
            {
                Text = option.Tilte
            })
            .SetSubtitle(new Subtitle
            {
                Text = option.SubTitle
            })
            .SetExporting(new Exporting {
                Enabled = true
            })
            .SetPlotOptions(new PlotOptions
            {
                Column = new PlotOptionsColumn()
                {
                    //Point = new PlotOptionsColumnPoint { Events = new PlotOptionsColumnPointEvents { Click = "ColumnPointClick" } },
                    Cursor     = Cursors.Pointer,
                    DataLabels = new PlotOptionsColumnDataLabels
                    {
                        //Style = "fontWeight: 'bold', fontFamily: 'B Nazanin'",
                        Enabled   = option.ShowDataLabels,
                        Color     = Color.AliceBlue,
                        Formatter = "function() { return '<div style=\"color: black;\">' + this.y.toLocaleString('fa-IR'); + '</div>'; }"
                    }
                }
            })
            .SetXAxis(xa)
            .SetSeries(new Series
            {
                Type = option.ChartType,
                Name = option.SeriesName,
                Data = option.YAxisData ?? new Data(new object[0, 0]),
                PlotOptionsColumn = new PlotOptionsColumn()
                {
                    ColorByPoint = option.ColorByPoint
                }
            })
            .SetYAxis(new YAxis
            {
                Title = new YAxisTitle()
                {
                    Text = option.YAxisTitle
                },
                Labels = new YAxisLabels
                {
                    Formatter = "function() { return '<div Locale=\"fa-IR\" style =\"color: black;\">'+ this.axis.defaultLabelFormatter.call(this) +'</div>'; }",
                    Style     = "color: '#89A54E'",
                    Align     = HorizontalAligns.Left,
                    X         = 3,
                    Y         = 16
                },
                ShowFirstLabel = false
            })
            .SetTooltip(new Tooltip
            {
                //UseHTML = true,
                //HeaderFormat = "<small dir=\"rtl\">{point.key}</small><table dir =\"rtl\">",
                //PointFormat = "<tr><td style=\"color= {series.color}\"></td>" +
                //                  "<td><b>{point.y} ریال</b></td></tr>",
                //FooterFormat = "</table>",
                //ValueDecimals = 0,
                //Style = "fontWeight: 'normal', fontFamily: 'B Nazanin'"
                Crosshairs = new Crosshairs(true),
                Formatter  = "TooltipFormatter"
            })
            .AddJavascripFunction(
                "TooltipFormatter",
                @"var s = '<div dir=""rtl"">' + this.point.name +':<b>  '+ this.y.toLocaleString('fa-IR') +' ریال</b><br/>';
                      return s;"
                )
            .SetLegend(new Legend
            {
                Enabled       = option.ShowLegend,
                Rtl           = true,
                Align         = HorizontalAligns.Left,
                VerticalAlign = VerticalAligns.Top,
                Y             = 20,
                Floating      = true,
                BorderWidth   = 0
            })
            .SetOptions(new GlobalOptions()
            {
                Lang = new DotNet.Highcharts.Helpers.Lang()
                {
                    //DrillUpText = "",
                    Loading           = "در حال بارگزاری",
                    PrintButtonTitle  = "چاپ",
                    ThousandsSep      = ",",
                    DecimalPoint      = ".",
                    DownloadJPEG      = "JPEG دانلود عکس",
                    DownloadPDF       = "PDF دانلود در قالب",
                    DownloadPNG       = "PNG دانلود عکس",
                    DownloadSVG       = "SGV دانلود فایل",
                    ExportButtonTitle = "خروج"
                }
            });



            return(highChart);
        }
        /// <summary>
        /// Returns a bar chart for a given set of values.
        /// </summary>
        /// <param name="seriesSet"></param>
        /// <param name="xValues"></param>
        /// <param name="title"></param>
        /// <returns></returns>
        public static DotNet.Highcharts.Highcharts GetBarChart(List<DotNet.Highcharts.Options.Series> seriesSet, List<string> xValues, string title)
        {
            DotNet.Highcharts.Highcharts chart = new DotNet.Highcharts.Highcharts(title);
            chart.InitChart(new Chart
            {
                Height = 320,
                Width = 320,
                DefaultSeriesType = ChartTypes.Column
            });

            chart.SetXAxis(new XAxis
            {
                Categories = xValues.ToArray()

            });

            chart.SetLegend(new Legend { Enabled = false });
            chart.SetSeries(seriesSet.ToArray());

            chart.SetTitle(new DotNet.Highcharts.Options.Title { Text = title.Replace("_", " ")});
            
            return chart;
        }
 public static DotNet.Highcharts.Highcharts GetPieChart(Series seriesSet, string title)
 {
     DotNet.Highcharts.Highcharts chart = new DotNet.Highcharts.Highcharts(title);
     chart.InitChart(new Chart
     {
         Height = 250,
         Width = 250,
         DefaultSeriesType = ChartTypes.Pie
     });          
     chart.SetSeries(seriesSet);
     chart.SetTitle(new DotNet.Highcharts.Options.Title { Text = title });
     return chart;
 }