{"spec_id":"line-arrhenius","library":"highcharts","language":"javascript","code":"// anyplot.ai\n// line-arrhenius: Arrhenius Plot for Reaction Kinetics\n// Library: highcharts 12.6.0 | JavaScript 22.22.3\n// Quality: 87/100 | Created: 2026-06-24\n\n//# anyplot-orientation: landscape\nconst t = window.ANYPLOT_TOKENS;\n\n// --- Data: first-order thermal decomposition with realistic experimental scatter ---\n// Temperatures spanning 300–600 K; ln(k) values reflect real measurement noise (R² ≈ 0.98)\nconst temperatures = [300, 325, 350, 375, 400, 425, 450, 475, 500, 550, 600];\nconst lnK = [-8.6, -8.1, -5.3, -2.3, -1.9, 1.1, 0.9, 3.4, 4.5, 4.8, 7.5];\nconst invT = temperatures.map(T => 1 / T);\n\n// --- Linear regression: ln(k) = ln(A) − (Ea/R)·(1/T) ---\nconst n = invT.length;\nconst sx = invT.reduce((a, b) => a + b, 0);\nconst sy = lnK.reduce((a, b) => a + b, 0);\nconst sxy = invT.reduce((a, x, i) => a + x * lnK[i], 0);\nconst sxx = invT.reduce((a, x) => a + x * x, 0);\nconst slope = (n * sxy - sx * sy) / (n * sxx - sx * sx);\nconst intercept = (sy - slope * sx) / n;\nconst yMean = sy / n;\nconst ssTot = lnK.reduce((a, y) => a + (y - yMean) ** 2, 0);\nconst ssRes = invT.reduce((a, x, i) => a + (lnK[i] - (slope * x + intercept)) ** 2, 0);\nconst r2 = 1 - ssRes / ssTot;\n\nconst eaOverR = Math.round(-slope);\nconst ea = (-slope * 8.314 / 1000).toFixed(1);\n\n// Fit line from slightly extended x range\nconst xLo = Math.min(...invT) * 0.97;\nconst xHi = Math.max(...invT) * 1.03;\nconst fitLine = [\n    [xLo, slope * xLo + intercept],\n    [xHi, slope * xHi + intercept]\n];\n\nconst scatterPoints = invT.map((x, i) => [x, lnK[i]]);\n\n// --- Chart ---\nconst chart = Highcharts.chart(\"container\", {\n    chart: {\n        backgroundColor: \"transparent\",\n        animation: false,\n        style: { fontFamily: \"inherit\" },\n        marginBottom: 110\n    },\n    credits: { enabled: false },\n    colors: t.palette,\n\n    title: {\n        text: \"line-arrhenius · javascript · highcharts · anyplot.ai\",\n        style: { color: t.ink, fontSize: \"22px\", fontWeight: \"600\" }\n    },\n    subtitle: {\n        text: \"Linear fit — Ea/R = \" + eaOverR.toLocaleString() + \" K | Ea ≈ \" + ea + \" kJ/mol | R² = \" + r2.toFixed(3),\n        style: { color: t.inkSoft, fontSize: \"14px\" }\n    },\n\n    xAxis: {\n        title: {\n            text: \"1/T  (K⁻¹)\",\n            style: { color: t.inkSoft, fontSize: \"16px\" }\n        },\n        lineColor: t.inkSoft,\n        tickColor: t.inkSoft,\n        gridLineColor: t.grid,\n        gridLineWidth: 1,\n        labels: {\n            useHTML: true,\n            style: { color: t.inkSoft, fontSize: \"13px\", textAlign: \"center\" },\n            formatter: function () {\n                const T = Math.round(1 / this.value);\n                return this.value.toFixed(4) +\n                    \"<br><span style=\\\"font-size:11px;color:\" + t.inkSoft + \"\\\">\" + T + \" K</span>\";\n            }\n        }\n    },\n\n    yAxis: {\n        title: {\n            text: \"ln(k)\",\n            style: { color: t.inkSoft, fontSize: \"16px\" }\n        },\n        lineColor: t.inkSoft,\n        tickColor: t.inkSoft,\n        gridLineColor: t.grid,\n        gridLineWidth: 1,\n        labels: { style: { color: t.inkSoft, fontSize: \"14px\" } }\n    },\n\n    legend: {\n        itemStyle: { color: t.inkSoft, fontSize: \"14px\" },\n        itemHoverStyle: { color: t.ink }\n    },\n\n    tooltip: { enabled: false },\n\n    plotOptions: {\n        series: { animation: false },\n        line: {\n            marker: { enabled: false },\n            lineWidth: 2.5,\n            states: { hover: { lineWidth: 2.5 } }\n        },\n        scatter: {\n            marker: {\n                radius: 7,\n                symbol: \"circle\",\n                lineColor: t.pageBg,\n                lineWidth: 1.5\n            }\n        }\n    },\n\n    series: [\n        {\n            type: \"scatter\",\n            name: \"Measured k\",\n            data: scatterPoints,\n            color: t.palette[0],\n            zIndex: 2,\n            marker: {\n                radius: 7,\n                symbol: \"circle\",\n                lineColor: t.pageBg,\n                lineWidth: 1.5\n            }\n        },\n        {\n            type: \"line\",\n            name: \"Arrhenius fit\",\n            data: fitLine,\n            color: t.palette[2],\n            lineWidth: 2.5,\n            zIndex: 1,\n            showInLegend: true\n        }\n    ]\n});\n\n// On-chart Ea/R annotation near the regression line midpoint\nconst xAnnot = xLo + 0.45 * (xHi - xLo);\nconst yAnnot = slope * xAnnot + intercept;\nconst pxAnnot = chart.xAxis[0].toPixels(xAnnot, false);\nconst pyAnnot = chart.yAxis[0].toPixels(yAnnot, false);\nchart.renderer.text(\"Ea/R = \" + eaOverR.toLocaleString() + \" K\", pxAnnot + 8, pyAnnot - 14)\n    .attr({ align: \"left\", zIndex: 5 })\n    .css({ color: t.inkSoft, fontSize: \"13px\" })\n    .add();\n"}