Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set a symbol marker with highchart

highchart has an option which will let me set a marker to certain value.

highchart doc:

...
     data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, {
        y: 26.5,
        marker: {
           symbol: 'url(/demo/gfx/sun.png)'
        }
     }, 23.3, 18.3, 13.9, 9.6]
...

As you can see, the position 26.5 gains a png image as its marker.

My question is: How can I set it to a certain value from my array?

$.getJSON('ajax/lineChart.ajax.php', function(data) {        
    $.each(data, function(key, value) {
        var series = { 
            data: [ {
                y: 0,
                marker: {
                    symbol: 'url(img/fail.png)'
                }
            }], //data array for new series
            name: key,
            marker: {
                    symbol: 'square'
                }
        }; 
        series.data = value;
        options.series.push(series); // <-------- pushing series object
    });
    var chart = new Highcharts.Chart(options);  
});

i tried this, but nothing appeared. The chart ran without the marker.

like image 831
Ricardo Binns Avatar asked Oct 21 '11 18:10

Ricardo Binns


People also ask

What is marker in Highcharts?

Options for the point markers of line-like series. Properties like fillColor , lineColor and lineWidth define the visual appearance of the markers. Other series types, like column series, don't have markers, but have visual options on the series level instead.

What is plotOptions in Highcharts?

The plotOptions is a wrapper object for config objects for each series type. The config objects for each series can also be overridden for each series item as given in the series array. Configuration options for the series are given in three levels. Options for all series in a chart are given in the plotOptions.

What is the default chart type in Highchart?

style: Highcharts. Defaults to {"fontFamily": "\"Lucida Grande\", \"Lucida Sans Unicode\", Verdana, Arial, Helvetica, sans-serif","fontSize":"12px"} .

What language is used in Highcharts?

Highcharts is a software library for charting written in pure JavaScript, first released in 2009. The license is proprietary.


1 Answers

The line:

series.data = value;

overwrite whatever you wrote in

var series = { 
        data: [ {

I am not sure what you have in the "data" variable, but assume its is as [key:[val1,val2,...],...], try replace "series.data = value" with the following:

var list= new Array();
foreach(var v as value){
   if (v==0){ //or what ever condition you need to use a different mark 
      var m={
            y: v,
            marker: {
                symbol: 'url(img/fail.png)'
            }};
      list.push(m);       
   } 
   else{
      list.push(v);
   }
}
series.data = list;
like image 81
Gormit Avatar answered Oct 13 '22 22:10

Gormit