你應該學會使用WPF,但是可以使用winforms標準控件來實現Sparkline。糾正我,如果我錯了,但sparkline是一個簡單的折線圖。
查看關於Chart control的文檔。你應該設置ChartType
到SeriesChartType.Spline
繪製迷你圖。
示例:爲了實現相似的外觀像博客帖子鏈接
var series = new Series("First")
{
ChartType = SeriesChartType.Spline, //line chart
ChartArea = "chartArea",
Color = Color.White
};
//generating data
var random = new Random();
for (int i = 0; i < 50; i++)
{
//random values
series.Points.AddXY(i, random.Next(100));
}
//creating display area
var chartArea = new ChartArea("chartArea")
{
//hiding grid lines
AxisX =
{
LineWidth = 0,
IntervalType = DateTimeIntervalType.NotSet,
LabelStyle = {Enabled = false},
MajorGrid = {LineWidth = 0},
MajorTickMark = {LineWidth = 0}
},
AxisY =
{
LineWidth = 0,
LabelStyle = {Enabled = false},
MajorGrid = {LineWidth = 0},
MajorTickMark = {LineWidth = 0}
},
BackColor = Color.Black
};
//creating chart control
var chart = new Chart {Dock = DockStyle.Fill, BackColor = Color.Black};
chart.ChartAreas.Add(chartArea);
chart.Series.Add(series);
//add chart control to form
Controls.Add(chart);
,其結果是: