2017-01-30 55 views
1

我很难用英文解释。 目前,我创建了如下图所示的图表。C#快速折线图

My Chart

与此代码:

public void CreateChart(DataTable chartTable ,string serieName) 
{ 

    var chartArea = new ChartArea(); 
    chartArea.AxisX.LabelStyle.Format = "dd/MM/yyy"; 
    chartArea.AxisX.MajorGrid.LineColor = Color.LightGray; 
    chartArea.AxisY.MajorGrid.LineColor = Color.LightGray; 
    chartArea.AxisX.LabelStyle.Font = new Font("Consolas", 6); 
    chartArea.AxisY.LabelStyle.Font = new Font("Consolas", 6); 
    chart1.ChartAreas.Add(chartArea); 


    var series = new Series(); 
    series.Name = "TEMP_STACK_BOILER_1"; 
    series.ChartType = SeriesChartType.FastLine; 
    series.XValueType = ChartValueType.DateTime; 
    series.YValueType = ChartValueType.Double; 
    chart1.Series.Add(series); 



    int lastrow = chartTable.Rows.Count - 4; 

    string[] xval = new string[lastrow]; 
    int[] yval = new int[lastrow]; 


    // bind the datapoints 

    chart1.ChartAreas[0].AxisY.Maximum = 1000; 
    chart1.ChartAreas[0].AxisY.Minimum = 0; 

    for (int i = 0; i < lastrow; i++) 
    { 
     xval[i] = chartTable.Rows[i][1].ToString() + "\r\n" +chartTable.Rows[i][0].ToString() ; 
     yval[i] = Convert.ToInt32(chartTable.Rows[i][serieName]);   
    } 

    chart1.Series[serieName].Points.DataBindXY(xval, yval); 
    chart1.Invalidate(); 
} 

但我想显示y值如图片 说明我不知道什么叫。 (请参见下图)

这里是我想要的图表:

The Chart which i want

我试图在谷歌搜索,但仍无法做到这一点。 我真的很抱歉我的英文不好。

希望任何人都可以帮助我。

+0

看看[此](http://stackoverflow.com/questions/13839359/display-values-on-bars-of-a-bar-chart-in-asp-net ) –

+0

非常感谢你,Mong Zhu –

回答

2

您必须切换到ChartType.Line

有一定restrictions for FastLine charts

的快绳图表类型是折线图,其中 显著减少包含 非常大量的数据点的串联的绘图时间的变化。在使用非常大的数据集并且渲染速度至关重要的情况下使用此图表。

从FastLine图表中省略了一些图表功能以提高 的性能。省略的功能包括控制点级 视觉属性,标记,数据点标签和阴影。

这是设计来保持绘图的快速。除了性能和那些它们是相同的,即它们看上去都差不多限制..

现在,您可以设置要么

yourSeries.IsValueShownAsLabel = true; 

了整整Series挑选一些值,并显示它们的值作为Labels

yourSeries.Points[someIndex].IsValueShownAsLabel = true; 
+0

非常感谢。我已经转换到折线图。 –