public object ToJavaScriptObject()
        {
            var jsLayout = Interop.ExecuteJavaScript(@"new Object()");

            Interop.ExecuteJavaScript(@"
                    $0['barmode'] = $1;
                    ",
                                      jsLayout,
                                      this.BarMode.ToString().ToLower());

            if (!string.IsNullOrEmpty(this.Title))
            {
                Interop.ExecuteJavaScript("$0['title'] = $1;",
                                          jsLayout,
                                          this.Title);
            }

            if (this.Xaxis != null)
            {
                Interop.ExecuteJavaScript("$0['xaxis'] = $1;",
                                          jsLayout,
                                          this.Xaxis.ToJavascriptObject());
            }

            if (this.Yaxis != null)
            {
                Interop.ExecuteJavaScript("$0['yaxis'] = $1;",
                                          jsLayout,
                                          this.Yaxis.ToJavascriptObject());
            }

            if (this.Annotations != null)
            {
                Interop.ExecuteJavaScript("$0['annotations'] = [];", jsLayout);

                foreach (Annotation Annotation in Annotations)
                {
                    Interop.ExecuteJavaScript("$0['annotations'].push($1);",
                                              jsLayout,
                                              Annotation.ToJavaScriptObject());
                }
            }

            if (this.Font != null)
            {
                Interop.ExecuteJavaScript("$0['font'] = $1;",
                                          jsLayout,
                                          this.Font.ToJavaScriptObject());
            }

            Interop.ExecuteJavaScript("$0['showlegend'] = $1;",
                                      jsLayout,
                                      InteropHelper.Unbox(this.ShowLegend));

            if (this.Legend != null)
            {
                Interop.ExecuteJavaScript("$0['legend'] = $1;",
                                          jsLayout,
                                          this.Legend.ToJavaScriptObject());
            }

            Interop.ExecuteJavaScript("$0['bargroupgap'] = $1;",
                                      jsLayout,
                                      InteropHelper.Unbox(this.BarGroupGap));

            if (!string.IsNullOrEmpty(this.PaperBgColor))
            {
                Interop.ExecuteJavaScript("$0['paper_bgcolor'] = $1;",
                                          jsLayout,
                                          this.PaperBgColor);
            }

            if (!string.IsNullOrEmpty(this.PlotBgColor))
            {
                Interop.ExecuteJavaScript("$0['plot_bgcolor'] = $1;",
                                          jsLayout,
                                          this.PlotBgColor);
            }

            Interop.ExecuteJavaScript("$0['width'] = $1",
                                      jsLayout,
                                      InteropHelper.Unbox(this.Width));
            Interop.ExecuteJavaScript("$0['height'] = $1",
                                      jsLayout,
                                      InteropHelper.Unbox(this.Height));

            return(jsLayout);
        }
Exemple #2
0
        public object ToJavaScriptObject()
        {
            var jsX = Interop.ExecuteJavaScript("[]");

            foreach (var xPoint in this.X)
            {
                Interop.ExecuteJavaScript("$0.push($1)", jsX, InteropHelper.Unbox(xPoint));
            }

            var jsY = Interop.ExecuteJavaScript("[]");

            foreach (var yPoint in this.Y)
            {
                Interop.ExecuteJavaScript("$0.push($1)", jsY, InteropHelper.Unbox(yPoint));
            }

            var jsText = Interop.ExecuteJavaScript("[]");

            if (this.Text is List <string> )
            {
                foreach (var text in (List <string>) this.Text)
                {
                    Interop.ExecuteJavaScript("$0.push($1)", jsText, text);
                }
            }
            else if (this.Text is string && !string.IsNullOrEmpty((string)this.Text))
            {
                Interop.ExecuteJavaScript("$0 = $1;",
                                          jsText,
                                          (string)this.Text);
            }

            var jsTrace = Interop.ExecuteJavaScript(@"new Object()");

            Interop.ExecuteJavaScript(@"
                      $0['x'] = $1;
                      $0['y'] = $2;
                      $0['type'] = $3;
                      $0['mode'] = $4;
                      if ($5 != '') {
                        $0['name'] = $5;
                      }
                      if ($6.length == 1) {
                        $0['text'] = $6[0];
                      } else if ($6.length > 1) {
                        $0['text'] = $6;
                      }
                ",
                                      jsTrace,
                                      jsX,
                                      jsY,
                                      this.Type.ToString().ToLower(),
                                      this.Mode.ToJavaScriptString(),
                                      this.Name ?? "",
                                      jsText);

            if (this.Marker != null)
            {
                Interop.ExecuteJavaScript("$0['marker'] = $1;",
                                          jsTrace,
                                          this.Marker.ToJavaScriptObject());
            }

            if (this.Values != null)
            {
                var jsValues = Interop.ExecuteJavaScript("[]");

                foreach (object Val in this.Values)
                {
                    Interop.ExecuteJavaScript("$0.push($1);", jsValues, InteropHelper.Unbox(Val));
                }

                Interop.ExecuteJavaScript("$0['values'] = $1;",
                                          jsTrace,
                                          jsValues);
            }

            if (this.Labels != null)
            {
                var jsLabels = Interop.ExecuteJavaScript("[]");

                foreach (string Lbl in this.Labels)
                {
                    Interop.ExecuteJavaScript("$0.push($1);",
                                              jsLabels,
                                              Lbl);
                }

                Interop.ExecuteJavaScript("$0['labels'] = $1;",
                                          jsTrace,
                                          jsLabels);
            }

            if (this.Domain != null)
            {
                Interop.ExecuteJavaScript("$0['domain'] = $1;",
                                          jsTrace,
                                          this.Domain.ToJavaScriptObject());
            }

            if (!string.IsNullOrEmpty(this.HoverInfo))
            {
                Interop.ExecuteJavaScript("$0['hoverinfo'] = $1;",
                                          jsTrace,
                                          this.HoverInfo);
            }

            if (!string.IsNullOrEmpty(this.TextInfo))
            {
                Interop.ExecuteJavaScript("$0['textinfo'] = $1;",
                                          jsTrace,
                                          this.TextInfo);
            }

            Interop.ExecuteJavaScript("$0['hole'] = $1;",
                                      jsTrace,
                                      InteropHelper.Unbox(this.Hole));

            if (!string.IsNullOrEmpty(this.TextPosition))
            {
                Interop.ExecuteJavaScript("$0['textposition'] = $1;",
                                          jsTrace,
                                          this.TextPosition);
            }

            return(jsTrace);
        }