navigateUrl ของ column2d เอาไว้สำหรับกำหนด link เวลาเราคลิกที่ chart ให้มัน redirect
ไปหน้าที่เรากำหนด
เพิ่ม code นี้ใน Column2D.cs
/// <summary>
/// The entire chart can now act as a hotspot. Use this URL to define the hotspot link for the chart.
/// </summary>
[Bindable(true)]
[Category("Navigation")]
[DefaultValue("")]
[Description("The entire chart can now act as a hotspot. Use this URL to define the hotspot link for the chart.")]
[Editor(typeof(System.Web.UI.Design.UrlEditor), typeof(System.Drawing.Design.UITypeEditor))]
[Localizable(true)]
[UrlProperty]
public virtual string NavigateUrl
{
get
{
String s = (String)ViewState["NavigateUrl"];
return (s == null) ? string.Empty : s;
}
set { ViewState["NavigateUrl"] = value; }
}
เริ่มต้นด้วยสร้าง class ขึ้นมาตั้งชื่อว่า ChartBorder.cs แล้วก็อปโค้ดด้านล่างลงไป
ChartBorder.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Drawing;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace FusionCharts
{
public sealed class ChartBorder : IStateManager
{
private StateBag _viewstate;
private bool _show;
private Color _color;
private Unit _alpha;
private Unit _width;
#region ========== Constructor ==========
public ChartBorder()
{
_viewstate = new StateBag();
_viewstate.Add("Show", _show);
_viewstate.Add("Color", _color);
_viewstate.Add("Alpha", _alpha);
_viewstate.Add("Width", _width);
this.Show = true;
this.Color = Color.Empty;
this.Width = 1;
this.Alpha = 50;
}
#endregion
#region ========== Property ==========
/// <summary>
/// Whether to show a border around the chart or not.
/// </summary>
[Bindable(true)]
[Category("Appearance")]
[DefaultValue(true)]
[Description("Whether to show a border around the chart or not.")]
[Localizable(true)]
public bool Show
{
get
{
object obj = _viewstate["Show"];
return (obj == null) ? true : (bool)obj;
}
set { _viewstate["Show"] = value; }
}
/// <summary>
/// Border color of the chart.
/// </summary>
[Bindable(true)]
[Category("Appearance")]
[DefaultValue("")]
[Description("Border color of the chart.")]
[Localizable(true)]
public Color Color
{
get
{
object obj = _viewstate["Color"];
return (obj == null) ? Color.Empty : (Color)obj;
}
set { _viewstate["Color"] = value; }
}
/// <summary>
/// Border alpha of the chart.
/// </summary>
[Bindable(true)]
[Category("Appearance")]
[DefaultValue(50)]
[Description("Border alpha of the chart.")]
[Localizable(true)]
public Unit Alpha
{
get
{
object obj = _viewstate["Alpha"];
return (obj == null) ? 50 : (Unit)obj;
}
set { _viewstate["Alpha"] = value; }
}
/// <summary>
/// Border thickness of the chart.
/// </summary>
[Bindable(true)]
[Category("Appearance")]
[DefaultValue(1)]
[Description("Border thickness of the chart.")]
[Localizable(true)]
public Unit Width
{
get
{
object obj = _viewstate["Width"];
return (obj == null) ? 1 : (Unit)obj;
}
set { _viewstate["Width"] = value; }
}
#endregion
#region IStateManager Members
public bool IsTrackingViewState
{
get { return ((IStateManager)_viewstate).IsTrackingViewState; }
}
public void LoadViewState(object state)
{
_show = (bool)_viewstate["Show"];
_color = (Color)_viewstate["Color"];
_alpha = (Unit)_viewstate["Alpha"];
_width = (Unit)_viewstate["Width"];
if (state != null)
((IStateManager)_viewstate).LoadViewState(state);
}
public object SaveViewState()
{
throw new NotImplementedException();
}
public void TrackViewState()
{
throw new NotImplementedException();
}
#endregion
}
}
แล้วก็ class นี้ด้วยสำหรับจัดการกับสีให้สามารถ convert hexstring เป็น color ได้ง่ายๆ
สร้าง class แล้วตั้งชื่อ ColorManager.cs แล้วก็อปโค้ดด้านล่างไปแปะ
ColorManager.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Text.RegularExpressions;
namespace FusionCharts
{
internal class ColorManager
{
/// <summary>
/// Convert a hex string to a .NET Color object.
/// </summary>
/// <param name="hexColor">a hex string: "FFFFFF", "#000000"</param>
public static Color HexStringToColor(string hexColor)
{
string hc = ExtractHexDigits(hexColor);
if (hc.Length != 6)
{
// you can choose whether to throw an exception
// throw new ArgumentException("hexColor is not exactly 6 digits.");
return Color.Empty;
}
string r = hc.Substring(0, 2);
string g = hc.Substring(2, 2);
string b = hc.Substring(4, 2);
Color color = Color.Empty;
try
{
int ri = Int32.Parse(r, System.Globalization.NumberStyles.HexNumber);
int gi = Int32.Parse(g, System.Globalization.NumberStyles.HexNumber);
int bi = Int32.Parse(b, System.Globalization.NumberStyles.HexNumber);
color = Color.FromArgb(ri, gi, bi);
}
catch
{
// you can choose whether to throw an exception
// throw new ArgumentException("Conversion failed.");
return Color.Empty;
}
return color;
}
/// <summary>
/// Extract only the hex digits from a string.
/// </summary>
/// <param name="input">a hex string: "FFFFFF", "#000000"</param>
public static string ExtractHexDigits(string input)
{
// remove any characters that are not digits (like #)
Regex isHexDigit = new Regex("[abcdefABCDEF\\d]+", RegexOptions.Compiled);
string newnum = "";
foreach (char c in input)
{
if (isHexDigit.IsMatch(c.ToString()))
newnum += c.ToString();
}
return newnum;
}
/// <summary>
/// Convert a .NET Color object to a hex string.
/// </summary>
/// <param name="color">.NET Color object</param>
public static string ColorToHexString(Color color)
{
string RGB;
RGB = int.Parse(color.R.ToString()).ToString("X").Length == 1 ? "0" + int.Parse(color.R.ToString()).ToString("X") : int.Parse(color.R.ToString()).ToString("X");
RGB += int.Parse(color.G.ToString()).ToString("X").Length == 1 ? "0" + int.Parse(color.G.ToString()).ToString("X") : int.Parse(color.G.ToString()).ToString("X");
RGB += int.Parse(color.B.ToString()).ToString("X").Length == 1 ? "0" + int.Parse(color.B.ToString()).ToString("X") : int.Parse(color.B.ToString()).ToString("X");
return RGB;
}
}
}
private ChartBorder borderStyle;
public Column2D()
{
borderStyle = new ChartBorder();
}
/// <summary>
/// Gets the border properties associated of the chart.
/// </summary>
[Browsable(true)]
[Category("Appearance")]
[Description("Gets the border properties associated of the chart.")]
[NotifyParentProperty(true)]
[PersistenceMode(PersistenceMode.Attribute)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public new ChartBorder BorderStyle
{
get { return borderStyle; }
}
Protected WithEvents Column2D1 As Global.FusionCharts.Column2D
ถ้ารัน มันก็จะขึ้น Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: Unknown server tag 'FCharts:Column2D'.
Source Error:
Line 12: <form id="form1" runat="server">
Line 13: <div>
Line 14: <FCharts:Column2D ID="Column2D1" Caption="tungman" Width="640" Height="480" runat="server">
Line 15: <asp:ListItem Text="tungman1" Value="100"></asp:ListItem> Line 16: <asp:ListItem Text="tungman2" Value="200"></asp:ListItem>
รบกวนทีนะครับ
ส่วนของ Visual 2010 มี Control Chart buildin มาด้วย ลองแล้วครับใช้ได้