简体   繁体   English

jqplot条形图问题

[英]jqplot bar graph issue

I need help to draq a graph with jqplot. 我需要帮助来用jqplot绘制图形。 The graph is simple, but jqplot make it complicated. 该图很简单,但是jqplot使它变得复杂。 I need to get a graph like this: 我需要得到一个像这样的图:

在此处输入图片说明 .

with some improvements: 有一些改进:

The colors are defined here: 颜色在这里定义:

graphColors = ['#048ff1', '#79b924', '#ffa600', '#ef5257', '#7b279b', '#8ff104',
               '#b92479', '#5257ef', '#279b7b', '#f1048f', '#00ffa6', '#9b7b27']

Some render options are here: 一些渲染选项在这里:

seriesDefaults: {
    seriesColors: graphColors,
    renderer: $.jqplot.BarRenderer,
    rendererOptions: { barDirection: 'vertical' }
    },
    axes: {
        yaxis: {
            renderer: $.jqplot.CategoryAxisRenderer,
            ticks: [ /* to be filled in automatically */ ]
        },
    xaxis: {
        min: 0
        }
    }

and the data I need to render is here: 我需要渲染的数据在这里:

//in the image I used instead of letters '1'
data = [[['a', 1112]],
        [['b', 1127]],
        [['c', 822]],
        [['d', 1039]]
       ];

Questions: 问题:

  1. How to set for each bar a label ('a', 'b', 'c', 'd' etc)? 如何为每个条设置标签(“ a”,“ b”,“ c”,“ d”等)?

  2. How to move the series to start from left (and not in the middle as now, of course with a small margin on left? 如何将系列从左开始(而不是现在的中间),当然在左边还有一点空白?

  3. The values on y axis, values bigger than 1000 are rendered over the graph lines. y轴上的值(大于1000的值)呈现在图形线上。 How to set a space between axis values and graph? 如何在轴值和图形之间设置间距?

  4. The graph I want to draw is simple. 我要绘制的图形很简单。 It is possible to obtain the same result without using series? 是否可以不使用序列而获得相同的结果? All I want is a bar graph with each bar having a distinct color and displaying a specific label? 我只需要一个条形图,每个条形具有不同的颜色并显示特定的标签?

Thank you. 谢谢。

See code and comments below. 请参阅下面的代码和注释。 Fiddle here . 在这里摆弄。

Item 2 on your list, I'm unclear about, if you push the plot to the left, you have empty white space on the right. 您不清楚清单2中的项目是什么,如果您将图表推到左侧,则右侧会有空白。 It's better to let the plot fill all the available space. 最好让绘图填充所有可用空间。

$(document).ready(function(){

   var graphColors = ['#048ff1', '#79b924', '#ffa600', '#ef5257', '#7b279b', '#8ff104',
           '#b92479', '#5257ef', '#279b7b', '#f1048f', '#00ffa6', '#9b7b27'];

   var data = [
        [1112],
        [1127],    
        [822],
        [1039]];

    var ticks = ['This is how to tick'];

    plot2 = $.jqplot('chart1', data, {
        seriesColors: graphColors, 
        seriesDefaults: {                
            renderer:$.jqplot.BarRenderer
        },
        axesDefaults:{pad: 1.3}, // Item 2, increase this padding so labels are cut off
        // Item 4, no, jqplot treats each differently colored bar as a series, so you must provide series options
        series:[
            {pointLabels:{show:true,labels:['a']}}, // Item 1, the label for each bar is the "labels" array 
            {pointLabels:{show:true,labels:['b']}},
            {pointLabels:{show:true,labels:['c']}},
            {pointLabels:{show:true,labels:['d']}}
        ],
        axes: {                
            xaxis: {
                renderer: $.jqplot.CategoryAxisRenderer,
                ticks: ticks // comment this out for "autoticks"
            }
        }
    });
});

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM