Dynamically adding scale markers?
Asked Answered
O

1

5

I was wondering if there was any way to dynamically add scale-x markers AFTER the graph has been rendered, perhaps via a function like-so:

zingchart.exec('myChart', 'addscalexmarker', {
    type: "line",
    range: 14,
    label: {
        text: "label!! yay!"
    }
}

I can't seem to figure out any other way to get this to work... Thanks in advance!

Ornithine answered 4/9, 2015 at 22:19 Comment(0)
C
7

While ZingChart does have a large range of API methods to allow users to modify different pieces of a chart, not every attribute is accessible through a named method.

My suggestion would be to use the setdata method which is a catch-all API method to modify the chart's JSON. The management of the chart's state would be external to ZingChart, but updates would be handled with a single setdata method call.

   zingchart.exec('myChart', 'setdata',{
     data : myConfig
   });

Working Demo : http://demos.zingchart.com/view/BG8SXI4W

I am on the ZingChart team -- let me know if you have any further questions.

Claypan answered 4/9, 2015 at 23:43 Comment(5)
hey @mike-shultz, thanks for the answer! In terms of "range", does that take in values based on the scaleX? I'm having an odd issue where the actual value does not plot the marker in the correct place. For clarification, I'm doing the following 'versionData.push({"type": "line", "range": [value.startDate], "label": { "text": value.version}}); });' startDate is a Number who's value is present on the scale. In this case it is 1441727046774 (a date). This does not work, though when I use '15' for the range, it shows up near the mid.Ornithine
edit- I'm also doing a zingchart.exec('mainChart', 'setdata', { data: myConfig});Ornithine
Hi @BrianCorbin , would you be able to post an example of the issue? Possibly on JSFiddle?Claypan
@BrianCorbin The "range" property accepts index values based off of the tick marks (visible and invisible) on the chart. The 15 is actually plotting on index 15. If you add the property "valueRange" : true to your scale-x marker object, it will plot where you expect it to. fiddle.jshell.net/g1upgLs4Claypan
We have updated docs to include dynamic marker generation zingchart.com/docs/tutorials/chart-elements/markersMicroscopium

© 2022 - 2024 — McMap. All rights reserved.