System.Web.UI.DataVisualization.Charting 和 Rangebar 图表集成

System.Web.UI.DataVisualization.Charting and Rangebar chart integration

通过使用以下代码,我的图表在代码之后看起来像下图。

我现在的问题是条形和 y 轴点没有正确对齐。

如何在同一行中显示范围栏及其对应的 y 轴值?

List<dummyGraph> objGraphList = new List<dummyGraph>();
        dummyGraph objDummyGraph = new dummyGraph();
        objDummyGraph.TKFEType = "Underwriter";
        objDummyGraph.min = 1;
        objDummyGraph.max = 8;
        objDummyGraph.Median = 1;
        objGraphList.Add(objDummyGraph);

        objDummyGraph = new dummyGraph();
        objDummyGraph.TKFEType = "Construction";
        objDummyGraph.min = 2;
        objDummyGraph.max = 5;
        objDummyGraph.Median = 2;
        objGraphList.Add(objDummyGraph);

        objDummyGraph = new dummyGraph();
        objDummyGraph.TKFEType = "Design";
        objDummyGraph.min = 3;
        objDummyGraph.max = 6;
        objDummyGraph.Median = 3;
        objGraphList.Add(objDummyGraph);

        objDummyGraph = new dummyGraph();
        objDummyGraph.TKFEType = "Partner";
        objDummyGraph.min = 4;
        objDummyGraph.max = 6;
        objDummyGraph.Median = 3;
        objGraphList.Add(objDummyGraph);

        System.Web.UI.DataVisualization.Charting.Chart chart1 = new System.Web.UI.DataVisualization.Charting.Chart();
        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 seriesInstance;
        List<System.Web.UI.DataVisualization.Charting.Series> seriesList = new List<System.Web.UI.DataVisualization.Charting.Series>();

        int xordinal = 0;

        foreach (var i in objGraphList)
        {
            seriesInstance = new System.Web.UI.DataVisualization.Charting.Series(i.TKFEType);

            seriesInstance.ChartType = SeriesChartType.RangeBar;
            seriesInstance.Color = Color.SkyBlue;
            seriesInstance.YValuesPerPoint = 2;
            seriesInstance.AxisLabel = i.TKFEType;

            double yplot1 = (double)i.min;
            double yplot2 = (double)i.max;

            seriesInstance.IsValueShownAsLabel = true;

            xordinal = xordinal + 1;
            seriesInstance.Points.AddXY(xordinal, yplot1, yplot2);                

            chart1.Series.Add(seriesInstance);
        }

        chart1.ChartAreas.Add(chartArea1);
        chart1.ChartAreas[0].AxisY.Interval = 1;

        chartArea1 = chart1.ChartAreas[0];

        chartArea1.AxisY.IsStartedFromZero = true;
        chartArea1.AxisY.Enabled = AxisEnabled.False;


        chartArea1.AlignmentOrientation = AreaAlignmentOrientations.All;

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

样条图疑惑

我有一个样条图。我需要显示从 x(例如:Underwriter)到 y(例如:200)的直线,如下图所示。我该怎么做?

更新代码:

  public ActionResult MMBRChart()
    {
        //Area for generating line chart
        List<dummyGraph> objGraphList = new List<dummyGraph>();
        dummyGraph objDummyGraph = new dummyGraph();
        objDummyGraph.TKFEType = "Underwriter";
        objDummyGraph.min = 1;
        objDummyGraph.max = 8;
        objDummyGraph.Median = "201";
        objGraphList.Add(objDummyGraph);

        objDummyGraph = new dummyGraph();
        objDummyGraph.TKFEType = "Construction";
        objDummyGraph.min = 2;
        objDummyGraph.max = 5;
        objDummyGraph.Median = "187";
        objGraphList.Add(objDummyGraph);

        objDummyGraph = new dummyGraph();
        objDummyGraph.TKFEType = "Design";
        objDummyGraph.min = 3;
        objDummyGraph.max = 6;
        objDummyGraph.Median = "243";
        objGraphList.Add(objDummyGraph);

        objDummyGraph = new dummyGraph();
        objDummyGraph.TKFEType = "Partner";
        objDummyGraph.min = 4;
        objDummyGraph.max = 6;
        objDummyGraph.Median = "200";
        objGraphList.Add(objDummyGraph);

        objDummyGraph = new dummyGraph();
        objDummyGraph.TKFEType = "Auditor";
        objDummyGraph.min = 4;
        objDummyGraph.max = 6;
        objDummyGraph.Median = "29";
        objGraphList.Add(objDummyGraph);

        objDummyGraph = new dummyGraph();
        objDummyGraph.TKFEType = "Associate";
        objDummyGraph.min = 4;
        objDummyGraph.max = 6;
        objDummyGraph.Median = "198";
        objGraphList.Add(objDummyGraph);

        System.Web.UI.DataVisualization.Charting.Chart chart1 = new System.Web.UI.DataVisualization.Charting.Chart();
        System.Web.UI.DataVisualization.Charting.Chart lineChart1 = new System.Web.UI.DataVisualization.Charting.Chart();
        System.Web.UI.DataVisualization.Charting.ChartArea chartArea1 = new System.Web.UI.DataVisualization.Charting.ChartArea();
        System.Web.UI.DataVisualization.Charting.ChartArea linechartArea1 = new System.Web.UI.DataVisualization.Charting.ChartArea("lineChart");
        System.Web.UI.DataVisualization.Charting.Legend legend1 = new System.Web.UI.DataVisualization.Charting.Legend();
        System.Web.UI.DataVisualization.Charting.Series seriesInstance = new Series();

        chart1.Titles.Add("Median MBR");//Add chart title 
        chart1.Series.Add(seriesInstance);
        chart1.Series[0].Points.DataBindXY(objGraphList.Select(x => x.TKFEType).ToList(), objGraphList.Select(x => x.Median).ToList());
        chart1.Series[0].ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Spline;
        chart1.Series[0].Color = Color.SkyBlue;
        chart1.Series[0].BorderWidth = 2;
        chart1.Series[0].MarkerStyle = MarkerStyle.Circle;
        chart1.Series[0].MarkerColor = Color.Blue;
        chart1.Series[0].Name = "MyGraph";

        seriesInstance = new System.Web.UI.DataVisualization.Charting.Series("lineSeries");
        //seriesInstance.ChartType = SeriesChartType.Bar;//Set chart type here
        seriesInstance.Color = Color.SkyBlue;
        seriesInstance.YValuesPerPoint = 2;

        chart1.Series.Add(seriesInstance);

        int j = 0;

        foreach (var p in objGraphList)
        {
            //chart1.Series[1].Points.AddXY(j, p.max);
            j = j + 1;
            chart1.Series[1].ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Bar;
            chart1.Series[1].Points.AddXY(p.TKFEType, p.Median);
            chart1.Series[1].Color = Color.Green;
            chart1.Series[1].BorderWidth = 2;
            chart1.Series[1].ToolTip = "#VALY, #VALX";
        }


        chart1.ChartAreas.Add(chartArea1);

        chart1.ChartAreas[0].Area3DStyle.Enable3D = false;
        chart1.ChartAreas[0].AxisX.MajorGrid.LineColor = Color.FromArgb(50, 200, 200, 200);
        chart1.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.FromArgb(50, 200, 200, 200);

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

您正在向图表中添加多个系列。不确定那是你的意图。此外,您使用 TKFEType 作为标签,而不是轴的实际值。这些因素加在一起可能会使您的图表错位。这是我的建议:

        List<DummyGraph> list1 = new List<DummyGraph>();
        list1.Add(new DummyGraph { TKFEType = "Underwritter", Min = 1, Max = 8, Median = 1 });
        list1.Add(new DummyGraph { TKFEType = "Construction", Min = 2, Max = 5, Median = 2 });
        list1.Add(new DummyGraph { TKFEType = "Design", Min = 3, Max = 6, Median = 3 });
        list1.Add(new DummyGraph { TKFEType = "Partner", Min = 4, Max = 6, Median = 4 });

        Chart1.DataSource = list1;
        Chart1.Series[0].XValueMember = "TKFEType";
        Chart1.Series[0].YValueMembers = "Min, Max";
        Chart1.DataBind();