LiveChart的用法二(熱點圖)
阿新 • • 發佈:2019-01-10
下面來自官方案例程式碼 看註釋吧0.0
var r = new Random(); /隨機
cartesianChart1.Series.Add(new HeatSeries
{
Values = new ChartValues<HeatPoint>
{
//X means sales man
//Y is the day
//"Jeremy Swanson"
new HeatPoint(0, 0, r.Next(0, 10)), //熱點型別的資料,前面是橫縱座標 後面是隨機0-9的一個值(不包含10)
new HeatPoint(0, 1, r.Next(0, 10)),
new HeatPoint(0, 2, r.Next(0, 10)),
new HeatPoint(0, 3, r.Next(0, 10)),
new HeatPoint(0, 4, r.Next(0, 10)),
new HeatPoint(0, 5, r.Next(0, 10)),
new HeatPoint(0, 6, r.Next(0, 10)),
//"Lorena Hoffman"
new HeatPoint(1, 0, r.Next(0, 10)),
new HeatPoint(1, 1, r.Next(0, 10)),
new HeatPoint(1, 2, r.Next(0, 10)),
new HeatPoint(1, 3, r.Next(0, 10)),
new HeatPoint(1, 4, r.Next(0, 10)),
new HeatPoint(1, 5, r.Next(0, 10)),
new HeatPoint(1, 6, r.Next(0, 10)),
//"Robyn Williamson"
new HeatPoint(2, 0, r.Next(0, 10)),
new HeatPoint(2, 1, r.Next(0, 10)),
new HeatPoint(2, 2, r.Next(0, 10)),
new HeatPoint(2, 3, r.Next(0, 10)),
new HeatPoint(2, 4, r.Next(0, 10)),
new HeatPoint(2, 5, r.Next(0, 10)),
new HeatPoint(2, 6, r.Next(0, 10)),
//"Carole Haynes"
new HeatPoint(3, 0, r.Next(0, 10)),
new HeatPoint(3, 1, r.Next(0, 10)),
new HeatPoint(3, 2, r.Next(0, 10)),
new HeatPoint(3, 3, r.Next(0, 10)),
new HeatPoint(3, 4, r.Next(0, 10)),
new HeatPoint(3, 5, r.Next(0, 10)),
new HeatPoint(3, 6, r.Next(0, 10)),
//"Essie Nelson"
new HeatPoint(4, 0, r.Next(0, 10)),
new HeatPoint(4, 1, r.Next(0, 10)),
new HeatPoint(4, 2, r.Next(0, 10)),
new HeatPoint(4, 3, r.Next(0, 10)),
new HeatPoint(4, 4, r.Next(0, 10)),
new HeatPoint(4, 5, r.Next(0, 10)),
new HeatPoint(4, 6, r.Next(0, 10))
},
DataLabels = true,
//The GradientStopCollection is optional // GradientStopCollection是可選的
//If you do not set this property, LiveCharts will set a gradient //如果未設定此屬性,LiveCharts將設定漸變
GradientStopCollection = new GradientStopCollection
{ ////第一個引數是顏色,第二個是對應的值(0-1) 然後上面r.Next隨機出的值按照比例對應顏色,各個顏色逐步漸變
new GradientStop(Color.FromRgb(0, 0, 0), 0), 設定0時的rgb為 (0,0,0)
new GradientStop(Color.FromRgb(0, 255, 0), .25), 設定0.25時rgb為(0,255,0)
new GradientStop(Color.FromRgb(0, 0, 255), .5),
new GradientStop(Color.FromRgb(255, 0, 0), .75),
new GradientStop(Color.FromRgb(255, 255, 255), 1)
}
});
//下面是新增軸,以及對應的引數,
cartesianChart1.AxisX.Add(new Axis
{
LabelsRotation = -15, //設定字型選擇角度
Labels = new[]
{
"Jeremy Swanson",
"Lorena Hoffman",
"Robyn Williamson",
"Carole Haynes",
"Essie Nelson"
},
Separator = new Separator {Step = 1}
});
cartesianChart1.AxisY.Add(new Axis
{
Labels = new[]
{
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
"Sunday"
}
});