C#自带的WebBrowser控件,传递数组只要webBrowser.InvokeScript("test", arguments.ToArray());就能实现;CefSharp中该怎么做,构造一个js方法慢慢push进去数据量大了就很狼狈。
public class Primitive图表Echart : Primitive浏览器本地 { [SortIndex(1000)] [DataType(DataType.Url)] [System.ComponentModel.Category("绑定相关|基本")] [System.ComponentModel.DisplayName("示例")] [System.ComponentModel.Description("示例")] public virtual Uri DemoUri { get; set; } = new Uri("https://echarts.apache.org/examples/zh/index.html#chart-type-line"); [Browsable(false)] [Filed] [SortIndex(1000)] [System.ComponentModel.Category("基本属性|场景")] [System.ComponentModel.DisplayName("网页文件")] [System.ComponentModel.Description("网页文件")] public override string Uri { get => base.Uri; set => base.Uri = value; } [Filed()] [DoNotCheckEquality] //[AutoUpdateText] [SortIndex(6000)] [System.ComponentModel.Category("绑定相关|基本")] [System.ComponentModel.DisplayName("绑定JS")] [System.ComponentModel.Description("绑定JS.")] [HeaderPlacement(HeaderPlacement.Above)] [Height(500)] public string JsValue { get => _jsValue; set { _jsValue = value; Browser?.Reload(); } } private string _jsValue = @"option = { xAxis: { type: 'category', data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] }, yAxis: { type: 'value' }, series: [{ data: [150, 230, 224, 218, 135, 147, 260], type: 'line' }] };"; private const string FileName = "Echarts.html"; public Primitive图表Echart() { } protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo) { base.OnRenderSizeChanged(sizeInfo); Browser?.Reload(); } void EvalChartJs() { if (!string.IsNullOrEmpty(_jsValue)) _frame?.ExecuteJavaScriptAsync($"{_jsValue}acceptOption();",_frame.Url); } protected override void OnLoaded(object sender, RoutedEventArgs e) { Uri = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, FileName); base.OnLoaded(sender, e); Browser.FrameLoadEnd += Browser_FrameLoadEnd; } protected override void SetAddress(string uri) { if (string.IsNullOrEmpty(uri)) return; var absoluteFilePath = uri; Browser.Address = $"file:///{uri}"; } protected override void OnUnloaded(object sender, RoutedEventArgs e) { base.OnUnloaded(sender, e); _frame = null; } private IFrame _frame; private void Browser_FrameLoadEnd(object sender, CefSharp.FrameLoadEndEventArgs e) { if (e.Frame.IsMain && e.Url.EndsWith(FileName)) { _frame = e.Frame; EvalChartJs(); } } }
我忘记了……
而且这个cefSharp有人说,不是很好用
我们后来开发出来不好用,砍掉了
@echo_lovely: 哦 是改用别的了嘛 是啥
@MinZom: 我们把这块给砍掉了
你问问其他人,好像有更好用的
@echo_lovely: 好吧 我再蹲蹲