Imports C1.Win.Chart
Imports C1.Chart
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' 棒グラフの作成
Dim series1 As New Series() With {
.ChartType = ChartType.Column,
.Name = "series1",
.DataSource = New PointF() {
New PointF(1, 20),
New PointF(2, 50),
New PointF(3, 30),
New PointF(4, 70)
},
.Binding = "Y",
.BindingX = "X"
}
' チャートの設定
FlexChart1.Series.Clear()
FlexChart1.Series.Add(series1)
FlexChart1.Legend.Position = Position.Bottom
' 軸の設定
FlexChart1.AxisY.Min = 0
FlexChart1.AxisY.Max = 100
FlexChart1.AxisY.MajorUnit = 20
FlexChart1.AxisY.AxisLine = True
FlexChart1.AxisY.Formatter = New CustomAxisLabelFormatter()
End Sub
' カスタム書式の作成
Private Class CustomAxisLabelFormatter
Implements ICustomFormatter
Public Function Format(fmt As String, arg As Object, formatProvider As IFormatProvider) As String Implements ICustomFormatter.Format
Dim value As Double = Convert.ToDouble(arg)
If value <> 0 Then
Return value.ToString("F2")
Else
Return value.ToString("F0")
End If
End Function
End Class
End Class
◎サンプルコード(C#)
using C1.Win.Chart;
namespace prj_C1FlexChart
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// 棒グラフの作成
Series series1 = new Series()
{
ChartType = C1.Chart.ChartType.Column,
Name = "series1",
DataSource = new PointF[] { new PointF(1, 20), new PointF(2, 50), new PointF(3, 30), new PointF(4, 70) },
Binding = "Y",
BindingX = "X"
};
// チャートの設定
flexChart1.Series.Clear();
flexChart1.Series.Add(series1);
flexChart1.Legend.Position = C1.Chart.Position.Bottom;
// 軸の設定
flexChart1.AxisY.Min = 0;
flexChart1.AxisY.Max = 100;
flexChart1.AxisY.MajorUnit = 20;
flexChart1.AxisY.AxisLine = true;
flexChart1.AxisY.Formatter = new CustomAxisLabelFormatter();
}
// カスタム書式の作成
private class CustomAxisLabelFormatter : ICustomFormatter
{
public string Format(string format, object arg, IFormatProvider formatProvider)
{
var formattedString = $"{arg:0.0E+00}";
if ((double)arg != 0)
{
formattedString = $"{arg:F2}";
}
else
{
formattedString = $"{arg:F0}";
}
return formattedString;
}
}
}
}