通过使用以下代码,我的图表在代码之后看起来像下面的图像。
我现在的问题是条形图和 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");
}
}