19 using Newtonsoft.Json;
20 using Newtonsoft.Json.Linq;
21 using System.Collections.Generic;
38 public override void WriteJson(JsonWriter writer,
object value, JsonSerializer serializer)
41 if (baseSeries ==
null)
46 writer.WriteStartObject();
48 writer.WritePropertyName(
"name");
49 writer.WriteValue(baseSeries.Name);
50 writer.WritePropertyName(
"unit");
51 writer.WriteValue(baseSeries.Unit);
52 writer.WritePropertyName(
"index");
53 writer.WriteValue(baseSeries.Index);
54 writer.WritePropertyName(
"seriesType");
55 writer.WriteValue(baseSeries.SeriesType);
57 if (baseSeries.ZIndex.HasValue)
59 writer.WritePropertyName(
"zIndex");
60 writer.WriteValue(baseSeries.ZIndex.Value);
63 if (baseSeries.IndexName !=
null)
65 writer.WritePropertyName(
"indexName");
66 writer.WriteValue(baseSeries.IndexName);
69 if (baseSeries.Tooltip !=
null)
71 writer.WritePropertyName(
"tooltip");
72 writer.WriteValue(baseSeries.Tooltip);
78 var values = series.
Values;
81 values =
new List<ISeriesPoint>();
82 var dataPoint = series.ConsolidateChartPoints();
83 if (dataPoint !=
null)
85 values.Add(dataPoint);
90 serializer.Converters.Add(_colorJsonConverter);
92 writer.WritePropertyName(
"values");
93 serializer.Serialize(writer, values);
94 writer.WritePropertyName(
"color");
95 serializer.Serialize(writer, series.Color);
96 writer.WritePropertyName(
"scatterMarkerSymbol");
97 serializer.Serialize(writer, series.ScatterMarkerSymbol);
101 writer.WritePropertyName(
"values");
102 serializer.Serialize(writer, (value as
BaseSeries).Values);
106 writer.WriteEndObject();
112 public override object ReadJson(JsonReader reader, Type objectType,
object existingValue, JsonSerializer serializer)
114 var jObject = JObject.Load(reader);
116 var name = (jObject[
"Name"] ?? jObject[
"name"]).Value<string>();
117 var unit = (jObject[
"Unit"] ?? jObject[
"unit"]).Value<string>();
118 var index = (jObject[
"Index"] ?? jObject[
"index"]).Value<int>();
119 var seriesType = (
SeriesType)(jObject[
"SeriesType"] ?? jObject[
"seriesType"]).Value<
int>();
120 var values = (JArray)(jObject[
"Values"] ?? jObject[
"values"]);
122 var zindex = jObject.TryGetPropertyValue<
int?>(
"ZIndex") ?? jObject.TryGetPropertyValue<
int?>(
"zIndex");
123 var indexName = jObject.TryGetPropertyValue<
string>(
"IndexName") ?? jObject.TryGetPropertyValue<
string>(
"indexName");
124 var tooltip = jObject.TryGetPropertyValue<
string>(
"Tooltip") ?? jObject.TryGetPropertyValue<
string>(
"tooltip");
135 IndexName = indexName,
137 Values = values.ToObject<List<Candlestick>>(serializer).Where(x => x !=
null).Cast<
ISeriesPoint>().ToList()
148 IndexName = indexName,
150 Color = (jObject[
"Color"] ?? jObject[
"color"])?.ToObject<Color>(serializer) ?? Color.Empty,
156 result.
Values = values.ToObject<List<ScatterChartPoint>>(serializer).Where(x => x !=
null).Cast<
ISeriesPoint>().ToList();
160 result.Values = values.ToObject<List<ChartPoint>>(serializer).Where(x => x !=
null).Cast<
ISeriesPoint>().ToList();
172 return typeof(
BaseSeries).IsAssignableFrom(objectType);