0

I have created one chart using angular2-highcharts based on the https://stackoverflow.com/questions/48002797/cant-bind-to-options-since-it-isnt-a-known-property-of-chart/48004515#48004515 . I got the result as well. Could anyone please tell me how to center-align the graph in mobile devices? I have tried text-align:center, padding, margin etc. enter image description here

Please help me with this issue

Edit- Added chart Options

this.chartOptions={
    chart: {
        type: 'column'
    },

    title: {
        text: 'Highcharts responsive chart'
    },

    subtitle: {
        text: 'Resize the frame to see the axes change'
    },

    xAxis: {
        categories: ['January', 'February', 'March', 'April', 'May', 'June',
            'July', 'August', 'September', 'October', 'November', 'December']
    },

    yAxis: {
        labels: {
            x: -15
        },
        title: {
            text: 'Items'
        }
    },

    series: [{
        name: 'Sales',
        data: [434, 523, 345, 785, 565, 843, 726, 590, 665, 434, 312, 432]
    }],

    responsive: {
        rules: [{
            condition: {
                maxWidth: 500
            },

            chartOptions: {
                xAxis: {
                    labels: {
                        formatter: function () {
                            return this.value.charAt(0);
                        }
                    }
                },
                yAxis: {
                    labels: {
                        align: 'left',
                        x: 0,
                        y: -2
                    },
                    title: {
                        text: ''
                    }
                }
            }
        }]
    }
}

Edit2. Added chart image after adding responsive parameters

enter image description here

Edit: Added HTML and CSS

HTML

 <chart id="container" [options] ="chartOptions" text-center></chart>

CSS

    page-keyinfo {

   svg{
       width:100%
   }



   /* Colors for data series and points. */
$colors: #7cb5ec #434348 #90ed7d #f7a35c #8085e9 #f15c80 #e4d354 #2b908f #f45b5b #91e8e1;

/* Chart background, point stroke for markers and columns etc, */
$background-color: #ffffff;

/* Neutral colors, grayscale by default. The default colors are defined by mixing the background-color
with neutral, with a weight corresponding to the number in the name. */
$neutral-color-100: #000000; /* Strong text. */
$neutral-color-80: #333333; /* Main text and some strokes. */
$neutral-color-60: #666666; /* Axis labels, axis title, connector fallback. */
$neutral-color-40: #999999; /* Credits text, export menu stroke. */
$neutral-color-20: #cccccc; /* Disabled texts, button strokes, crosshair etc. */
$neutral-color-10: #e6e6e6; /* Grid lines etc. */
$neutral-color-5: #f2f2f2; /* Minor grid lines etc. */
$neutral-color-3: #f7f7f7; /* Tooltip backgroud, button fills, map null points. */

/* Colored, shades of blue by default */
$highlight-color-100: #003399; /* Drilldown clickable labels, color axis max color. */
$highlight-color-80: #335cad; /* Selection marker, menu hover, button hover, chart border, navigator series. */
$highlight-color-60: #6685c2; /* Navigator mask fill. */
$highlight-color-20: #ccd6eb; /* Ticks and axis line. */
$highlight-color-10: #e6ebf5; /* Pressed button, color axis min color. */

.highcharts-container {
    position: relative;
    overflow: scroll !important;
    width:  100% !important;
    height: 100% !important;
    text-align: center;
    line-height: normal;
    z-index: 0; /* #1072 */
    font-family: "Lucida Grande", "Lucida Sans Unicode", Arial, Helvetica, sans-serif;
    font-size: 12px;
}
.highcharts-root text {
    stroke-width: 0;
}
.highcharts-background {
    fill: $background-color;
}
.highcharts-plot-border, .highcharts-plot-background {
    fill: none;
}
.highcharts-label-box {
    fill: none;
}
.highcharts-button-box {
    fill: inherit;
}

/* Titles */
.highcharts-title {
    fill: $neutral-color-80;
    font-size: 1.5em;
}
.highcharts-subtitle {
    fill: $neutral-color-60;
}

/* Axes */
.highcharts-axis-line {
    fill: none;
    stroke: $highlight-color-20;
}
.highcharts-yaxis .highcharts-axis-line {
    stroke-width: 0;
}
.highcharts-axis-title {
    fill: $neutral-color-60;
}
.highcharts-axis-labels {
    fill: $neutral-color-60;
    cursor: default;
    font-size: 0.9em;
}
.highcharts-grid-line {
    fill: none;
    stroke: $neutral-color-10;
}
.highcharts-xaxis-grid .highcharts-grid-line {
    stroke-width: 0;
}
.highcharts-tick {
    stroke: $highlight-color-20;
}
.highcharts-yaxis .highcharts-tick {
    stroke-width: 0;
}
.highcharts-minor-grid-line {
    stroke: $neutral-color-5;
}
.highcharts-crosshair-thin {
    stroke-width: 1px;
    stroke: $neutral-color-20;
}
.highcharts-crosshair-category {
    stroke: $highlight-color-20;
    stroke-opacity: 0.25;
}


/* Credits */
.highcharts-credits {
    display: none !important;

}


/* Tooltip */
.highcharts-tooltip {
    cursor: default;
    pointer-events: none;
    white-space: nowrap;
    transition: stroke 150ms;
}
.highcharts-tooltip text {
    fill: $neutral-color-80;
}
.highcharts-tooltip .highcharts-header {
    font-size: 0.85em;
}
.highcharts-tooltip-box {
    stroke-width: 1px;
    fill: $neutral-color-3;
    fill-opacity: 0.85;
}

.highcharts-selection-marker {
    fill: $highlight-color-80;
    fill-opacity: 0.25;
}

.highcharts-graph {
    fill: none;
    stroke-width: 2px;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.highcharts-state-hover .highcharts-graph {
    stroke-width: 3;
}
.highcharts-state-hover path {
    transition: stroke-width 50; /* quick in */
}
.highcharts-state-normal path {
    transition: stroke-width 250ms; /* slow out */
}

/* Legend hover affects points and series */
g.highcharts-series, .highcharts-point {
    transition: opacity 250ms;
}
.highcharts-legend-series-active g.highcharts-series:not(.highcharts-series-hover),
.highcharts-legend-point-active .highcharts-point:not(.highcharts-point-hover) {
    opacity: 0.2;
}

/* Series options */

/* Default colors */
@for $i from 1 through length($colors) {
  $color: nth($colors, $i);
  .highcharts-color-#{$i - 1} {
    fill: $color;
    stroke: $color;
  }
}

.highcharts-area {
    fill-opacity: 0.75;
    stroke-width: 0;
}
.highcharts-markers {
    stroke-width: 1px;
    stroke: $background-color;
}
.highcharts-point {
    stroke-width: 1px;
}

.highcharts-dense-data .highcharts-point {
    stroke-width: 0;
}

.highcharts-data-label {
    font-size: 0.9em;
    font-weight: bold;
}
.highcharts-data-label-box {
    fill: none;
    stroke-width: 0;
}
.highcharts-data-label text {
    fill: $neutral-color-80;
}
.highcharts-data-label-connector {
    fill: none;
}
.highcharts-halo {
    fill-opacity: 0.25;
    stroke-width: 0;
}
.highcharts-point-select {
    fill: $neutral-color-20;
    stroke: $neutral-color-100;
}
.highcharts-column-series .highcharts-point {
    stroke: $background-color;
    transition: fill-opacity 250ms;
}
.highcharts-column-series .highcharts-point-hover {
    fill-opacity: 0.75;
    transition: fill-opacity 50ms;
}
.highcharts-pie-series .highcharts-point {
    stroke-linejoin: round;
    stroke: $background-color;
}
.highcharts-pie-series .highcharts-point-hover {
    fill-opacity: 0.75;
    transition: fill-opacity 50ms;
}
.highcharts-pie-series .highcharts-point-select {
    fill: inherit;
    stroke: inherit;
}
.highcharts-funnel-series .highcharts-point {
    stroke-linejoin: round;
    stroke: $background-color;
}
.highcharts-funnel-series .highcharts-point-hover {
    fill-opacity: 0.75;
    transition: fill-opacity 50ms;
}
.highcharts-funnel-series .highcharts-point-select {
    fill: inherit;
    stroke: inherit;
}
.highcharts-pyramid-series .highcharts-point {
    stroke-linejoin: round;
    stroke: $background-color;
}
.highcharts-pyramid-series .highcharts-point-hover {
    fill-opacity: 0.75;
    transition: fill-opacity 50ms;
}
.highcharts-pyramid-series .highcharts-point-select {
    fill: inherit;
    stroke: inherit;
}
.highcharts-solidgauge-series .highcharts-point {
    stroke-width: 0;
}
.highcharts-treemap-series .highcharts-point {
    stroke-width: 1px;
    stroke: $neutral-color-10;
    transition: stroke 250ms, fill 250ms, fill-opacity 250ms;
}
.highcharts-treemap-series .highcharts-point-hover {
    stroke: $neutral-color-40;
    transition: stroke 25ms, fill 25ms, fill-opacity 25ms;
}

.highcharts-treemap-series .highcharts-above-level {
    display: none;
}
.highcharts-treemap-series .highcharts-internal-node {
    fill: none;
}
.highcharts-treemap-series .highcharts-internal-node-interactive {
    fill-opacity: 0.15;
    cursor: pointer;
}
.highcharts-treemap-series .highcharts-internal-node-interactive:hover {
    fill-opacity: 0.75;
}



/* Legend */
.highcharts-legend-box {
    fill: none;
    stroke-width: 0;
}
.highcharts-legend-item text {
    fill: $neutral-color-80;
    font-weight: bold;
    cursor: pointer;
    stroke-width: 0;
}
.highcharts-legend-item:hover text {
    fill: $neutral-color-100;
}
.highcharts-legend-item-hidden * {
    fill: $neutral-color-20 !important;
    stroke: $neutral-color-20 !important;
    transition: fill 250ms;
}
.highcharts-legend-nav-active {
    fill: $highlight-color-100;
    cursor: pointer;
}
.highcharts-legend-nav-inactive {
    fill: $neutral-color-20;
}
.highcharts-legend-title-box {
    fill: none;
    stroke-width: 0;
}

/* Loading */
.highcharts-loading {
    position: absolute;
    background-color: $background-color;
    opacity: 0.5;
    text-align: center;
    z-index: 10;
    transition: opacity 250ms;
}
.highcharts-loading-hidden {
    height: 0 !important;
    opacity: 0;
    overflow: hidden;
    transition: opacity 250ms, height 250ms step-end;
}
.highcharts-loading-inner {
    font-weight: bold;
    position: relative;
    top: 45%;
}

/* Plot bands and polar pane backgrounds */
.highcharts-plot-band {
    fill: $neutral-color-100;
    fill-opacity: 0.05;
}
.highcharts-plot-line {
    fill: none;
    stroke: $neutral-color-40;
    stroke-width: 1px;
}

/* Highcharts More */
.highcharts-boxplot-box {
    fill: $background-color;
}
.highcharts-boxplot-median {
    stroke-width: 2px;
}
.highcharts-bubble-series .highcharts-point {
    fill-opacity: 0.5;
}
.highcharts-errorbar-series .highcharts-point {
    stroke: $neutral-color-100;
}
.highcharts-gauge-series .highcharts-data-label-box {
    stroke: $neutral-color-20;
    stroke-width: 1px;
}
.highcharts-gauge-series .highcharts-dial {
    fill: $neutral-color-100;
    stroke-width: 0;
}
.highcharts-polygon-series .highcharts-graph {
    fill: inherit;
    stroke-width: 0;
}
.highcharts-waterfall-series .highcharts-graph {
    stroke: $neutral-color-80;
    stroke-dasharray: 1, 3;
}

/* Highstock */
.highcharts-navigator-mask {
    fill: $highlight-color-60; /* navigator.maskFill option */
    fill-opacity: 0.25;
}
.highcharts-navigator-mask-inside {
    fill: $highlight-color-60; /* navigator.maskFill option */
    fill-opacity: 0.25;
    cursor: ew-resize;
}

.highcharts-navigator-outline {
    stroke: $neutral-color-20;
    fill: none;
}
.highcharts-navigator-handle {
    stroke: $neutral-color-20;
    fill: $neutral-color-5;
    cursor: ew-resize;
}
.highcharts-navigator-series {
    fill: $highlight-color-80;
    stroke: $highlight-color-80;
}
.highcharts-navigator-series .highcharts-graph {
    stroke-width: 1px;
}
.highcharts-navigator-series .highcharts-area {
    fill-opacity: 0.05;
}
.highcharts-navigator-xaxis .highcharts-axis-line {
    stroke-width: 0;
}
.highcharts-navigator-xaxis .highcharts-grid-line {
    stroke-width: 1px;
    stroke: $neutral-color-10;
}
.highcharts-navigator-xaxis.highcharts-axis-labels {
    fill: $neutral-color-40;
}
.highcharts-navigator-yaxis .highcharts-grid-line {
    stroke-width: 0;
}
.highcharts-scrollbar-thumb {
    fill: $neutral-color-20;
    stroke: $neutral-color-20;
    stroke-width: 1px;
}
.highcharts-scrollbar-button {
    fill: $neutral-color-10;
    stroke: $neutral-color-20;
    stroke-width: 1px;
}
.highcharts-scrollbar-arrow {
    fill: $neutral-color-60;
}
.highcharts-scrollbar-rifles {
    stroke: $neutral-color-60;
    stroke-width: 1px;
}
.highcharts-scrollbar-track {
    fill: $neutral-color-5;
    stroke: $neutral-color-5;
    stroke-width: 1px;
}
.highcharts-button {
    fill: $neutral-color-3;
    stroke: $neutral-color-20;
    cursor: default;
    stroke-width: 1px;
    transition: fill 250ms;
}
.highcharts-button text {
    fill: $neutral-color-80;
}
.highcharts-button-hover {
    transition: fill 0ms;
    fill: $neutral-color-10;
    stroke: $neutral-color-80;
}
.highcharts-button-pressed {
    font-weight: bold;
    fill: $highlight-color-10;
    stroke: $highlight-color-80;
}
.highcharts-button-disabled text {
    fill: $neutral-color-20;
}
.highcharts-range-selector-buttons .highcharts-button {
    stroke-width: 0;
}
.highcharts-range-label rect {
    fill: none;
}
.highcharts-range-label text {
    fill: $neutral-color-60;
}
.highcharts-range-input rect {
    fill: none;
}
.highcharts-range-input text {
    fill: $neutral-color-80;
}
input.highcharts-range-selector {
    position: absolute;
    border: 0;
    width: 1px; /* Chrome needs a pixel to see it */
    height: 1px;
    padding: 0;
    text-align: center;
    left: -9em; /* #4798 */
}
.highcharts-crosshair-label text {
    fill: $background-color;
    font-size: 1.1em;
}
.highcharts-crosshair-label .highcharts-label-box {
    fill: inherit;
}


.highcharts-candlestick-series .highcharts-point {
    stroke: $neutral-color-100;
    stroke-width: 1px;
}
.highcharts-candlestick-series .highcharts-point-up {
    fill: $background-color;
}
.highcharts-ohlc-series .highcharts-point-hover {
    stroke-width: 3px;
}
.highcharts-flags-series .highcharts-point {
    stroke: $neutral-color-40;
    fill: $background-color;
}
.highcharts-flags-series .highcharts-point-hover {
    stroke: $neutral-color-100;
    fill: $highlight-color-20;
}
.highcharts-flags-series .highcharts-point text {
    fill: $neutral-color-100;
    font-size: 0.9em;
    font-weight: bold;
}

/* Highmaps */
.highcharts-map-series .highcharts-point {
    transition: fill 500ms, fill-opacity 500ms, stroke-width 250ms;
    stroke: $neutral-color-20;
}
.highcharts-map-series .highcharts-point-hover {
    transition: fill 0ms, fill-opacity 0ms;
    fill-opacity: 0.5;
    stroke-width: 2px;
}
.highcharts-mapline-series .highcharts-point {
    fill: none;
}
.highcharts-heatmap-series .highcharts-point {
    stroke-width: 0;
}
.highcharts-map-navigation {
    font-size: 1.3em;
    font-weight: bold;
    text-align: center;
}
.highcharts-coloraxis {
    stroke-width: 0;
}
.highcharts-coloraxis-marker {
    fill: $neutral-color-40;
}
.highcharts-null-point {
    fill: $neutral-color-3;
}

/* 3d charts */
.highcharts-3d-frame {
    fill: transparent;
}
.highcharts-column-series .highcharts-point  {
    stroke: inherit; /* use point color */
}

/* Exporting module */
.highcharts-contextbutton {
    fill: $background-color; /* needed to capture hover */
    stroke: none;
    stroke-linecap: round;
}
.highcharts-contextbutton:hover {
    fill: $neutral-color-10;
    stroke: $neutral-color-10;
}
.highcharts-button-symbol {
    stroke: $neutral-color-60;
    stroke-width: 3px;
}
.highcharts-menu {
    border: 1px solid $neutral-color-40;
    background: $background-color;
    padding: 5px 0;
    box-shadow: 3px 3px 10px #888;
}
.highcharts-menu-item {
    padding: 0.5em 1em;
    background: none;
    color: $neutral-color-80;
    cursor: pointer;
    transition: background 250ms, color 250ms;
}
.highcharts-menu-item:hover {
    background: $highlight-color-80;
    color: $background-color;
}

/* Drilldown module */
.highcharts-drilldown-point {
    cursor: pointer;
}
.highcharts-drilldown-data-label text, .highcharts-drilldown-axis-label {
    cursor: pointer;
    fill: $highlight-color-100;
    font-weight: bold;
    text-decoration: underline;
}

/* No-data module */
.highcharts-no-data text {
    font-weight: bold;
    font-size: 12px;
    fill: $neutral-color-60;
}

}
Dak
  • 312
  • 2
  • 10
  • Did you used the [responsive module](https://www.highcharts.com/docs/chart-concepts/responsive) ? – Core972 Dec 29 '17 at 07:40
  • where should I add this? In the chartOption? – Dak Dec 29 '17 at 08:00
  • yes take a look to the [API](https://api.highcharts.com/highcharts/responsive) for more examples – Core972 Dec 29 '17 at 08:34
  • Yeah, gone through it. Even after that I am getting the same result – Dak Dec 29 '17 at 08:51
  • @Core972 please see the edited question – Dak Dec 29 '17 at 09:00
  • if the width isn't set highcharts will always use 100% of parent so check in CSS the parent width. [API](https://api.highcharts.com/highcharts/chart.width) – Core972 Dec 29 '17 at 15:20
  • Do you want to maintain current chart size (currently it exceeds the borders of the screen - some parts are not visible) and simply have it centered (probably leftmost and rightmost months (like Jan and Dec))? Or maybe you just want to adjust the size of the chart so that it's fully visible? – Kamil Kulig Jan 02 '18 at 11:40
  • @KamilKulig I want to show the entire chart without adjusting size – Dak Jan 03 '18 at 04:54
  • Please provide HTML and CSS code. – Kamil Kulig Jan 03 '18 at 08:12
  • @KamilKulig Please see the edited question – Dak Jan 03 '18 at 11:40
  • **angular2-highcharts** is not an official wrapper so it can work differently. In Highcharts when properties like `chart.width` and `chart.height` are not provided Highcharts adjust its size to the size of the container. `chart.reflow()` is responsible for resizing the chart. By default only `window.resize` calls this function. So if the `window.resize` event doesn't happen the chart won't be resized and it's the user's responsibility to call `reflow()` when needed. See this demo: http://jsfiddle.net/kkulig/mcdgofLh/ (try commenting out `chart.reflow()`). – Kamil Kulig Jan 04 '18 at 09:36
  • @KamilKulig from where the setTimeout() method is called? – Dak Jan 05 '18 at 10:33
  • I don't understand your question. I used `setTimeout()` in my code just for example purposes. – Kamil Kulig Jan 05 '18 at 12:16

0 Answers0