1

这就是我到目前为止所做的。请仔细阅读整个描述以了解我的要求

        System.Web.UI.DataVisualization.Charting.ChartArea chartArea1 = new System.Web.UI.DataVisualization.Charting.ChartArea();
        System.Web.UI.DataVisualization.Charting.Legend legend1 = new System.Web.UI.DataVisualization.Charting.Legend();
        System.Web.UI.DataVisualization.Charting.Series series1 = new System.Web.UI.DataVisualization.Charting.Series();
        System.Web.UI.DataVisualization.Charting.Series series2 = new System.Web.UI.DataVisualization.Charting.Series();
        System.Web.UI.DataVisualization.Charting.Chart chart1 = new System.Web.UI.DataVisualization.Charting.Chart();
        //((System.ComponentModel.ISupportInitialize)(chart1)).BeginInit();
        //this.SuspendLayout();
        // 
        // chart1
        // 
        chartArea1.Name = "ChartArea1";
        chart1.ChartAreas.Add(chartArea1);
        legend1.Name = "Legend1";
        chart1.Legends.Add(legend1);
        //chart1.Location = new System.Drawing.Point(49, 62);
        //chart1.Name = "chart1";
        series1.ChartArea = "ChartArea1";
        series1.ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.StackedBar;
        series1.Legend = "Legend1";
        series1.Name = "Series2";
        series2.ChartArea = "ChartArea1";
        series2.ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.StackedBar;
        series2.Legend = "Legend1";
        series2.Name = "Series3";
        chart1.Series.Add(series1);
        chart1.Series.Add(series2);
        //chart1.Size = new System.Drawing.Size(534, 300);
        chart1.TabIndex = 0;
        //chart1.Text = "chart1";

        chart1.Series["Series2"].Points.Add(new DataPoint(1, 1));
        chart1.Series["Series2"].Points.Add(new DataPoint(2, 4));
        chart1.Series["Series2"].Points.Add(new DataPoint(3, 5));
        chart1.Series["Series3"].Points.Add(new DataPoint(2, 3));

        chart1.Series["Series2"].IsValueShownAsLabel = true;
        chart1.Series["Series3"].IsValueShownAsLabel = true;

        using (MemoryStream ms = new MemoryStream())
        {
            chart1.SaveImage(ms, ChartImageFormat.Png);
            return File(ms.ToArray(), "image/png");
        }

这将给出以下图表。

在此处输入图像描述

但我需要的是如下图,其中包含开始值和结束值

在此处输入图像描述

我如何得到它?

更新:我希望显示的数据存储在一个列表中,如下所示

   List<dummyGraph> objGraphList = new List<dummyGraph>();

        dummyGraph objDummyGraph = new dummyGraph();
        objDummyGraph.RiskCategories = "Compliance,Law,Legislation";
        objDummyGraph.HighImpactRisks = "4";
        objDummyGraph.MediumImpactRisks = "1";
        objDummyGraph.LowImpactRisks = "0";
        objDummyGraph.NoImpactRisks = "5";
        objDummyGraph.index = 1;

        objGraphList.Add(objDummyGraph);

        objDummyGraph = new dummyGraph();

        objDummyGraph.RiskCategories = "Construction";
        objDummyGraph.HighImpactRisks = "5";
        objDummyGraph.MediumImpactRisks = "1";
        objDummyGraph.LowImpactRisks = "4";
        objDummyGraph.NoImpactRisks = "0";
        objDummyGraph.index = 2;

        objGraphList.Add(objDummyGraph);
4

1 回答 1

2

也许SeriesChartType.RangeBar图表类型会比SeriesChartType.StackedBar

这是一个参考:https ://msdn.microsoft.com/en-us/library/vstudio/dd456745(v=vs.100).aspx

于 2015-08-13T13:04:05.090 回答