作成日: 2021/02/19 最終更新日: 2021/02/19
文書種別
使用方法
詳細
円グラフ内への文字列描画のため、SliceRenderedイベントにて、e.EngineのSetFontメソッドの引数に "new Font(・・・)"という形でフォントを指定しても、設定は有効になりません。
e.EngineはIRenderingEngineであるので、そのSetFontメソッドを用いてフォントを設定するには、XamlFontクラスを用いた特殊なラッパークラスを使用する必要があります。
(例)
この後、e.Engine.SetFillメソッドおよびe.Engine.DrawStringメソッドを使用して、円グラフ内に文字列を描画することができます。
以下に、サンプルプロジェクトの全体的なコードを記載します。
(MainWindow.xaml)
(MainWindow.xaml.cs)(C#)
e.EngineはIRenderingEngineであるので、そのSetFontメソッドを用いてフォントを設定するには、XamlFontクラスを用いた特殊なラッパークラスを使用する必要があります。
(例)
private void FlexPie_SliceRendered(object sender, C1.WPF.Chart.RenderSliceEventArgs e)
{
e.Engine.SetFont(new C1.WPF.Chart.XamlFont()
{
FontFamily = new System.Windows.Media.FontFamily("Courier New"),
FontSize = 44,
FontStyle = FontStyles.Italic,
FontStretch = FontStretches.Expanded,
FontWeight = FontWeights.Bold
});
・・・
この後、e.Engine.SetFillメソッドおよびe.Engine.DrawStringメソッドを使用して、円グラフ内に文字列を描画することができます。
以下に、サンプルプロジェクトの全体的なコードを記載します。
(MainWindow.xaml)
<Window x:Class="FlexPieDrawString.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:c1="http://schemas.componentone.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:FlexPieDrawString"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<c1:C1FlexPie x:Name="flexPie"></c1:C1FlexPie>
</Grid>
</Window>
(MainWindow.xaml.cs)(C#)
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace FlexPieDrawString
{
///
/// Interaction logic for MainWindow.xaml
///
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
flexPie.BindingName = "Name";
flexPie.Binding = "Population";
flexPie.ItemsSource = new List()
{
new Country(){ Name = "USA", Population = 330000000},
new Country(){ Name = "England", Population = 187030000 },
new Country(){ Name = "India", Population = 1300000000 }
};
flexPie.SliceRendered += FlexPie_SliceRendered;
}
private void FlexPie_SliceRendered(object sender, C1.WPF.Chart.RenderSliceEventArgs e)
{
e.Engine.SetFont(new C1.WPF.Chart.XamlFont()
{
FontFamily = new System.Windows.Media.FontFamily("Courier New"),
FontSize = 44,
FontStyle = FontStyles.Italic,
FontStretch = FontStretches.Expanded,
FontWeight = FontWeights.Bold
});
e.Engine.SetFill(System.Windows.Media.Brushes.Green);
e.Engine.DrawString("Sample String", new C1.Chart._Point(e.CenterX, e.CenterY));
}
}
public class Country
{
public string Name { get; set; }
public int Population { get; set; }
}
}
旧文書番号
86431