// can't yet format YamlFrontmatter (["title: Chart config"; "category: General"; "categoryindex: 1"; "index: 4"], Some { StartLine = 2 StartColumn = 0 EndLine = 6 EndColumn = 8 }) to pynb markdown

In [ ]:
#r "nuget: Plotly.NET, 2.0.0-preview.16"
#r "nuget: Plotly.NET.Interactive, 2.0.0-preview.16"

Chart config

BinderScriptNotebook

Config is an object that configures high level properties of the chart like making all chart elements editable or the tool bar on top

Image button options

Options for chart export can be set in the config at ToImageButtonOptions:

  • Three file formats for chart exports are supported (SVG, PNG, JPEG) and can be set as Format.

  • A predefined name for the downloaded chart can be set at Filename.

  • The dimensions of the downloaded chart are set at Width and Height.

  • The Scale defines the size of the exported svg.

The settings do not apply for the html document containing the chart but for charts that are exported by clicking the camera icon in the menu bar.

In [3]:
open Plotly.NET
open Plotly.NET.ConfigObjects

let svgConfig =
    Config.init (
        ToImageButtonOptions = ToImageButtonOptions.init(
            Format = StyleParam.ImageFormat.JPEG,
            Filename = "mySvgChart",
            Width = 900.,
            Height = 600.,
            Scale = 10.
        )
    )

let svgButtonChart = 
    Chart.Point([(1.,2.)])
    |> Chart.withConfig svgConfig
In [ ]:
svgButtonChart
Out[ ]:

Static plots

To create a static plot that has no hoverable elements, use StaticPlot=true on the Config:

In [5]:
let staticConfig = Config.init(StaticPlot=true)

let staticPlot =
    Chart.Point([(1.,2.)])
    |> Chart.withConfig staticConfig
In [ ]:
staticPlot
Out[ ]:

Editable charts

You can define fields that can be edited on the chart by setting Editable = true on the config, optionally explicitly setting the editable parts via EditableAnnotations

In [7]:
let editableConfig = 
    Config.init(
        Editable = true,
        EditableAnnotations = [
            StyleParam.AnnotationEditOptions.LegendPosition
            StyleParam.AnnotationEditOptions.AxisTitleText
            StyleParam.AnnotationEditOptions.LegendText
        ]
    )

let editablePlot =
    Chart.Point([(1.,2.)])
    |> Chart.withConfig editableConfig
In [ ]:
editablePlot
Out[ ]:

Responsive charts

To create a chart that is reponsive to its container size, use Responsive=true on the Config:

(try resizing the window)

In [9]:
let responsiveConfig = Config.init(Responsive=true)

let responsivePlot =
    Chart.Point([(1.,2.)])
    |> Chart.withConfig responsiveConfig
In [ ]:
responsivePlot
Out[ ]: