예제 #1
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));
        }
예제 #2
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);
        }
예제 #3
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);
        }