Spline chart smooth corners

只愿长相守 提交于 2019-12-02 09:36:30

问题


I am using Chart control from .NET framework in my project. I have added chart control to the form and configured as shown below.

// Add a new series.
chart1.Series.Add("1");
var series = chart1.Series[0];
series.ChartType = SeriesChartType.Spline;
// Hide the legend.
series.IsVisibleInLegend = false;

// configure x axis.
var cArea = chart1.ChartAreas[0];
cArea.AxisX.IntervalType = DateTimeIntervalType.Number;

cArea.AxisX.LabelStyle.Format = "00";
cArea.AxisY.LabelStyle.Format = "0.000";
cArea.AxisY.LabelStyle.IsEndLabelVisible = true;

cArea.AxisX.Minimum = 0;
cArea.AxisX.Maximum = 100;
cArea.AxisX.Interval = 20;

cArea.AxisY.Minimum = 0;
cArea.AxisY.Maximum = 100;
cArea.AxisX.Interval = 20;

Data point values are as below:

chart1.Series[0].Points.AddXY(0, 5);
chart1.Series[0].Points.AddXY(5, 10);
chart1.Series[0].Points.AddXY(10, 30);
chart1.Series[0].Points.AddXY(20, 100);
chart1.Series[0].Points.AddXY(30, 100);
chart1.Series[0].Points.AddXY(40, 90);
chart1.Series[0].Points.AddXY(50, 80);

For the above data points, series is not smooth. Upper edge is getting cut. Refer attached image.

How to make it smooth so that whole line is visible ?


回答1:


It's not visible because of the smoothing, adapt the scale (using cArea.AxisX.Maximum = 150; for example) or remove the smoothing to make the whole curve visible.




回答2:


As with the DrawCurves GDI+ method you can control the tension of the splines, i.e. how close they are to the points and their connecting lines and how much smoothing they create. Too much 'smoothing' creates the fantasy tops you see and also crazy whirls from even small bumps in the data..

Setting the tension it is done via the LineTension Custom attribute.

Lower it from the default of 0.8 to something smaller. Test to see what you prefer.

Here is an example for a Series S :

S.SetCustomProperty("LineTension", "0.4");

Note that you still should make the y-axis Maximum a little larger or else you may need to bring the tension down to 0, which will look like a line type..

Here are a few variations:



来源:https://stackoverflow.com/questions/38080022/spline-chart-smooth-corners

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!