Customizing your plots

Danfo.js currently supports Plotly.js for plotting. This means you have all the configuration, flexibility, and interactiveness of Plotly.

All customization on the plot can be passed in the config and layout parameter.

Config Parameter

The config parameter extends the Plotly.js config type. That is, all properties available to the Plotly config argument, are available. Alongside those arguments, Danfo.js uses some custom arguments which we list below:

Layout Parameter

The layout argument object is used to configure the overall display of a chart. See the full list of supported arguments

In the following example, we show how to set some basic configuration as well as layout for a line plot.

import { useEffect } from 'react';
import './App.css';
import { readCSV } from "danfojs-nightly";

function App() {

  useEffect(() => {

    readCSV("https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv")
      .then(df => {

        const layout = {
          title: {
            text: "Time series plot of AAPL open and close points",
            x: 0
          },
          legend: {
            bgcolor: "#fcba03",
            bordercolor: "#444",
            borderwidth: 1,
            font: { family: "Arial", size: 10, color: "#fff" }
          },
          width: 1000,
          yaxis: {
            title: 'AAPL open points',
          },
          xaxis: {
            title: 'Date',
          },
        }

        const config = {
          columns: ["AAPL.Open", "AAPL.Close"], //columns to plot
          displayModeBar: true,
          displaylogo: false,
        }
        df.plot("plot_div").line({ layout, config })
      })
  }, [])

  return (
    <div className="App">
      <header className="App-header">
        <div id="plot_div"></div>
      </header>
    </div>
  );
}

export default App;

Last updated