Forum Replies Created by Samuel

Viewing 3 posts - 1 through 3 (of 3 total)
  • in reply to: Labels not working correctly #21992

    I still have some problems adding more values to the chart. It will only show 5 but I have 7.

    var dataSet = [{ x: 10, y: 71, position: "upperValue", label: "13-17" },
                   { x: 20, y: 55, position: "upperValue", label: "18-24" },
                   { x: 30, y: 55, position: "upperValue", label: "25-34" },
                   { x: 40, y: 65, position: "upperValue", label: "35-44" },
                   { x: 50, y: 95, position: "upperValue", label: "45-54" },
                   { x: 50, y: 95, position: "upperValue", label: "55-64" },
                   { x: 40, y: 65, position: "upperValue", label: "65" },
                   { x: 10, y: 51, position: "lowerValue", label: "13-17" },
                   { x: 20, y: 95, position: "lowerValue", label: "18-24" },
                   { x: 30, y: 20, position: "lowerValue", label: "25-34" },
                   { x: 40, y: 85, position: "lowerValue", label: "35-44" },
                   { x: 40, y: 85, position: "lowerValue", label: "45-54" },
                   { x: 40, y: 85, position: "lowerValue", label: "55-64" },
                   { x: 50, y: 15, position: "lowerValue", label: "65" }];
    
    var chartGender = new CanvasJS.Chart("chartGender",{
      animationEnabled: true,
      theme: "light2",
      axisX: {
        interval: 10,
      },
      axisY: {
        labelFormatter: function(e) {
          if (e.value < 0)
            return label = -1 * e.value;
          else
            return label =  e.value;
        }
      },
      toolTip:{
        contentFormatter: function ( e ) {
          if( e.entries[0].dataPoint.y < 0)
            return e.entries[0].dataPoint.x + ": " + -1 * e.entries[0].dataPoint.y ;
          else
            return e.entries[0].dataPoint.x + ": " + e.entries[0].dataPoint.y ;
        }},
      data: [
        {
          type: "column",
          dataPoints: [ ]
        }
      ]
    });
    
    for( var i = 0; i < dataSet.length; i++ )
      if( dataSet[i].position === "lowerValue")
        chartGender.options.data[0].dataPoints.push({ x:dataSet[i].x, y: (-1 * dataSet[i].y), label: dataSet[i].label, color: "#229DA0"});
      else
        chartGender.options.data[0].dataPoints.push({ x:dataSet[i].x, y: (dataSet[i].y), label: dataSet[i].label, color: "#27B6BA" });
    
      chartGender.render();
    

    The chart must be able to show more than 5 age groups.

    in reply to: Labels not working correctly #21816

    Hi

    Thx but that was not what I meant.

    I don’t want a label on each bar. I want 1 label in total per color, below the chart. Like this one: https://canvasjs.com/javascript-charts/multi-series-chart/

    The labels “Myrtle Beach” “Martha Vineyard” etc.

    in reply to: Labels not working correctly #21808

    Looks great! Thx.

    How do I add “Women” as dark blue (name of dark blue dataset) and “Men” as the lighter blue with this setup?

Viewing 3 posts - 1 through 3 (of 3 total)