jq plot - getting linear x axis ticks

人盡茶涼 提交于 2019-12-12 04:57:52

问题


I have a jqPlot chart which is rendered as in the image below.

Iam using LinearAxisRenderer for the x-axis.

But the x-axis values are coming as 0 ,1,1,2,2, etc..

Is there a way to get the values as 0, 1,2,3 etc..

Thanks in advance.

Code :

 $.jqplot(ctrlId, [graphPt], {
        title: chartTitle,
        seriesDefaults: {
            renderer: $.jqplot.BarRenderer,
            pointLabels: { show: true, location: 'e', edgeTolerance: -15, formatString: '%s' },
            shadow: false,
            rendererOptions: {
                barDirection: 'horizontal',
                barMargin: 2
            }
        },
        axesDefaults: {
            renderer: $.jqplot.canvasAxisTickRenderer,
            min: 0,      // minimum numerical value of the axis.  Determined automatically.
            pad: 1.3,       // a factor multiplied by the data range on the axis to give the
            // axis range so that data points don't fall on the edges of the axis.

            tickOptions: {
                mark: 'outside',    // Where to put the tick mark on the axis 'outside', 'inside' or 'cross',
                markSize: 95,                  // 
                showGridline: false, // wether to draw a gridline (across the whole grid) at this tick,
                show: true,         // wether to show the tick (mark and label),
                showLabel: true,    // wether to show the text label at the tick,
                formatString: '%d'   // format string to use with the axis tick formatter
            },
            showTicks: true,        // wether or not to show the tick labels,
            showTickMarks: true    // wether or not to show the tick marks
        },

        axes: {
            yaxis: {
                renderer: $.jqplot.CategoryAxisRenderer
            },
            xaxis: {
                 renderer: $.jqplot.LinearAxisRenderer,
                tickOptions: {
                    mark: 'cross', 
                    markSize: 2
                }
            }
        }
    });

回答1:


Add tickinterval property to your xaxis settings.

xaxis: {
             renderer: $.jqplot.LinearAxisRenderer,
            tickOptions: {
                mark: 'cross', 
                markSize: 2,   
            },
            tickInterval: 1 //ADD THIS
        }

From the jqplot documentation:

tickInterval - number of units between ticks. Mutually exclusive with numberTicks.




回答2:


Don'forget to add 'max' and 'min' properties. If your are manipulating xaxis ticks individually. I've Lost lots of time on that.

xaxis: {
            renderer: $.jqplot.LinearAxisRenderer,
            tickOptions: {
                mark: 'cross', 
                markSize: 2,   
            },
            tickInterval: 1 
            max :0,
            min :100
        }


来源:https://stackoverflow.com/questions/9765521/jq-plot-getting-linear-x-axis-ticks

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!