{"spec_id":"line-stress-strain","library":"highcharts","language":"javascript","code":"// anyplot.ai\n// line-stress-strain: Engineering Stress-Strain Curve\n// Library: highcharts 12.6.0 | JavaScript 22.23.2\n// Quality: 89/100 | Created: 2026-08-24\n\nconst t = window.ANYPLOT_TOKENS;\n\n// --- Data: Aluminum 6061-T6 tensile test (Ramberg-Osgood elastic-plastic model) --\nconst E = 69000; // Young's modulus, MPa\nconst sigmaY = 276; // 0.2% offset yield strength, MPa\nconst sigmaUTS = 310; // ultimate tensile strength, MPa\nconst sigmaFracture = 235; // fracture stress, MPa\nconst roExponent = 25; // Ramberg-Osgood hardening exponent\n\nconst curve = [];\nconst hardeningSteps = 220;\nfor (let i = 0; i <= hardeningSteps; i++) {\n  const sigma = (sigmaUTS * i) / hardeningSteps;\n  const strain = sigma / E + 0.002 * Math.pow(sigma / sigmaY, roExponent);\n  curve.push([strain, sigma]);\n}\nconst strainAtUTS = curve[curve.length - 1][0];\nconst strainAtFracture = 0.11;\n\nconst neckingSteps = 80;\nfor (let i = 1; i <= neckingSteps; i++) {\n  const frac = i / neckingSteps;\n  const strain = strainAtUTS + frac * (strainAtFracture - strainAtUTS);\n  const stress = sigmaUTS - (sigmaUTS - sigmaFracture) * Math.pow(frac, 1.6);\n  curve.push([strain, stress]);\n}\n\n// 0.2% offset method: yield point is where the curve meets the offset line\nconst strainAtYield = sigmaY / E + 0.002;\n\nconst elasticModulusLine = [\n  [0, 0],\n  [strainAtYield, sigmaY],\n];\nconst offsetLine = [\n  [0.002, 0],\n  [strainAtYield + 0.0015, E * (strainAtYield + 0.0015 - 0.002)],\n];\n\n// x-axis min pulled slightly negative so the origin-anchored elastic-modulus\n// and offset construction lines get breathing room from the left edge.\nconst xAxisMin = -strainAtFracture * 0.03;\n\nconst criticalPoints = [\n  {\n    x: strainAtYield,\n    y: sigmaY,\n    name: \"Yield (0.2% offset)\",\n    color: t.ink,\n    dataLabels: { align: \"left\", x: 20, y: -14 },\n  },\n  {\n    x: strainAtUTS,\n    y: sigmaUTS,\n    name: \"UTS\",\n    color: t.ink,\n    dataLabels: { align: \"center\", x: 0, y: -16 },\n  },\n  {\n    x: strainAtFracture,\n    y: sigmaFracture,\n    name: \"Fracture\",\n    color: t.palette[4],\n    dataLabels: { align: \"right\", x: -10, y: -10 },\n  },\n];\n\n// --- Title (scaled to the mandated + descriptive prefix length) ------------\nconst titleText = \"Al 6061-T6 tensile test · line-stress-strain · javascript · highcharts · anyplot.ai\";\nconst titleLen = titleText.length;\nconst titleFontSize = Math.max(14, Math.round(22 * (titleLen > 67 ? 67 / titleLen : 1)));\n\n// --- Chart -------------------------------------------------------------------\nHighcharts.chart(\"container\", {\n  chart: {\n    type: \"line\",\n    backgroundColor: \"transparent\",\n    animation: false,\n    style: { fontFamily: \"inherit\" },\n  },\n  credits: { enabled: false },\n  colors: t.palette,\n  title: {\n    text: titleText,\n    style: { color: t.ink, fontSize: `${titleFontSize}px`, fontWeight: \"600\" },\n  },\n  xAxis: {\n    title: { text: \"Engineering strain (mm/mm)\", style: { color: t.inkSoft, fontSize: \"16px\" } },\n    min: xAxisMin,\n    max: strainAtFracture * 1.05,\n    lineColor: t.inkSoft,\n    tickColor: t.inkSoft,\n    gridLineWidth: 0,\n    labels: { style: { color: t.inkSoft, fontSize: \"14px\" } },\n    plotBands: [\n      { from: xAxisMin, to: strainAtYield, color: Highcharts.color(t.palette[0]).setOpacity(0.05).get(), label: { text: \"Elastic\", align: \"center\", verticalAlign: \"top\", y: 30, style: { color: t.inkMuted, fontSize: \"13px\", fontStyle: \"italic\" } } },\n      { from: strainAtYield, to: strainAtUTS, color: \"transparent\", label: { text: \"Plastic (strain hardening)\", align: \"center\", verticalAlign: \"top\", y: 30, style: { color: t.inkMuted, fontSize: \"13px\", fontStyle: \"italic\" } } },\n      { from: strainAtUTS, to: strainAtFracture, color: Highcharts.color(t.palette[0]).setOpacity(0.05).get(), label: { text: \"Necking\", align: \"center\", verticalAlign: \"top\", y: 30, style: { color: t.inkMuted, fontSize: \"13px\", fontStyle: \"italic\" } } },\n    ],\n    plotLines: [\n      { value: strainAtYield, color: t.grid, width: 1, dashStyle: \"Dot\", zIndex: 0 },\n      { value: strainAtUTS, color: t.grid, width: 1, dashStyle: \"Dot\", zIndex: 0 },\n    ],\n  },\n  yAxis: {\n    title: { text: \"Engineering stress (MPa)\", style: { color: t.inkSoft, fontSize: \"16px\" } },\n    min: 0,\n    lineColor: t.inkSoft,\n    tickColor: t.inkSoft,\n    gridLineColor: t.grid,\n    labels: { style: { color: t.inkSoft, fontSize: \"14px\" } },\n  },\n  legend: {\n    align: \"center\",\n    verticalAlign: \"bottom\",\n    itemStyle: { color: t.inkSoft, fontSize: \"14px\" },\n    itemHoverStyle: { color: t.ink },\n  },\n  tooltip: {\n    headerFormat: \"\",\n    pointFormat: \"strain {point.x:.3f} · stress {point.y:.0f} MPa\",\n  },\n  plotOptions: {\n    series: { animation: false },\n    line: { marker: { enabled: false } },\n  },\n  series: [\n    {\n      name: \"Al 6061-T6 stress-strain\",\n      type: \"line\",\n      data: curve,\n      color: t.palette[0],\n      lineWidth: 3.5,\n      zIndex: 3,\n    },\n    {\n      name: \"Elastic modulus (E ≈ 69 GPa)\",\n      type: \"line\",\n      data: elasticModulusLine,\n      color: t.ink,\n      lineWidth: 1.5,\n      dashStyle: \"Dash\",\n      enableMouseTracking: false,\n      zIndex: 1,\n    },\n    {\n      name: \"0.2% offset (yield method)\",\n      type: \"line\",\n      data: offsetLine,\n      color: t.palette[1],\n      lineWidth: 1.5,\n      dashStyle: \"LongDash\",\n      enableMouseTracking: false,\n      zIndex: 1,\n    },\n    {\n      name: \"Critical points\",\n      type: \"scatter\",\n      data: criticalPoints,\n      color: t.ink,\n      marker: { enabled: true, radius: 6, lineWidth: 1.5, lineColor: t.pageBg },\n      dataLabels: {\n        enabled: true,\n        formatter() {\n          return `${this.point.name}: ${Math.round(this.y)} MPa`;\n        },\n        style: { color: t.ink, fontSize: \"13px\", fontWeight: \"500\", textOutline: \"none\" },\n        verticalAlign: \"bottom\",\n        y: -12,\n      },\n      zIndex: 4,\n    },\n  ],\n});\n"}