NachoDawg
NachoDawg

Reputation: 1544

highcharts get dashstyle from existing series

I have an existing highchart (type line) with some series in it. I have given them particular dashStyles. I am replicating the chart in a "window.open()" window and i duplicate the main chart's series and paste them into the new window's highchart.

I am having problems get'ing the dashStyle for when I iterate over the chart to create my own cloneSeries object.

This is a simplified version of what I'm currently trying

var hcCharts = $(this).closest(".chartWrapper").find(".chartContainer").highcharts()
var cloneSeries = [];

    for (var i = 0; i < hcCharts.series.length; i++) {
        cloneSeries.push({
                name: hcCharts.series[i].name,
                data: y,
                color: hcCharts.series[i].color,
                dashStyle: hcCharts.series[i].dashStyle, //not working!
                dataLabels: {
                    enabled: true,
                }

        })
   }

Then later in the window.open() document

$(".largeChart").highcharts({
    chart: {
        type: "line"
    },
    tooltip: {
        shared: true                    
    },
    series: cloneSeries, //cloneSeries is passed to the series option
    title: { text: title },                   
    exporting: { enabled: false },
    credits: {
        text: '',
    }
});

The series are coming through with data, names and color. but not the dashStyle.

Please don't hesitate to ask for clarifications

Upvotes: 1

Views: 290

Answers (1)

Kabulan0lak
Kabulan0lak

Reputation: 2136

It seems like the dashStyle property is in series.options. I would suggest you to try:

var hcCharts = $(this).closest(".chartWrapper").find(".chartContainer").highcharts()
var cloneSeries = [];

    for (var i = 0; i < hcCharts.series.length; i++) {
        cloneSeries.push({
                name: hcCharts.series[i].name,
                data: y,
                color: hcCharts.series[i].color,
                dashStyle: hcCharts.series[i].options.dashStyle, // << Line modified
                dataLabels: {
                    enabled: true,
                }

        })
   }

Upvotes: 2

Related Questions