Multi-Line Comparison Plot in MUI X Charts (JavaScript)

The same plot in 14 other libraries — JavaScript: Chart.js, D3.js, Apache ECharts, Highcharts; Python: Altair, Bokeh, lets-plot, Matplotlib, Plotly, plotnine, Pygal, Seaborn; R: ggplot2; Julia: Makie.jl. Compare all 15 side by side: Multi-Line Comparison Plot in Python, R, Julia and JavaScript.

A multi-line plot displays multiple data series on the same axes for direct comparison. Each series is represented by a distinct line with its own color and optional style, making it easy to identify trends, correlations, and divergences between variables. This visualization is essential for comparing related metrics over a common sequence or time period.

Multi-Line Comparison Plot rendered with MUI X Charts

Renders

JavaScript source (MUI X Charts)

// anyplot.ai
// line-multi: Multi-Line Comparison Plot
// Library: muix 9.17.0 | JavaScript 22.23.4
// Quality: 86/100 | Updated: 2026-11-08

import { LineChart } from "@mui/x-charts/LineChart";

const t = window.ANYPLOT_TOKENS;

// Constants
const X_PAD_SHARE = 0.03; // share of the x range added on both sides so the end markers stay whole
const Y_PAD_SHARE = 0.06; // share of the value range added below and above the data

// Columns: set these to your data's column names
const MONTH = "Month"; // role: x
const CITY = "City"; // role: series
const TEMP = "Average temperature (°C)"; // role: y

// Data: replace this block with your own records, one object per row
// Monthly mean temperatures of four cities in distinct climate zones.
const data = Object.entries({
  Reykjavik: [0, 1, 2, 5, 8, 11, 13, 13, 10, 6, 3, 1],
  Berlin: [1, 2, 6, 11, 16, 19, 21, 21, 16, 11, 6, 2],
  Dubai: [19, 20, 24, 29, 34, 36, 38, 38, 35, 31, 25, 21],
  Singapore: [27, 27, 28, 28, 28, 28, 28, 28, 27, 27, 27, 27],
}).flatMap(([city, temps]) =>
  ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"].map((month, i) => ({
    [MONTH]: month,
    [CITY]: city,
    [TEMP]: temps[i],
  })),
);

// Plot: reads only data and the constants above
// Months keep their order of appearance and sit on an index axis, so the axis can pad past the end markers.
const months = [...new Set(data.map((d) => d[MONTH]))];
const cities = [...new Set(data.map((d) => d[CITY]))];
const xs = months.map((_, i) => i);
const lines = cities.map((city, i) => ({
  id: `city-${i}`,
  label: city,
  color: t.palette[i],
  values: months.map((m) => data.find((d) => d[CITY] === city && d[MONTH] === m)?.[TEMP] ?? null),
}));

const temps = data.map((d) => d[TEMP]);
const yLow = Math.min(...temps);
const yHigh = Math.max(...temps);
const yPad = (yHigh - yLow) * Y_PAD_SHARE;
const xPad = (xs.length - 1) * X_PAD_SHARE;
const unit = TEMP.match(/\(([^)]+)\)/)?.[1] ?? "";

const TITLE = "line-multi · javascript · muix · anyplot.ai";
const SUBTITLE = `${cities.length} series × ${months.length} ${MONTH.toLowerCase()}s · range ${yLow} to ${yHigh} ${unit}`;
const HEADER_H = 80;
const LEGEND_H = 44;

export default function Chart() {
  const { width, height } = window.ANYPLOT_SIZE;

  return (
    <div style={{ width, height, display: "flex", flexDirection: "column" }}>
      <div style={{ height: HEADER_H, padding: "16px 40px 0 104px", boxSizing: "border-box" }}>
        <div style={{ fontSize: 22, fontWeight: 600, color: t.ink, lineHeight: 1.25 }}>{TITLE}</div>
        <div style={{ fontSize: 15, color: t.inkSoft, marginTop: 6 }}>{SUBTITLE}</div>
      </div>
      <LineChart
        width={width}
        height={height - HEADER_H - LEGEND_H}
        skipAnimation
        grid={{ horizontal: true }}
        margin={{ top: 12, right: 48, bottom: 16, left: 24 }}
        xAxis={[
          {
            data: xs,
            scaleType: "linear",
            min: -xPad,
            max: xs.length - 1 + xPad,
            tickInterval: xs,
            valueFormatter: (v: number) => months[v] ?? "",
            label: MONTH,
            height: 64,
            tickLabelStyle: { fontSize: 15, fill: t.inkSoft },
            labelStyle: { fontSize: 16, fill: t.ink },
          },
        ]}
        yAxis={[
          {
            min: yLow - yPad,
            max: yHigh + yPad,
            label: TEMP,
            width: 76,
            tickLabelStyle: { fontSize: 14, fill: t.inkSoft },
            labelStyle: { fontSize: 16, fill: t.ink },
          },
        ]}
        series={lines.map((line) => ({
          id: line.id,
          data: line.values,
          label: line.label,
          color: line.color,
          curve: "monotoneX",
          showMark: true,
          labelMarkType: "line+mark",
          valueFormatter: (v: number | null) => (v == null ? "" : `${v} ${unit}`),
        }))}
        slotProps={{
          legend: {
            direction: "horizontal",
            position: { vertical: "top", horizontal: "end" },
            sx: { fontSize: 16, color: t.ink, columnGap: 3, pr: 5, "& .MuiChartsLegend-mark": { width: 24, height: 24 } },
          },
        }}
        sx={{
          "& .MuiLineChart-line": { strokeWidth: 3 },
          "& .MuiLineChart-mark": { strokeWidth: 2.5 },
          "& .MuiChartsAxis-line": { stroke: t.inkSoft },
          "& .MuiChartsAxis-tick": { stroke: t.inkSoft },
          "& .MuiChartsGrid-line": { stroke: t.grid, strokeWidth: 1 },
        }}
      />
    </div>
  );
}

Retrieve this implementation

Runnable source as JSON, for any HTTP client: https://api.anyplot.ai/specs/line-multi/muix/code. Any spec id and library id listed in llms-full.txt fit the same URL shape; every URL below is complete and callable.

{
  "spec_id": "line-multi",
  "language": "javascript",
  "library": "muix",
  "page": "https://anyplot.ai/line-multi/javascript/muix",
  "hub": "https://anyplot.ai/line-multi",
  "code_json": "https://api.anyplot.ai/specs/line-multi/muix/code",
  "spec_json": "https://api.anyplot.ai/specs/line-multi",
  "render_light_png": "https://storage.googleapis.com/anyplot-images/plots/line-multi/javascript/muix/plot-light.png",
  "render_dark_png": "https://storage.googleapis.com/anyplot-images/plots/line-multi/javascript/muix/plot-dark.png",
  "interactive_light_html": "https://storage.googleapis.com/anyplot-images/plots/line-multi/javascript/muix/plot-light.html",
  "interactive_dark_html": "https://storage.googleapis.com/anyplot-images/plots/line-multi/javascript/muix/plot-dark.html",
  "quality_score": 86.0,
  "license": "MIT",
  "guide": "https://anyplot.ai/llms.txt"
}

Part of Multi-Line Comparison Plot on anyplot.ai.

Other implementations