Search code examples
javascriptjqueryjqplot

Remove serie and replot with new values when toggling series on and off with EnhancedLegendRenderer


Let's say you have a line-graph with the series shown on the picture. When you toggle series on and off with EnhancedLegendRenderer, the serie toggles between hidden and visible. That is how it is supposed to be. The thing is though, that i want the series that remain visible to scale so that the serie with the highest y-value will be on top of the chart, adjusting the values on the y-axis at the same time. The bottom picture shows how it looks when i have toggled the series with the highest values to hidden.

Is there an easy, or an advanced for that matter, way to do this? I have tried to remove the serie totally from the chart, by removing it from the data, and creating a new jqplot. But then it's not visible on the legend anymore either. Also tried different approaches with chart.series[i].show = false; chart.replot(); etc, but with the same results.

Plot image Plot image


Solution

  • There is also an undocumented renderOption that you can use that will do the same:

    seriesToggleReplot: { resetAxes: true }
    

    So my legend looks like this:

    legend: {
        show: true,
        renderer: $.jqplot.EnhancedLegendRenderer,
        rendererOptions:{
            seriesToggleReplot: { resetAxes: true }
        },
        placement: 'outside'
    }