作成日: 2015/09/24 最終更新日: 2015/09/24
文書種別
使用方法
詳細
データラベルに要素の割合を表示するには下記コードのようにコレクションビューより全体の数を求め、dataLabelプロパティのcontentプロパティに設定した関数で表示する方法があります。
◎サンプルコード(ビュー/VB)
◎サンプルコード(ビュー/C#)
◎サンプルコード(コントローラー/VB)
◎サンプルコード(コントローラー/C#)
◎サンプルコード(モデル - CustomerOrder/VB)
◎サンプルコード(モデル - CustomerOrder/C#)
◎サンプルコード(モデル - FlexPieModel/VB)
◎サンプルコード(ビュー/VB)
@Imports C1.Web.Mvc
@ModelType <プロジェクト名>.FlexPieModel
<script type="text/javascript">
function chartRendering(sender) {
// コレクションビューの取得
var cv = sender.itemsSource;
// 全体の数を求める
var total = 0;
for (var i = 0; i < cv.items.length; i++) {
total += cv.items[i].Count;
}
// データラベル設定
sender.dataLabel.content = function (ht) {
return ht.name + ":" + ht.value + "個(" + ((ht.value / total) * 100).toFixed(0) + "%)";
}
}
</script>
<div>
@(Html.C1().FlexPie() _
.Bind("Country", "Count", Model.CountryGroupOrderData) _
.DataLabel(Function(dl)
dl.Position(C1.Web.Mvc.Chart.PieLabelPosition.Center)
End Function) _
.OnClientRendering("chartRendering")
)
</div>
@ModelType <プロジェクト名>.FlexPieModel
<script type="text/javascript">
function chartRendering(sender) {
// コレクションビューの取得
var cv = sender.itemsSource;
// 全体の数を求める
var total = 0;
for (var i = 0; i < cv.items.length; i++) {
total += cv.items[i].Count;
}
// データラベル設定
sender.dataLabel.content = function (ht) {
return ht.name + ":" + ht.value + "個(" + ((ht.value / total) * 100).toFixed(0) + "%)";
}
}
</script>
<div>
@(Html.C1().FlexPie() _
.Bind("Country", "Count", Model.CountryGroupOrderData) _
.DataLabel(Function(dl)
dl.Position(C1.Web.Mvc.Chart.PieLabelPosition.Center)
End Function) _
.OnClientRendering("chartRendering")
)
</div>
◎サンプルコード(ビュー/C#)
@using <プロジェクト名>.Models
@model IEnumerable<CustomerOrder>
<script type="text/javascript">
function chartRendering(sender) {
// コレクションビューの取得
var cv = sender.itemsSource;
// 全体の数を求める
var total = 0;
for (var i = 0; i < cv.items.length; i++) {
total += cv.items[i].Count;
}
// データラベル設定
sender.dataLabel.content = function (ht) {
return ht.name + ":" + ht.value + "個(" + ((ht.value / total) * 100).toFixed(0) + "%)";
}
}
</script>
<div>
@(Html.C1().FlexPie<CustomerOrder>()
.Bind("Country", "Count", Model)
.DataLabel(dl =>
{
dl.Position(C1.Web.Mvc.Chart.PieLabelPosition.Center);
})
.OnClientRendering("chartRendering")
)
</div>
@model IEnumerable<CustomerOrder>
<script type="text/javascript">
function chartRendering(sender) {
// コレクションビューの取得
var cv = sender.itemsSource;
// 全体の数を求める
var total = 0;
for (var i = 0; i < cv.items.length; i++) {
total += cv.items[i].Count;
}
// データラベル設定
sender.dataLabel.content = function (ht) {
return ht.name + ":" + ht.value + "個(" + ((ht.value / total) * 100).toFixed(0) + "%)";
}
}
</script>
<div>
@(Html.C1().FlexPie<CustomerOrder>()
.Bind("Country", "Count", Model)
.DataLabel(dl =>
{
dl.Position(C1.Web.Mvc.Chart.PieLabelPosition.Center);
})
.OnClientRendering("chartRendering")
)
</div>
◎サンプルコード(コントローラー/VB)
Function Index() As ActionResult
Dim ModelObj As New FlexPieModel()
ModelObj.CountryGroupOrderData = CustomerOrder.GetCountryGroupOrderData()
Return View(ModelObj)
End Function
Dim ModelObj As New FlexPieModel()
ModelObj.CountryGroupOrderData = CustomerOrder.GetCountryGroupOrderData()
Return View(ModelObj)
End Function
◎サンプルコード(コントローラー/C#)
public ActionResult Index()
{
return View(CustomerOrder.GetCountryGroupOrderData());
}
{
return View(CustomerOrder.GetCountryGroupOrderData());
}
◎サンプルコード(モデル - CustomerOrder/VB)
Public Class CustomerOrder
Public Property ID() As Integer
Get
Return m_ID
End Get
Set(value As Integer)
m_ID = value
End Set
End Property
Private m_ID As Integer
Public Property Country() As String
Get
Return m_Country
End Get
Set(value As String)
m_Country = value
End Set
End Property
Private m_Country As String
Public Property Product() As String
Get
Return m_Product
End Get
Set(value As String)
m_Product = value
End Set
End Property
Private m_Product As String
Public Property OrderTime() As DateTime
Get
Return m_OrderTime
End Get
Set(value As DateTime)
m_OrderTime = value
End Set
End Property
Private m_OrderTime As DateTime
Public Property Count() As Integer
Get
Return m_Count
End Get
Set(value As Integer)
m_Count = value
End Set
End Property
Private m_Count As Integer
Public Property Price() As Decimal
Get
Return m_Price
End Get
Set(value As Decimal)
m_Price = value
End Set
End Property
Private m_Price As Decimal
Public Shared Function GetCountryGroupOrderData() As IEnumerable(Of CustomerOrder)
Dim countries = New String() {"US", "UK", "Canada", "Japan", "China", "France", "German", "Italy", "Korea", "Australia"}
Dim products = New String() {"PlayStation 4", "XBOX ONE", "Wii U", "PlayStation Vita", "PlayStation 3", "XBOX 360"}
Dim rand = New Random(0)
Dim baseTime = DateTime.Parse("2014-1-1")
Dim list = countries.Select(Function(country, i)
Dim product = products(rand.Next(0, products.Length - 1))
Dim time = baseTime.AddSeconds(rand.Next(600, 36000))
baseTime = time
Dim count = rand.Next(1, 5)
Dim price = rand.Next(99, 499)
Dim co As CustomerOrder = New CustomerOrder()
co.ID = i + 1
co.Country = country
co.Product = product
co.OrderTime = time
co.Count = count
co.Price = price
Return co
End Function)
Return list
End Function
End Class
Public Property ID() As Integer
Get
Return m_ID
End Get
Set(value As Integer)
m_ID = value
End Set
End Property
Private m_ID As Integer
Public Property Country() As String
Get
Return m_Country
End Get
Set(value As String)
m_Country = value
End Set
End Property
Private m_Country As String
Public Property Product() As String
Get
Return m_Product
End Get
Set(value As String)
m_Product = value
End Set
End Property
Private m_Product As String
Public Property OrderTime() As DateTime
Get
Return m_OrderTime
End Get
Set(value As DateTime)
m_OrderTime = value
End Set
End Property
Private m_OrderTime As DateTime
Public Property Count() As Integer
Get
Return m_Count
End Get
Set(value As Integer)
m_Count = value
End Set
End Property
Private m_Count As Integer
Public Property Price() As Decimal
Get
Return m_Price
End Get
Set(value As Decimal)
m_Price = value
End Set
End Property
Private m_Price As Decimal
Public Shared Function GetCountryGroupOrderData() As IEnumerable(Of CustomerOrder)
Dim countries = New String() {"US", "UK", "Canada", "Japan", "China", "France", "German", "Italy", "Korea", "Australia"}
Dim products = New String() {"PlayStation 4", "XBOX ONE", "Wii U", "PlayStation Vita", "PlayStation 3", "XBOX 360"}
Dim rand = New Random(0)
Dim baseTime = DateTime.Parse("2014-1-1")
Dim list = countries.Select(Function(country, i)
Dim product = products(rand.Next(0, products.Length - 1))
Dim time = baseTime.AddSeconds(rand.Next(600, 36000))
baseTime = time
Dim count = rand.Next(1, 5)
Dim price = rand.Next(99, 499)
Dim co As CustomerOrder = New CustomerOrder()
co.ID = i + 1
co.Country = country
co.Product = product
co.OrderTime = time
co.Count = count
co.Price = price
Return co
End Function)
Return list
End Function
End Class
◎サンプルコード(モデル - CustomerOrder/C#)
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
public class CustomerOrder
{
public int ID
{
get { return m_ID; }
set { m_ID = value; }
}
private int m_ID;
public string Country
{
get { return m_Country; }
set { m_Country = value; }
}
private string m_Country;
public string Product
{
get { return m_Product; }
set { m_Product = value; }
}
private string m_Product;
public DateTime OrderTime
{
get { return m_OrderTime; }
set { m_OrderTime = value; }
}
private DateTime m_OrderTime;
public int Count
{
get { return m_Count; }
set { m_Count = value; }
}
private int m_Count;
public decimal Price
{
get { return m_Price; }
set { m_Price = value; }
}
private decimal m_Price;
public static IEnumerable GetCountryGroupOrderData()
{
var countries = new string[] {"US","UK","Canada","Japan","China","France","German","Italy","Korea","Australia"};
var products = new string[] { "PlayStation 4", "XBOX ONE", "Wii U", "PlayStation Vita", "PlayStation 3", "XBOX 360" };
var rand = new Random(0);
var baseTime = DateTime.Parse("2014-1-1");
List list = new List ();
for(int i = 0; i < countries.Length; i++)
{
var product = products[rand.Next(0, products.Length - 1)];
var time = baseTime.AddSeconds(rand.Next(600, 36000));
baseTime = time;
var count = rand.Next(1, 5);
var price = rand.Next(99, 499);
CustomerOrder co = new CustomerOrder();
co.ID = i + 1;
co.Country = countries[i];
co.Product = product;
co.OrderTime = time;
co.Count = count;
co.Price = price;
list.Add(co);
}
return list;
}
}
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
public class CustomerOrder
{
public int ID
{
get { return m_ID; }
set { m_ID = value; }
}
private int m_ID;
public string Country
{
get { return m_Country; }
set { m_Country = value; }
}
private string m_Country;
public string Product
{
get { return m_Product; }
set { m_Product = value; }
}
private string m_Product;
public DateTime OrderTime
{
get { return m_OrderTime; }
set { m_OrderTime = value; }
}
private DateTime m_OrderTime;
public int Count
{
get { return m_Count; }
set { m_Count = value; }
}
private int m_Count;
public decimal Price
{
get { return m_Price; }
set { m_Price = value; }
}
private decimal m_Price;
public static IEnumerable
{
var countries = new string[] {"US","UK","Canada","Japan","China","France","German","Italy","Korea","Australia"};
var products = new string[] { "PlayStation 4", "XBOX ONE", "Wii U", "PlayStation Vita", "PlayStation 3", "XBOX 360" };
var rand = new Random(0);
var baseTime = DateTime.Parse("2014-1-1");
List
for(int i = 0; i < countries.Length; i++)
{
var product = products[rand.Next(0, products.Length - 1)];
var time = baseTime.AddSeconds(rand.Next(600, 36000));
baseTime = time;
var count = rand.Next(1, 5);
var price = rand.Next(99, 499);
CustomerOrder co = new CustomerOrder();
co.ID = i + 1;
co.Country = countries[i];
co.Product = product;
co.OrderTime = time;
co.Count = count;
co.Price = price;
list.Add(co);
}
return list;
}
}
◎サンプルコード(モデル - FlexPieModel/VB)
Public Class FlexPieModel
Public Overridable ReadOnly Property ControlId() As String
Get
Return "DemoControl"
End Get
End Property
Public Property Settings() As IDictionary(Of String, Object())
Get
Return m_Settings
End Get
Set(value As IDictionary(Of String, Object()))
m_Settings = value
End Set
End Property
Private m_Settings As IDictionary(Of String, Object())
Public Property DefaultValues() As IDictionary(Of String, Object)
Get
Return m_DefaultValues
End Get
Set(value As IDictionary(Of String, Object))
m_DefaultValues = value
End Set
End Property
Private m_DefaultValues As IDictionary(Of String, Object)
Public Property CountryGroupOrderData() As IEnumerable(Of CustomerOrder)
Get
Return m_CountryGroupOrderData
End Get
Set(value As IEnumerable(Of CustomerOrder))
m_CountryGroupOrderData = value
End Set
End Property
Private m_CountryGroupOrderData As IEnumerable(Of CustomerOrder)
End Class
Public Overridable ReadOnly Property ControlId() As String
Get
Return "DemoControl"
End Get
End Property
Public Property Settings() As IDictionary(Of String, Object())
Get
Return m_Settings
End Get
Set(value As IDictionary(Of String, Object()))
m_Settings = value
End Set
End Property
Private m_Settings As IDictionary(Of String, Object())
Public Property DefaultValues() As IDictionary(Of String, Object)
Get
Return m_DefaultValues
End Get
Set(value As IDictionary(Of String, Object))
m_DefaultValues = value
End Set
End Property
Private m_DefaultValues As IDictionary(Of String, Object)
Public Property CountryGroupOrderData() As IEnumerable(Of CustomerOrder)
Get
Return m_CountryGroupOrderData
End Get
Set(value As IEnumerable(Of CustomerOrder))
m_CountryGroupOrderData = value
End Set
End Property
Private m_CountryGroupOrderData As IEnumerable(Of CustomerOrder)
End Class
旧文書番号
81462