chartjs-plugin-trendline icon indicating copy to clipboard operation
chartjs-plugin-trendline copied to clipboard

Trendline for second Y axis

Open YukonJJR opened this issue 5 years ago • 3 comments

The trend line for a second Y axis is plotted on the first Y axis therefore it does not match the scale of the datapoint it represents. Is there a way to plot the trend line on a secondary (righthand) Y axis?

YukonJJR avatar Mar 10 '20 16:03 YukonJJR

The beforeDraw function can be modified to select the yAxis for the dataset by changing the forEach function to

chartInstance.data.datasets.forEach(function (dataset, index) { if (dataset.trendlineLinear && chartInstance.isDatasetVisible(index)) { var datasetMeta = chartInstance.getDatasetMeta(index); // Check if a "named" yScale is being used var ySc = yScale if (dataset.yAxisID !== undefined && dataset.yAxisID !== null && chartInstance.scales[dataset.yAxisID] !== undefined) { ySc = chartInstance.scales[dataset.yAxisID]; } addFitter(datasetMeta, ctx, dataset, xScale, ySc); } });

JWealthall avatar May 03 '20 15:05 JWealthall

Thank you very much.  Worked perfectly….

Jeff Rogers IT Manager

419.873.9500 x1131

248.396.0289

419.873.9600

1300 Flagship Dr. Perrysburg, OH 43551

www.CECtops.com

    

On May 3, 2020, at 11:15 AM, John Wealthall [email protected] wrote:

CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.

The beforeDraw function can be modified to select the yAxis for the dataset by changing the forEach function to chartInstance.data.datasets.forEach(function (dataset, index) { if (dataset.trendlineLinear && chartInstance.isDatasetVisible(index)) { var datasetMeta = chartInstance.getDatasetMeta(index); // Check if a "named" yScale is being used var ySc = yScale if (dataset.yAxisID !== undefined && dataset.yAxisID !== null && chartInstance.scales[dataset.yAxisID] !== undefined) { ySc = chartInstance.scales[dataset.yAxisID]; } addFitter(datasetMeta, ctx, dataset, xScale, ySc); } }); — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

YukonJJR avatar May 05 '20 14:05 YukonJJR

The beforeDraw function can be modified to select the yAxis for the dataset by changing the forEach function to

chartInstance.data.datasets.forEach(function (dataset, index) { if (dataset.trendlineLinear && chartInstance.isDatasetVisible(index)) { var datasetMeta = chartInstance.getDatasetMeta(index); // Check if a "named" yScale is being used var ySc = yScale if (dataset.yAxisID !== undefined && dataset.yAxisID !== null && chartInstance.scales[dataset.yAxisID] !== undefined) { ySc = chartInstance.scales[dataset.yAxisID]; } addFitter(datasetMeta, ctx, dataset, xScale, ySc); } });

Please make a pull request.

Makanz avatar Nov 04 '20 21:11 Makanz