1

次のコードを使用すると、私のチャートは次のコードの画像のようになります。

私の質問は、バーと 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 (例: 保険会社) から 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");
        }
    }
4

1 に答える 1

1

グラフに複数の系列を追加しています。それがあなたの意図であったかどうかはわかりません。また、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();

ここに画像の説明を入力

于 2015-08-18T18:24:45.263 に答える