c3 icon indicating copy to clipboard operation
c3 copied to clipboard

Ability to update axis label

Open nathancole opened this issue 12 years ago • 4 comments

Is it currently possible to update an axis label after the chart has been created. In my case I am showing to different series. The user can change the data item that is being displayed on the second series. The new data item displayed can have a completely different unit from the previous data series. For example, the original data2 could be a temperature and the new data2 could be currency. For this reason it would be nice to be able to update the axis label accordingly. See the chart below for reference.

This is closely related to issue #100 as a use case.

Thanks, Nathan

c3chart

nathancole avatar Apr 01 '14 03:04 nathancole

Hi, I added axis.labels API and I think this can be used for this issue. Sample is here http://c3js.org/samples/api_axis_label.html Could you try this on the latest version?

masayuki0812 avatar Apr 01 '14 14:04 masayuki0812

Updating the labels seems to work great. The only problem I see is that it seems to override any transitions in process and lead to an abrupt redraw. The chart.data.names API does not seem to have this same effect. In the example script below, the chart will not perform an animated transition with the chart.axis.labels call. If I comment that out I get the smooth transition.

Of course... I can simply update the axis label prior loading the new data and get the desired effect. This is only really a concern in that it appears to behave slightly differently than other, similar, API calls.

function changeData() {
        $.ajax({
            url: '/Home/GetRandomData'
        }).done(function (data) {
            chart.load({
                columns: [
                    data
                ]
            });
            chart.data.names({
                data2: "NDVI " + data[1]
            });
            chart.axis.labels({
                y2: "Vegitation Index " + data[1]
            });
            setTimeout(function () {
                changeData();
            }, 2000);
        });

nathancole avatar Apr 02 '14 02:04 nathancole

Thanks for the feedback! I think this has been fixed by the commit above. Could you try the newest code?

masayuki0812 avatar Apr 02 '14 02:04 masayuki0812

All better!

nathancole avatar Apr 02 '14 03:04 nathancole